1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
typedef char cstr[50];
struct ITEM
{
cstr weapon{};
cstr armorhelm{};
cstr shield{};
};
struct allweapons
{ //example but not useful!
cstr weaponlist[100];
};
struct player
{
int weapon{};
int armorhelm{};
int shield{};
};
int main()
{
ITEM i{"spear", "magic helment", "used hubcap"};
cout << i.weapon << endl;;
allweapons awlist {"Amazon Bow", "Amazon Spear", "Assassin Katar", "Axe", "Bow",
"Club", "Crossbow", "Dagger", "Hammer", "Mace", "Polearm",
"Scepter", "Sorceress Orb", "Spear", "Staff", "Sword", "Wand"};
cout << awlist.weaponlist[3] << endl;
player bob{8,0,0};
cout << awlist.weaponlist[bob.weapon]<< endl; //bob has a hammer!
//ok but that is an unholy mess. the struct for all weapons in a list
// is an unnecessary layer, just do this:
const cstr allweapons[]{"Amazon Bow", "Amazon Spear", "Assassin Katar", "Axe", "Bow",
"Club", "Crossbow", "Dagger", "Hammer", "Mace", "Polearm",
"Scepter", "Sorceress Orb", "Spear", "Staff", "Sword", "Wand"};
cout << allweapons[bob.weapon] << endl; //bob has a hammer!
//^^^^^^^^^^^^^^^^^see how that is cleaner than first version?
}
|