c++ - text adventure - how to add items to 'inventory' struct/class without defining each in advance? -
c++ - text adventure - how to add items to 'inventory' struct/class without defining each in advance? -
so far awkward thing i've come about. have set integers mark how many potions, keys, player has, i'm not sure how can random items, rocks, cpu (in case of dunnet), stick, shovel, etc.
i dont want have figure out every item in game , assign variable. there has easier way. thought of using 2 arrays, 1 string , 1 int, job - wont work variety of reasons 1 beingness cant string stringname[10], see problems associating two, and... list goes on, i'm sure wont work way.
everything else class btw, dont using structs (but going used throughout code, , accessed everywhere), far code
struct inventory{ int keys; int potions; int getinventory() const { homecoming keys, potions; } void addkey(int amt){ keys += amt; } void addpotion(int amt){ potions += amt; } void usepotion(){potions -= 1;} void usekey() { if (keys >> 0) { keys -= 1; } else if (keys << 1) { cout << "you not have key!" << endl; } } };
im still working on getinventory(), because well, i'm not sure i'm doing code, or if i'm using it. way i'm going work, define each variable create in game , add together in?
i going handle weapons , monsters way... sucks not having dynamic scheme inventory. i'd focus on parsing user input , not have go header main classes consistently... plus havent written story yet, dont know whats happening...
what creating construction this:
struct inventoryitem { enum { key, potion, rock, stick, shovel } type_; unsigned int num_; }
and have inventory
contain std::vector
of inventoryitem.
c++ adventure
Comments
Post a Comment