inventory for RPG text game

Started by
2 comments, last by UndeadInsanity 18 years, 10 months ago
hey everyone, so im kinda knee deep in making my first major program and i was wondering how i should go about making my inventory for the player. i'm using c++ and have considered using a class (but am not quite sure how since i just got started on classes) or using new to create new memory somehow for each new inventory item and then place it somewhere. . . .somehow. . . .to be recalled later. any help would be appreciated! thanks
Advertisement
The simplest solution is:

#include <vector>class Character{   std::vector<Item> inventory;   ...};

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Use a vector to store your items in. You items must all be the same type.
Something like this:
struct item{  std::string name;  std::string description;  ...};std::vector<item> items;
I recommend you use vectors, as previously mentioned.

Vectors are much like arrays, but have much more functionality and accessibility, along with them being dynamic (they can change their size easily).
Arron Bailiss | UndeadInsanityNetwork Programmerwww.ArronBailiss.co.uk

This topic is closed to new replies.

Advertisement