Need Help with Game Development

Ok. So i am programming a text RPG. yea another one of those lol.

I am having issues with skills.

so lets say you have certain skills for certain classes of characters and they are unlocked as you level up. How would I make an array of skills that are tied into your character level to unlock the skills it needs. Then, how would i let the user choose what skills would go into the skills displayed on the battlefield for the user to use.

here is what I have so far when you are at the battlefield only. It is incomplete. All the #includes are for testing purposes and what I am using in the actual program I am trying to make. How would I display what skills the user chose to put into whatever slot they chose with the Array that displays the skills on the battlefield for a user to choose which to use?

I am not sure if I am coming out clear so please feel free to ask questions.
disregard variables not being used.
the stats are just for testing as well.

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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#define NOMINMAX     // Must define NOMINMAX before including windows.h if you want to use the min() and max() macros.
#include <iostream>
#include <limits>    // This header used for the cin.ignore(numeric_limits<streamsize>max(), '\n');
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <fstream>
#include <string>
#include <time.h>
#include <Windows.h>
#include <iomanip>

using namespace std;

void battlefieldMenu(string, string, int, int, int, int, int, int);
double cAttack(int, int, int, int);
double mAttack(int, int, int, int);
void clearScreen();

void main ()
{

   string charName, mobName;
   int charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic,
       battlefieldSelection, charStr, charDef, charDex, charIntel,
       mobStr, mobDef, mobDex, mobIntel, cAttackCalc, mAttackCalc, selection, youWin = 1,
       skillCount = 1, skillSelection;

   string skillsArr [5] = {"fire", "water", "earth", "whatever", "hello"};
   int inventory [25];

   charName = "James";
   mobName = "Mob";
   charLevel = 1;
   mobLevel = 1;
   charHealth = 100;
   mobHealth = 100;
   charMagic = 100;
   mobMagic = 100;
   mobDef = 30;
   mobStr = 35;
   charDef = 20;
   charStr = 55;

   cout << fixed << showpoint << setprecision(2);

   battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);

   cin >> selection;

   // input validation
   while (selection < 1 || selection > 3){

      if (cin.fail()){

         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
      }

      cout << "Please enter a correct choice   ";
      cin >> selection;
   }


   while (charHealth > 0 && mobHealth > 0){

      switch(selection){

      case 1:
         {

            cAttackCalc = cAttack(charLevel, mobLevel, charStr, mobDef);
            clearScreen();
            mobHealth -= cAttackCalc;

            if (mobHealth <= 0){

               cout << "You win!\n\n";
               system ("pause");

               youWin = 0;

               break;
            }

            battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);
            cout << "You did " << cAttackCalc << " damage\n\n";

            system("pause");

            mAttackCalc = mAttack (charLevel, mobLevel, charDef, mobStr);
            clearScreen();
            charHealth -= mAttackCalc;

            if (charHealth <= 0){

               cout << "You lose...\n\n";
               system ("pause");

               youWin = 0;

               break;
            }

            battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);
            cout << "The enemy did " << mAttackCalc << " damage\n\n";

            system("pause");
            break;
         }

      case 2:
         {

            clearScreen();

            for (int i = 0; i < 5; i++){
               cout << "(" <<  skillCount << ") ";
               cout << skillsArr[i] << "  ";
               skillCount++;
            }

            cout << endl << endl;

            cout << "Choose a skill...";
               cin >> skillSelection;

               //input validation
               while (selection < 1 || selection > 3){

                  if (cin.fail()){

                     cin.clear();
                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
                  }

                  cout << "Please enter a correct choice   ";
                  cin >> selection;
               }

               switch (skillSelection){

               case 1:
                  {



                  }

               }

            cout << endl << endl;

            system("pause");
            break;
         }

      case 3:
         {
            break;
         }

      }

      if(youWin == 0){
         break;
      }

      cin >> selection;
   }
}

void clearScreen()
{
   DWORD n;                         /* Number of characters written */
   DWORD size;                      /* number of visible characters */
   COORD coord = {0};               /* Top left screen position */
   CONSOLE_SCREEN_BUFFER_INFO csbi;

   /* Get a handle to the console */
   HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );

   GetConsoleScreenBufferInfo ( h, &csbi );

   /* Find the number of characters to overwrite */
   size = csbi.dwSize.X * csbi.dwSize.Y;

   /* Overwrite the screen buffer with whitespace */
   FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
   GetConsoleScreenBufferInfo ( h, &csbi );
   FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );

   /* Reset the cursor to the top left position */
   SetConsoleCursorPosition ( h, coord );
}

