Question

Hey guy I'm wondering if there is a tutorial or example code for a C++ RPG inventory system. I've surfed the website and I only discovered to make two classes, item and inventory and to use each of them for item's detail and holding the items in a linked list.

This is what I have so far..

using namespace std;

int maxWeight;

class inventory {  //manages the entire inventory
public:
    inventory();
    inventory::inventory(int defaultWeight = maxWeight);

private:
    int maxWeight = 100;


};

class item {  //holds the details about a particular item
public:
    item();
    item(char* name, double weight);    
private:
    char* name;
    double weight;
};

I'm hoping my long search for such a tutorial can end..

Thank you.

Was it helpful?

Solution

Basically, from what I understand so far, what you are looking for is a linked list in your inventory to store all the items. Find out how a linked list works and go ahead from there. You will probably need to

  1. Add items (check the weight of your current linked list prior to adding the item).
  2. Remove items.
  3. Print whatever is in the linked list.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top