Trying to make a simple in-game store

So I'm trying to make a store for a game, each object has 4 things; a name, a price, the stat that it improves (ej. Armor, Strength, etc.) and how much it improves it.

Example of a blade:

The super legendary blade, 10 (price), Strength, +12

So I've thought of creating 4 arrays, 2 that hold strings and 2 that hold integers; then I would have to somehow connect this 4 arrays so that is easy to show the store; meaning that I could do a simple function that says cout<<array_that_holds_all_arrays[i][j]; and the i and would be numbers created in a for loop so I just show all the store.

I hope you understand what I'm trying to explain; the problem is that I don't know hoe to do this array that holds arrays... maybe with a vector? I need help xD

Thanks!
Ever heard of OOP?
http://www.tutorialspoint.com/cplusplus/cpp_object_oriented.htm

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
class GameObject {
    std::string name;
    std::string stat;
    float price;
    int bonus;

public:
    explicit GameObject(std::string name, std::string stat, float price, int bonus):
        name(name),
        stat(stat),
        price(price),
        bonus(bonus)
    {}

    std::string getName() {}
....
};


class GameStore {
    std::map<std::string, GameObject> storeItems;
public:
    GameObject buyItem(std::string name) {
        ...
    }
}

int main() {
    GameObject *g = new GameObject("super legendary blade", "Strength", 10, 12);
    ...
    return 0;
}

Last edited on
Yeah, object oriented programming, I've jsut had a lot of problems with objects... I don't get why can't I declare a global object so that I can use it anywhere I want to... I always got this god damm out of scope error...

So if I do it this way, whn do I have to declare al the objects? and what is an explicit type?
And what am I supposed to write on getName()
Topic archived. No new replies allowed.