double mAttack(int cLevel, int mLevel, int cDef, int mStr)
{
   double health = 100.00;

   double deductCharHealth = (mStr / 2) - (cDef / 2);
   double deduct = (rand()%(int)deductCharHealth) + (deductCharHealth - (deductCharHealth * 0.75));

   return deduct;
}

double cAttack(int cLevel, int mLevel, int cStrength, int mDefense)
{
   double health = 100.00;
   double deductMobHealth = (cStrength / 2) - (mDefense / 2);
   double deduct = (rand() % (int)deductMobHealth) + ((int)deductMobHealth - (deductMobHealth * 0.75));

   return deduct;

}

void battlefieldMenu(string cName, string mName, int cLevel, int mLevel, int cHealth, int mHealth, int cMagic, int mMagic)
{
   // choose your selection.
   int selection;

   // displays both character's information.
   cout << "Level - " <<  cLevel << setw(21) << "Level - " << mLevel << endl
      << cName << setw(20) 
      << mName << endl
      << "Health -" << setw(5) << cHealth << setw(17) << " Health -" << setw(5) << mHealth << endl
      << "Magic  -" << setw(5) << cMagic << setw(17) << "Magic  -" << setw(5) <<  mMagic << endl;

   cout << endl;

   cout << "Choose an option\n"
      << "(1) Attack\n"
      << "(2) Skills\n"
      << "(3) Open Inventory\n\n";
}
Last edited on
Why are you not using classes for this text rpg? It would make things so much easier!

You must change void main() to int main() too.
I have not learned classes yet. Just finished my first semester of software engineering and learned all the way up to multidimensional arrays so far.

Ive heard classes would make it much easier.

it is really this piece of code right here

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
case 2:
         {

            clearScreen();

            for (int i = 0; i < 5; i++){
               cout << "(" <<  skillCount << ") ";
               cout << skillsArr[i] << "  ";
               skillCount++;
            }

            cout << endl << endl;

            cout << "Choose a skill...";
               cin >> skillSelection;

               //input validation
               while (selection < 1 || selection > 3){

                  if (cin.fail()){

                     cin.clear();
                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
                  }

                  cout << "Please enter a correct choice   ";
                  cin >> selection;
               }

               switch (skillSelection){

               case 1:
                  {



                  }

               }


How would I display the skills chosen and equipped in their slots by the user in previous menus, here. as well as having the correct damage and everything for the correct skills so when the user enters 1, lets say for instance here its fire, it would do the correct damage needed with whatever calculations i choose to use.
Well first of all, I would question if you actually want to do this. Writing a text based RPG is a long and difficult process. Doing this project without classes means it will be much unlike future game projects that you do and so I don't think doing this RPG will even be of much benefit.


How would I make an array of skills that are tied into your character level to unlock the skills it needs.


This question makes no sense, but I think you were trying to ask how to unlock different skills depending on your character's level and class? If so, then just do it with if statements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if(characterclass == "wizard" && level == 10)
{
    //unlock something only wizards  can use that are lvl 10+
}
else if(characterclass == "rogue" && level == 10)
{
    //unlock something only rogues lvl 10+ can use. 
}
else if(characterclass == "human" && level == 15)
{
    //unlock something only level 15 humans can use
}

//You could use bool to check if things are locked/unlocked.   



Then, how would i let the user choose what skills would go into the skills displayed on the battlefield for the user to use.


So let's say you can have 4 skills displayed on the main screen, something like this will do it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string mainscreenskills[4]; 
string selectedskill; 
int i;
bool valid = 0; 
for(i = 0; i < 4; ++i)
{
     do
     {
     std::cout << "Type the name of the skill you want to use in slot 1: "; 
     //Might want to display user skill list here 
     std::cin >> selectedskill; 
    //Check this skill exists and the character can use it. 
    //If the skill exists 
    valid = 1; //Success; 
    mainscreenskills[i] = selectedskill; 
    }while(valid == 0) //Keep doing this loop until valid input is entered. 
//for loop will continue for 3 more runs to fill the other skills. 
}


How would I display the skills chosen and equipped in their slots by the user in previous menus, here. as well as having the correct damage and everything for the correct skills so when the user enters 1, lets say for instance here its fire, it would do the correct damage needed with whatever calculations i choose to use.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
string skill; 
int enemyhealth, playerfireskill, playerweaponskill; 
do //Do some user input validation. 
{
std::cout << "Select skill: "; 
std::cin >> skill; 
}while(skill is not valid); 

if(skill == "fire")
{
    enemyhealth = enemyhealth - playerfireskill; 
}
else if(skill == "weapon")
{
    enemyhealth = enemyhealth - playerweaponskill; 
}



Last edited on
As Mats has mentioned, classes would make this less hardcoded and more streamlined. I realize that you probably only want a direct answer to your question, using the stylistic choices you've elected to use, and don't want to hear about classes.
However, I'm an object-oriented programming advocate. Here's a crash course in classes. Feel free to ignore this if you don't care. If you do care, the following summary is by no means complete, and you should at least read the documentation on this website.

Classes allow you to "create" your own type of variables.
Classes are often most closely associated with the Object-oriented programming paradigm, because a class can behave like a real world object very easily.
What do I mean with that? Basically, with classes it's very easy to model real world intuitive concepts.
At this point, I will not cover the basics of separating class declarations and implementations into different files, so don't worry about that yet.

Before we look at the syntax of creating a class, let's look at the syntax for creating a struct. "struct" is short for "structure". A structure is almost the same thing as a class, with only a few differences in their development timeline. I'll address this later, but for know, just be aware that a struct and a class are BASICALLY the same thing.

Here's the syntax for creating a struct:

1
2
3
struct MyStruct {
	int a;
};


Here's what we can say about this struct:
1.) The name of the struct is "MyStruct"
2.) It has an integer, which is named "a". One could say that this integer is a member variable of the MyStruct type.

