text based RPG

I really dont have much of a question. still pretty much learning the basics right now. i just want some feedback. im mostly just outlining right now for a text based rpg game.

I dont really have a story line thought out yet. And i dont really know where to go with the simple stats integers that are produced or how to use them for fight scenes ect...
IM NOT ASKING FOR INFO ABOUT THAT STUFF THOUGH!

i just want to know if this is a good start and a little bit of info as to if im headed in the right direction as far as how my learning is going right now.

also, does anyone have a suggestion for some websites i can look at for some more useful info on programming text based games?

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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#include <iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{

	//Character info list
	char Name [20];
	
	int HP;
	int MP;
	int STR;
	int DEF;
	int LUCK;
	
	int Gender;
	
	
	//Choices
	int MenuChoice;
	char BACK;
	int NAME;
	int STATS;
	int CHOICE1;
	int RAND;
	
		//  Title screen Rogue
	//  '\\' is required for '\' to be displayed
	cout << endl;
	cout << "  ____                        " << endl;
	cout << " |  _ \\ ___   __ _ _   _  ___ " << endl;
	cout << " | |_) / _ \\ / _` | | | |/ _ \\" << endl;
	cout << " |  _ < (_) | (_| | |_| |  __/" << endl;
	cout << " |_| \\_\\___/ \\__, |\\__,_|\\___|" << endl;
	cout << "             |___/            " << endl << endl;
	
	cout << endl << "By Anthony Branda" << endl << endl;
	
	//Plays sound

	//Main Menu
Menu:
	cout << " __________________" << endl;
	cout << "|----Menu----------|" << endl;
	cout << "|------------------|" << endl;
	cout << "|-1.-Start Game----|" << endl;
	cout << "|-2.-Options-------|" << endl;
	cout << "|-3.-Quit Game-----|" << endl;
	cout << "|------------------|" << endl;
	cout << " Make your choice: ";
	
	cin >> MenuChoice;
	{
		if(MenuChoice == 1)
		{
			//starts the game
			system("cls");
		}
		else if(MenuChoice == 2)
		{
			//options
			//try and put playable music option on or off
			system("cls");
			
			cout << endl << "We are working on options" << endl;
			
			cout << "Press any key to continue: ";
			
			cin >> BACK;
			
			system("cls");
			
			goto Menu;
		}
		else if(MenuChoice == 3)
		{
			return 0;
		}
	}
	
Stats:
		//Stats
			//Not 100% sure why strand time is needed but it is..
			//FIGURE THAT OUT!
	srand(time(0));
	
	HP = rand()%15+1;
	MP = rand()%15+1;
	STR = rand()%9+2;
	DEF = rand()%9+2;
	LUCK = rand()%9+2;
	
	cout << "To start out, please make a choice of what you would like your stats to be." << endl;
	
	cout << "When you find the stats you are happy with, press the 1." << endl;
	
	cout << "If you are unhappy with the stats, press the 2." << endl;
	
	cout << "The stats are completely random." << endl << endl;
	
	cout << "HP:" << HP << ", MP:" << MP << ", STR:" << STR<< ", DEF:" << DEF << ", LUCK:" << LUCK << endl;
	
	cin >> STATS;
	{
		if(STATS == 1)
		{
			cout << "Your stats have been set." << endl << endl << endl;
		}
		else if(STATS == 2)
		{
			system("cls");
			goto Stats;
		}
	}
Name:
	cout << "Now, what is your name?" << endl;
	cin >> Name;
	system("cls");
	cout << endl << endl << "So your name is: " << Name << "?" << endl << endl;
	cout << "(1=Yes, 2=No.)"<< endl;
	cin >> NAME;
	{
		if(NAME == 1)
		{
			cout << "Ok, " << Name << " are you a male or a female?" << endl << endl;
			cout << "(1=Male, 2=Female.)" << endl;
			cin >> Gender;
			goto Gender;
		}
		else if(NAME == 2)
		{
			system("cls");
			goto Name;
		}
	}
