Help with my combat tester thing

im making a program to test combat for a game im creating.
so my game has 4 races that you can choose from. 3 classes you can choose from. and 2 sub classes you can choose from.
stats are calculated with exponential equations.
stats are used to calculate damage dealt.
my issue is.
im having the user input the race, then the class of that race, then your level.
so say i have these races:
1
2
3
4
and theses "starting" classes (lvl 1-15)
5
6
7
and these 2nd classes (lvl 15-35)
8
9
10
and these 3rd classes (lvl 35-50)
11
12
13
14
15
16

(there are alot more than that but you get my point, counting through my comments, there are 34 different classes with 4 different races, with each class having a set of 12 stats each such as attack and defense).

do i have to make a bunch of if statements, like this:
if (chooserace = 1)
{
if (chooseclass = 5)
{
}
if (choose class = 6)
{
}
other if statements
}
if (chooserace = 2)
{
if (chooseclass = 5)
{
}
if (chooseclass = 6)
{
}
even more if statements
}

for each race with class combination?

if you request that i put the code i have done so far in, i can, but would rather not, i have so many comments.
Last edited on
Take a look at switch statements (right at the bottom).
http://www.cplusplus.com/doc/tutorial/control/
i was looking at it, but i was thinking i should use arrays.
I suggest you use classes or the like, so you can keep it all neat and tidy. You can then use a map to keep track of which classes have what stats, like this:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <map>
#include <iostream>
#include <exception>

struct Stats {
    int attack;
    int defense;
    // etc.
};

// add two Stats together
Stats operator+ (const Stats& lhs, const Stats& rhs) {
    Stats s;
    s.attack = lhs.attack + rhs.attack;
    s.defense = lhs.defense + rhs.defense;
    // for all other stats...
    return s;
}

class Player {
public:
    Player() : level(1) {}

    int getLevel() const { return _level; }

    void setLevel(int level) { 
        _level = level;
        calcStats();
    }

    void setStats(const Stats& stats) {
        _baseStats = stats;
        calcStats();
    }

    // other things, like attacking, choosing moves, etc etc etc.

private:
    int _level;

    Stats _baseStats; // to calculate your stats from
    Stats _currStats; // your actual stats

    void calcStats() {
        // calculate stats based off _baseStats and _level
    }
};

int main() {
    // you can give these actual names for races and classes if you like
    const std::map<std::string, Stats> races {
        { "race1", { 10, 8, /* ... */ }},
        { "race2", { 13, 5, /* ... */ }},
        // ...
    }; 

    const std::map<std::string, Stats> classes {
        { "class1", { 3, -2, /* ... */ }},
        { "class2", { -4, 5, /* ... */ }},
        // ...
    };

    // so on for each sub class you might have

    std::string race, class;
    int level;
    std::cout << "Enter a race: ";
    std::cin >> race;
    std::cout << "Enter a class: ";
    std::cin >> class;
    std::cout << "Enter your level: ";
    std::cin >> level;

    Player p;
    // using a try-catch block, alternately you could check to see if
    // it is a valid class before you set the stats of your player
    try {
        p.setLevel(level);
        p.setStats(races.at(race) + classes.at(class));
    }
    catch (const std::exception&) {
        std::cout << "That wasn't a valid race/class!\n";
        // you could loop here, I'm just quitting:
        return 1;
    }

    // use your player

    return 0;
}


This is just a rough (untested) example of how you might do it. Notice that if you do it like this then you can load your stats from a file instead of having to hard-code them into your game and recompile it each time you tweak some numbers. Also, you might want to keep track of what race/class your player is, so that you can change its race/class more easily.
well im using the app to test if the combat system (i.e. the formulas used to make damage) are balanced.

stats are based off an exponential equation ie:
y=137(1.102)^x
where x is just the level (this is user input)

currently im creating an array to keep track of the growth rate (.102 in the case above) of a certain stat when using a certain class, but im not sure if i should be putting the equation itself in the array or if i should just keep the growth rate in the array.

and im sorry, but what you are explaining with your code is too advanced for me at the moment, i have not learned how to do any of that.
I am curious, why do you need to program all that? It is a mathematic problem which could be analitically solved. Any computational software (MathLab, Mathematica, Maxima) can help you with number-crunching part.

You are trying to bruteforce your problem without even creating a math model for it.
well i wanted to learn more c++ and decided that doing this would be a good idea.
@NT3
could i also loop in the try part?
Yes. If an exception is thrown in the loop, it escapes from the loop and goes to the catch statement. Also, having seen your clarified question, I would agree with @MiiNiPaa, but this is also a good way to learn how to do some C++ design and the like.
@NT3 so what container method should i use? Classes? and create the class in a separate file and just call the classes as needed? or structures? etc etc
Topic archived. No new replies allowed.