Also note the semi-colon at the end of the struct declaration. A common mistake is to forget the semi-colon, which will result in a compilation error.
Another important distinction to know is the difference between the words "declaration" and "definition" or "implementation".
"declaration" is what I did above. I declared the struct, in other words, I'm saying that this struct exists. However, I didn't "define" it. When people talk about "defining" or "implementing" a struct or class, they're talking about giving actual values to the member variables in a struct or class (which has been declared).

Back to MyStruct... because it has a member variable integer named "a", we
know that every MyStruct object will have it's own "a" integer.
Here is how I might use the MyStruct struct:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

struct MyStruct {
	int a;
};

int main() {
	MyStruct one;// MyStruct object named "one"
	MyStruct two;// MyStruct object named "two"

	one.a = 9;//	assign 9 to one's "a"
	two.a = 400;//	assign 400 to two's "a"

	std::cout << "one.a:\t" << one.a << std::endl;
	std::cout << "two.a:\t" << two.a << std::endl;

	std::cin.get();
	return 0;
}


The same code would work if I changed the name of the member variable "a" to something else. However, I would have to change all the lines where I'm accessing "a" as well, because in that case "a" wouldn't exist anymore.

The same program, only having changed the name of "a" to "b".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

struct MyStruct {
	int b;
};

int main() {
	MyStruct one;// MyStruct object named "one"
	MyStruct two;// MyStruct object named "two"

	one.b = 9;//	assign 9 to one's "b"
	two.b = 400;//	assign 400 to two's "b"

	std::cout << "one.b:\t" << one.b << std::endl;
	std::cout << "two.b:\t" << two.b << std::endl;

	std::cin.get();
	return 0;
}



You can access an object's members with the dot operator (.).
There are some things to know about accessing members, however. I'll try to write some more here later.

The point is, that you can easily wrap things like Skills and Players into classes or structs. Here's a pseudo-code example:

1
2
3
4
5
6
7
8
9
10
struct Skill {
	std::string name;// Name of the skill
	int modifier;// Might be base damage of skill
};

struct Player {
	const static unsigned short num_skills = 9;//max number of skills
	Skill skills[num_skills];// an array of skills (skill slot)
	int health;
};
Last edited on
Ok thanks guys. I now see why this is so hard lol. I will re think this entire process and learn how to do classes and structs first. It seems like not only does is simplify it down but makes it easier to manage and control what happens later on.
So since i am new to classes and all. Lets say I need to create a class for Paladin.

how would I go about initializing the skills that a paladin could have and its correct attributes.

the basic structure would start like this

1
2
3
4
5
6
class Paladin {

   int str, def, intel, dex;


};
should I be doing it like this? I have no clue sorry.

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
class Paladin{
public:
   int str, intel, def, dex;
};

class Mage {
public:
   int str, intel, def, dex;
};

class  Warrior {
public:
   int str, intel, def, dex;
};

class Assassin {
public:
   int str, intel, def, dex;
};

class Archer {
public:
   int str, intel, def, dex;
};


