Making a Game

I'm making a small Turn Based Combat game. I have the spells Fireball and FreezeEnemy, You start with 500 Mana and 100 Health. What spells should I add to the game, specify like so:

Spell Name:
What it does:
Power Levels:
Damage each Power Level:
Other:

Anyone can contribute if interested, PM me or email me at rakafattah@yahoo.com GitHub Repo coming soon!

Code So Far:
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <string>
#include <windows.h>

    int ManaRegenActive = 1;
    int PlayerFrozen = 0;
    int EnemyFrozen = 0;
    int eHealth = 100;
    int eMana = 500;
    int pHealth = 100;
    int pMana = 500;
    int pManaRegen = 10;
    int eManaRegen = 10;

using namespace std;




void eFreezeEnemy(int efePowerLevel)
{
    cout << "Enemy casting Freeze Spell" << endl;
    int tempMana3 = eMana;
    cout << endl << "Executing Spell 'Freeze Enemy'...";
    cout << endl << "Calculating Damage Afflicted...";
    int efeDamage = rand()% 11 * efePowerLevel;
    pHealth -= efeDamage;
    cout << endl << "Calculating Mana Usage...";
    eMana -= rand()%6 * efePowerLevel;
    cout << endl << endl << "Player has taken " << efeDamage << " damage!";
    int ManaUsage = tempMana3 -= eMana;
    cout << endl << "This spell has used " << ManaUsage << " Mana!" << endl << endl;
    cout << "Player is frozen for: " << efePowerLevel << " turn<s>!" << endl;
    PlayerFrozen = efePowerLevel;
}

void FreezeEnemy(int fePowerLevel)
{
    int tempMana2 = pMana;
    cout << endl << "Executing Spell 'Freeze Enemy'...";
    cout << endl << "Calculating Damage Afflicted...";
    int feDamage = rand()% 11 * fePowerLevel;
    eHealth -= feDamage;
    EnemyFrozen = fePowerLevel;
    cout << endl << "Calculating Mana Usage...";
    pMana -= rand()%6 * fePowerLevel;
    cout << endl << endl << "Enemy has taken " << feDamage << " damage!";
    int ManaUsage = tempMana2 -= pMana;
    cout << endl << "This spell has used " << ManaUsage << " Mana!" << endl << endl;
    cout << "Enemy is frozen for: " << fePowerLevel << " turn<s>!" << endl;
    EnemyFrozen = fePowerLevel;

}

void eFireball(int fPowerLevel)
{
    int tempMana4 = eMana;
    cout << endl << "Executing Spell 'Fireball'...";
    int efDamage = rand()%11 * fPowerLevel;
    cout << endl << "Calculating Damage Afflicted...";
    pHealth -= efDamage;
    cout << endl << "Calculating Mana Usage...";
    eMana -= rand()%21 * fPowerLevel;
    cout << endl << endl << "Player has taken " << efDamage << " damage!";
    int ManaUsage = tempMana4 -= eMana;
    cout << endl << "This spell has used " << ManaUsage << " Mana!" << endl << endl;
}

void Fireball(int fPowerLevel)
{
    int tempMana = pMana;
    cout << endl << "Executing Spell 'Fireball'...";
    int fDamage = rand()%11 * fPowerLevel;
    cout << endl << "Calculating Damage Afflicted...";
    eHealth -= fDamage;
    cout << endl << "Calculating Mana Usage...";
    pMana -= rand()%21 * fPowerLevel;
    cout << endl << endl << "Enemy has taken " << fDamage << " damage!";
    int ManaUsage = tempMana -= pMana;
    cout << endl << "This spell has used " << ManaUsage << " Mana!" << endl << endl;
}

