lately i have been having a problem with making an inventory in my c++ rpg game
this game uses SFML/opengl(later on) and im wondering how i would make an inventory where i can:
Have multiple bags of a set number of slots(1/2/3/4/5 bags with 9 slots each)
have code that can show the items in an inventory
there is also equipment that you can use(and the equipment has levels that determine its strength/intel/etc)
also you can move the items between bags(an extra thing)
im basically asking what types of functions i should use to make this inventory(arrays,vectors,etc) and it would help if someone could provide a basic setup for this
class item{
protected:
//blah blah characteristics
public:
//blah blah methods
};
//add subclasses for your items (your "equipment")
class container{
protected:
item *items; //could use vector if desired
public:
// maybe make some setter and getter methods, and probably in your constructor
// initialize items to the number of items in the container
};
class slot: public container{
//any extra setup or characteristics being a slot may entail
};
class bag{
protected:
slot *slots; // same vector usage possibility
public:
// I would set up your constructor to describe the number of slots in the bag and items per slot
// you could also make them dynamic with good programming, and vectors if you want
};
for the display you can make the objects display themselves or you can display them yourself. Just add some graphics variables to each subclass of your item class and have them display their image based on their own image variable (or animation, or whatever)
hey ive been looking at vectors and other tutorials involving an inventory.
this is what i have thought of
in main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
vector<Item*> test;
Weapon *sword = new Weapon();
sword->itemID = 199; //this determines the items own identity. i may have done this wrong, but im trying to make the bags slot show this in the console
test.push_back(sword);
Consume *potion = new Consume();
test.push_back(potion);
Consume *potion2 = new Consume();
test.push_back(potion2);
cout << "Element 1: " << test.at(0) << endl; //this shows up as i believe an encrypted code(0x0f633n is an example)im trying to make this show the item's ID(itemID) if i could just know how to call for this information correctly i think i would be okay..
cout << "Element 2: " << test.at(1) << endl;
cout << "Element 3: " << test.at(2) << endl;
in the item.hpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Item
{
virtual string myType() {return"Blank";};
};
class Weapon: public Item
{
string myType() {return"Weapon";};
public:
int itemID;
};
class Consume: public Item
{
string myType() {return"Consume";};
};
my main problem with this is that i have no idea how to access the information in the item(stats or other characteristics) and show them in the bag
yes its a problem with accessing the information once its in the vector..
i just dont know how to call for it like for example: if i make sword have the itemID then how do i use it for other purposes(other than put to public, forgot that part) or probably change it?
EDIT: also im wondering how to set that inventory to the player(this game is planned to be online, i know, bad choice) that way its not used by anyone else?