int main ()
{  // start int main()

   // Paladin Stats
   Paladin pStr;
   pStr.str = 15;
   Paladin pDef;
   pDef.def = 15;
   Paladin pInt;
   pInt.intel = 10;
   Paladin pDex;
   pDex.dex = 5;

   //Mage Stats
   Mage mStr;
   mStr.str = 5;
   Mage mDef;
   mDef.def = 5;
   Mage mInt;
   mInt.intel = 20;
   Mage mDex;
   mDex.dex = 10;

   // Warrior Stats
   Warrior wStr;
   wStr.str = 20;
   Warrior wDef;
   wDef.def = 10;
   Warrior wInt;
   wInt.intel = 5;
   Warrior wDex;
   wDex.dex = 5;

   // Assassin Stats
   Assassin aStr;
   aStr.str = 10;
   Assassin aDef;
   aDef.def = 5;
   Assassin aInt;
   aInt.intel = 5;
   Assassin aDex;
   aDex.dex = 20;

   // Archer Stats
   Archer arStr;
   arStr.str = 15;
   Archer arDef;
   arDef.def = 5;
   Archer arInt;
   arInt.intel = 5;
   Archer arDex;
   arDex.dex = 15;

   system("pause");
   return 0;

}  // end int main() 


Should i be declaring the stats along with the classes or is that not needed, just things like skills and stuff. idk. Im pretty much lost with this whole class thing.
Sorry to disappoint you, but you will probably not be able to do it for quite some time.
You need to understand dependencies and links between classes in game, how game work(game loop, etc), before you can do text RPG. Can you make 2-D arcanoid game? Making text RPG is much harder.

You need to know inheritance, polymorphism, and these are the absolute minimum. I also tried to write text RPG when I was beginning my programming adventure.
It's simple when you think of it. It's harder when you try to do it.

I mean, it depends on what you define by "text RPG". If you want to make some really really simple game, linear and such - no problem. BUt most of the time text RPG is RPG without bounds of 2/3D graphics, which allow user to play just fine, but instead of graphics you use imagination, and you use commands to walk around.
I strongly recommend you focusing on learning C++ so that you are quite comfortable in in. You can also start learning some basic game programming on side. After that, you may want to do simple 2D games, so that you learn how games work.
And after that you will know, when you may try to make text RPG.

That's my advice. You may, of course, ignore it; but as I said, I wouldn't predict you much success unless you are really stubborn.
And you would have to learn many things anyway.

You may want to check out these sites(really useful):
http://www.sloperama.com/advice.html
http://www.holub.com/goodies/rules.html
http://www-cs-students.stanford.edu/~amitp/gameprog.html
http://www.gamasutra.com/

http://www.3dbuzz.com/training/view/c-plus-plus-complete/intro-to-game-dev <-- this may allow you to "build" your first game that is actually nice(plus there are few things you can improve, so it's nice training :) )

http://lazyfoo.net/SDL_tutorials/index.php

Good luck!
thanks man! appreciate the advice. Yea after doing some research. Ive seen many things I have not learned in school yet, which I will be learning in this upcoming semester of my degree. I didnt realize how difficult it actually would be. I will try to get a jump ahead of my class and learn about it now and practice small things.

Are there any small projects you would recommend for me to practice classes and such things like that to get a little familiar with it? My above post I now realize is definitely not in any way how I would approach making the game that I would like to make lol. Dissappointing :( lol.
You practice best when you write code.
However, before you start writing your own code, go through several class tutorials - these got some nice simple classes that will teach you what do you use class for and how.

Try out 3dbuzz, you will see how clases work in real game.(simple one, yet quite enjoyable)
Try out SDL tutorials from lazyfoo, you will learn how to create some classes for objects that can be printed to screen. Also, you will learn how to make some wrapper classes(if I remember correctly).
Try some online tutorials on classes, inheritance, etc. so you know what is going on in tutorials above.

Right now don't write the game so that it's good, fun, etc. Write a game to learn something new.
If you start writing game, but it isn't perfect, yet you learned something - it's success for you. Don't spend too much time making perfect game. It won't be perfect, and even if you make perfect tic-tac-toe - no one will play it. Go on, just make sure it's playable, not too buggy, and make sure you learned something.


Wrapper class is a class that takes another class, and adds new features to it.
For example, in SDL 2.0 you have "SDL_Texture", which is a structure that allows you to load image - but it has no function that can tell you width or height of texture. So I made wrapper class(I called "Texture"), so now instead of using SDL_Texture, I use my wrapper class Texture - and my class allows me to check width and height. That's simple example, but I hope it will do.

It's obvious that you want to make a big game, but the higher you aim, the harder you hit the ground.

Also, if you need help, you may want to try:
http://stackoverflow.com/
http://gamedev.stackexchange.com/

And when you don't know what game you should do, here are some examples:
http://gamedev.stackexchange.com/questions/854/what-are-good-games-to-earn-your-wings-with/1047#1047

Cheers!
Topic archived. No new replies allowed.