int main ()
{

    int gameplay = 1;
    string playerCommand = "Nothing here for now...";
    while (gameplay == 1)
    {
        if(ManaRegenActive > 0)
    {
        cout << "Mana regenerated by 10!" << endl << endl << endl;
        pMana += pManaRegen;
    }
    else
    {
        cout << "Mana Regeneratin is inactive";
    }
    if(PlayerFrozen == 0)
    {

    cout << "Enemy Health is At: " << eHealth << endl;
    cout << "Enemy Mana is At: " << eMana << endl;
    cout << "Player Health is At: " << pHealth << endl;
    cout << "Player Mana is At: " << pMana << endl << endl << endl << endl;
    cout << "Enter a command: ";
    cin >> playerCommand;
    cout << endl;
    if(playerCommand == "Fireball" || playerCommand == "fireball")
    {
        int fpl;
        cout << "Enter the power level of the fireball spell, max is 5.\nEnter power level: ";
        cin >> fpl;
        cout << endl;
        while(fpl > 5 || fpl == 0)
        {
            cout << "Power level too high or is equal to 0.\n Enter Power Level: ";
            cin >> fpl;
            cout << endl;
        }
        Fireball(fpl);
    }

    else if(playerCommand == "FreezeEnemy" || playerCommand == "freezeenemy")
    {
        int fepl;
        cout << "Enter the power level of the Enemy Freezing spell, max is 3.\nEnter power level: ";
        cin >> fepl;
        cout << endl;
        while(fepl > 3 || fepl == 0)
        {
            cout << "Power level too high or is equal to 0.\n Enter Power Level: ";
            cin >> fepl;
            cout << endl;
        }
        FreezeEnemy(fepl);
    }
    }
    else
    {
       cout << "You are still frozen for " << PlayerFrozen << " turn<s>" << endl << endl << endl;
       PlayerFrozen--;
    }
    if(EnemyFrozen == 0)
    {

        cout << "Choosing spell...";
        Sleep(5000);

    int eCommand = 0;
    eCommand = rand()%2+1;
    if(eCommand == 1)
    {
        eFreezeEnemy(rand()%3+1);
    }
    if(eCommand == 2)
    {
        eFireball(rand()%5+1);
    }
    }
    else
    {
        cout << "Enemy is still frozen for " << EnemyFrozen << " turn<s>!" << endl << endl << endl;
        EnemyFrozen--;
    }
    }

    return 0;
}
There is an amazing thing C++ added to C called "classes"; you should use them.
Last edited on
Yeah you definitely want to be using classes if you're making a game. For a game like this, you can make some base class and inherit from them and it will make things so much more simple!

I also strongly suggest to avoid using namespace std; and instead to use using <only what you are using> e.g. using std::cout; using std::cin; , otherwise, you might find some naming conflicts appearing in your game. It's also just plain bad to use namespace std;
Advise taken, and the using namespace std part will be removed soon, I'm just using it for the mo
base class and inherit from them
component or other design patterns may be more suited than inheritance.
http://gameprogrammingpatterns.com/
component or other design patterns may be more suited than inheritance.

Inheritance can be part of certain design pattern implementations.
Last edited on
I meant an inheritance hierarchy, which can become very confusing when you have multiple inheritances in each branch.
http://en.wikipedia.org/wiki/Composition_over_inheritance
http://stackoverflow.com/questions/406081/why-should-i-avoid-multiple-inheritance-in-c

So instead of having something like:
Creature - human, dog, cat, ect..

You would have:
Person - arm, leg, body , head , ect..
Then create different creatures with the components.

Some people refer to it as "is-a vs has-a."

Last edited on
I see, but that is more of a composition versus inheritance statement rather than about design patterns. Some design patterns implemented in C++ can use inheritance and others use composition. I was pointing out that saying "design patterns are more suited than inheritance" is not the right thing to state.
I think what giblet meant by design patterns is using a Component Based Entity System which is a "design pattern" commonly used in game development or other design patterns like it.

Basically what he is saying is that components based systems and other designs like it are much better suited for game entities then inheritance trees because of the massive inheritance trees that result over time. Another problem with inheritance with entities is that your trees are usually very top heavy since over the course of development you will continue to push features up the tree just so a few sub classes can make use of them features, while most don't need it.

Component based designs tend to be a bit harder to implement if you are not familiar with them but in the long run I have found they produce much more modular code and greatly ease the development process in the long run.
Ah, thanks for the clarification.
Topic archived. No new replies allowed.