Gender:
	{
		if(Gender == 1)
		{
			system("cls");
			cout << endl << "Ok, you are a guy.";
		}
		else if(Gender == 2)
		{
			system("cls");
			cout << endl << "Ok, you are a girl." << endl << endl;
		}
	}
	
	cout << endl << endl << "You wake up in your small campsite." << endl;
	cout << "You have been on your own for just a short time now and have decided to set up base outside of a forest." << endl;
	cout << "The forest is to the East and there are grass lands to the West." << endl << endl;
	
Camp:	
	srand(time(0));
	
	RAND = rand()%10+1;
	
	cout << "What would you like to do?" << endl << endl;
	cout << "(1=Explore Forest, 2=Explore Grass Lands)" << endl;
	cin >> CHOICE1;
	{
	if(CHOICE1 == 1)
		{
			if(RAND == 1)
			{
				cout << "1" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 2)
			{
				cout << "2" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 3)
			{
				cout << "3" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 4)
			{
				cout << "4";
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 5)
			{
				cout << "5" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 6)
			{
				cout << "6" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 7)
			{
				cout << "7" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 8)
			{
				cout << "8" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 9)
			{
				cout << "9" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 10)
			{
				cout << "10" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
		}
	else if(CHOICE1 == 2)
			{
			if(RAND == 1)
			{
				cout << "1" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 2)
			{
				cout << "2" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 3)
			{
				cout << "3" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 4)
			{
				cout << "4" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 5)
			{
				cout << "5" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 6)
			{
				cout << "6" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 7)
			{
				cout << "7" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 8)
			{
				cout << "8" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 9)
			{
				cout << "9" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
			else if(RAND == 10)
			{
				cout << "10" << endl;
				cout << endl << "Press any key to continue.";
				cin >> BACK;
				system("cls");
				goto Camp;
			}
		}
}
	
	
	cout << endl << endl << endl << endl;
	
	// Ends the game
char EndGame;	
	cout << endl << endl << "Press any key, then hit enter to continue..." << endl;
	cin >> EndGame;
	return 0;
}
Thank you in advance for the tips.
Last edited on
I'm not the best at programming, but my suggestion would be to dip your feet into OOP.

For example, you could have different objects in your game like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Player
{
int attack;
int defense;
string name;

};

class Item
{
int worth;
enum type{}


};


etc etc.

Also, you REALLY shouldn't use goto. Search around for why it's so bad, but you should teach yourself use loops, functions, and possibly gamestates (i don't know how complicated your game will be).

And for the end game, you don't have to do
cin >> EndGame

just do

std::cin.get();

:)
Last edited on
Generally, when making any sort of game, you should plan first and implement second.

I would listen to kong here regarding design. You'll save yourself a LOT of headache by getting acquainted with classes, and splitting your program up. Before you do that, though, split your program up into functions. Walk before you can jog.

Also. Kong is also right when he tells you not to use goto. Goto is a readability nightmare and there aren't that many cases when its use is better than using a function.

Also, you may want to use std::string instead of char[] or char*. This way you won't run into length issues, not to mention that std::strings provide a lot of fun string manipulation functions directly built in that are convenient to use. #include <string> to use them.

-Albatross

P.S.- The srand(time(0)) bit is what makes rand() random. ;)
Firstly you should use subprograms for repeated code.

Secondly when you have a bunch of things that do same thing and the only thing that changes is a number you should use a variable for that number.

Anyways lines 166 - 330 could be simplified as this:

1
2
3
4
5
6
7
8
if( ( choice == 1 || choice == 2 ) && ( RAND > 0 && RAND < 11 ) )
{
    cout << RAND << endl;
    cout << endl << "Press any key to continue.";
    cin >> BACK;
    system("cls");
    goto Camp;
}



Though I do NOT suggest you use system( "ANYTHING" ) or goto statements.
Topic archived. No new replies allowed.