| View previous topic :: View next topic |
| Author |
Message |
alloydog LXF regular

Joined: Thu Apr 07, 2005 8:32 pm Posts: 600
|
Posted: Thu Jul 27, 2006 5:17 pm Post subject: data array?? |
|
|
I'm not a 100% sure if I'm on the right track...
I am going to try and right a programme (for a wargame) that calculates the damage done by a weapon. The weapon has several 'characterisitics', being:
• name
• one- or two-handed
• number of dice to roll (if one-handed)
• number of dice to roll (if two-handed)
• bonus points (if one-handed)
• bonus points (if two-handed)
Some weapons can be used only two-handed, or only single-handed. for example:
| Code: | ONE-HANDED TWO-HANDED
TYPE DICE BONUS DICE BONUS
Broadsword - - 5 2
Bastardsword 3 2 4 0
Sword 3 0 - - |
How would I put this information so that a C++ programme could use it?
The aim is for the used just to select the weapon used and the programme returns a value for the damage done.
Is data array the correct term? |
|
| Back to top |
|
 |
GMorgan LXF regular
Joined: Thu Jan 12, 2006 6:58 pm Posts: 684 Location: South Wales, UK
|
Posted: Thu Jul 27, 2006 5:36 pm Post subject: RE: data array?? |
|
|
Personally I'd create a struct to account for the weapon. Prehaps something like this.
| Code: | typedef struct{
string name;
int numhands;
int weapontype;
int basedamage;
}weapon;
|
Here name is obvious, numhands is the handedness of the weapon so obviously 1 and 2 are the correct values. The value weapontype would contain an index for the weapon. So sword may enter 1, mace 2, bow 3 etc. Variable basedamage would give you your lowest damage value.
Just add fields for all the other posibilities then create an array of them. So your array might be created like this.
| Code: |
weapon allweapons[x];
|
Where x is the number of entries. To access the different fields you use the following.
| Code: |
allweapons[x].numhands = y;
|
or
| Code: |
y = allweapons[x].numhands;
|
When called like that all the normal operations work on them as they would for the normal datatypes including assignments as LV's and RV's as above or for use in comparisons.
//edit - a quick tip about arrays. They are indexed from 0 so 0 is the first entry not 1.// |
|
| Back to top |
|
 |
alloydog LXF regular

Joined: Thu Apr 07, 2005 8:32 pm Posts: 600
|
Posted: Fri Jul 28, 2006 8:08 am Post subject: RE: data array?? |
|
|
| Thanks, that's given me somewhere to start from! |
|
| Back to top |
|
 |
GMorgan LXF regular
Joined: Thu Jan 12, 2006 6:58 pm Posts: 684 Location: South Wales, UK
|
Posted: Fri Jul 28, 2006 9:05 pm Post subject: RE: data array?? |
|
|
| Another thing, remember to place the struct definition in the files header rather than inside a function. |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|