-
Notifications
You must be signed in to change notification settings - Fork 0
/
Text-Based-Adventure.cpp
487 lines (435 loc) · 18.4 KB
/
Text-Based-Adventure.cpp
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#include <iostream>
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <ctime>
using namespace std;
class Tribute {
string name; // Attributes
int defense;
int speed;
int strength;
int camouflage;
int district;
string weapon;
vector<string> inventory;
public :
Tribute(string na, int df, int sp, int st, int cf, int ds, string wp) : name(na), defense(df), speed(sp), strength(st), camouflage(cf), district(ds), weapon(wp) {} // Constructor
void add_df(int num); // Editors
void sub_df(int num);
void add_sp(int num);
void sub_sp(int num);
void add_st(int num);
void sub_st(int num);
void add_cf(int num);
void sub_cf(int num);
void add_iv(string item); // Add to inventory
bool sub_iv(string item); // Remove from inventory
string get_na(); // Getters
int get_df();
int get_sp();
int get_st();
int get_cf();
int get_ds();
string get_wp();
void get_iv();
~Tribute(); // Destructor
};
bool introduction(); // Functions
Tribute character_selection();
bool character_preview(Tribute user);
bool if_dead(int trait, int liveChance);
void entrance(Tribute user);
void encounter1(Tribute user);
void encounter2(Tribute user);
void encounter3(Tribute user);
void encounter4(Tribute user);
void encounter5(Tribute user);
void encounter6(Tribute user);
void win();
void dead(string cod);
int main() {
bool selection = introduction(); // Checking if user wants to play
if (!selection) {
cout << "\n";
cout << "Maybe next time!" << "\n";
cout << "\n";
return 0;
}
Tribute user = character_selection(); // User picks valid tribute
while (user.get_na() == "default") {
cout << "\nSorry, wrong selection. Please try again:\n";
user = character_selection();
}
if (!character_preview(user)) { // Second validation to start the game
cout << "\n";
cout << "Maybe next time!" << "\n";
cout << "\n";
return 0;
}
entrance(user); // Hunger Games Begin!
return 0;
}
void Tribute::add_df(int num) { defense += num; }
void Tribute::sub_df(int num) { defense -= num; }
void Tribute::add_sp(int num) { speed += num; }
void Tribute::sub_sp(int num) { speed -= num; }
void Tribute::add_st(int num) { strength += num; }
void Tribute::sub_st(int num) { strength -= num; }
void Tribute::add_cf(int num) { camouflage += num; }
void Tribute::sub_cf(int num) { camouflage -= num; }
void Tribute::add_iv(string item) {
inventory.push_back(item);
}
bool Tribute::sub_iv(string item) {
for (int i = 0; i < inventory.size(); i++) {
if (item == inventory[i]) {
inventory[i].erase();
return true;
}
}
return false;
}
string Tribute::get_na() { return name; }
int Tribute::get_df() { return defense; }
int Tribute::get_sp() { return speed; }
int Tribute::get_st() { return strength; }
int Tribute::get_cf() { return camouflage; }
int Tribute::get_ds() { return district; }
string Tribute::get_wp() { return weapon; }
void Tribute::get_iv() {
cout << "Your inventory: ";
for (int i = 0; i < inventory.size(); i++) {
if (i == inventory.size() - 1) {
cout << inventory[i]; break;
}
cout << inventory[i] << ", ";
}
}
Tribute::~Tribute() {}
bool introduction() {
string user;
cout << "\n";
cout << "Welcome to the 74th Annual Hunger Games. . . Are you ready to begin? (Yes or No): ";
cin >> user;
if (user == "Yes" || user == "yes" || user == "Y" || user == "y") { return true; }
else { return false; }
}
Tribute character_selection() {
int selection;
cout << "\nSelect your tribute!" << "\n";
cout << "\n1. Marvel \n2. Glimmer \n3. Cato \n4. Clove \n5. Foxface \n6. Thresh \n7. Rue \n8. Peeta \n9. Katniss \n \nYour selection is: ";
while (!(cin >> selection)) {
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\nSelect your tribute!" << "\n";
cout << "\n1. Marvel \n2. Glimmer \n3. Cato \n4. Clove \n5. Foxface \n6. Thresh \n7. Rue \n8. Peeta \n9. Katniss \n \nYour selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : { // District 1
Tribute _1("Marvel", 30, 80, 50, 40, 1, "Spear"); // Specialty Luxury
return _1;
}
case 2 : {
Tribute _2("Glimmer", 30, 80, 30, 60, 1, "Bow");
return _2;
}
case 3 : { // District 2
Tribute _3("Cato", 60, 30, 90, 20, 2, "Sword"); // Specialty Guns
return _3;
}
case 4 : {
Tribute _4("Clove", 70, 90, 20, 20, 2, "Knife");
return _4;
}
case 5 : { // District 5
Tribute _5("Foxface", 20, 80, 10, 90, 5, "Knife"); // Specialty Energy
return _5;
}
case 6 : { // District 11
Tribute _6("Thresh", 60, 20, 100, 20, 11, "Sword"); // Specialty Agriculture
return _6;
}
case 7 : {
Tribute _7("Rue", 10, 80, 10, 100, 11, "Knife");
return _7;
}
case 8 : { // District 12
Tribute _8("Peeta", 10, 10, 80, 100, 12, "Sword"); // Specialty Mining
return _8;
}
case 9 : {
Tribute _9("Katniss", 80, 50, 50, 20, 12, "Bow");
return _9;
}
default : {
Tribute def("default", 0, 0, 0, 0, 0, "");
return def;
}
}
}
bool character_preview(Tribute user) {
string selection;
cout << "\nYou have selected " << user.get_na() << " from District " << user.get_ds() << ", these are your skill stats:\n";
cout << "\nDefense - " << user.get_df() << "\nSpeed - " << user.get_sp() << "\nStrength - " << user.get_st() << "\nCamouflage - " << user.get_cf() << "\n";
cout << "\nAre you now ready to start the Hunger Games? (Yes or No): "; cin >> selection;
if (selection == "Yes" || selection == "yes" || selection == "Y" || selection == "y") { return true; }
else { return false; }
}
bool if_dead(int trait, int liveChance) {
srand(time(0)); int chance = rand() % 100 + 1;
if (((trait + liveChance) / chance) < 1) {
return true;
}
return false;
}
void entrance(Tribute user) {
int selection;
cout << "\n. . .\n\n"; sleep(3); cout << "You are entering the arena. . .\n"; sleep(3);
cout << "\nYou are in a grass field and have a large forest behind you. . .\n"; sleep(4);
cout << "\nYou see the the Cornucopia with supplies and weapons in front of you, as well as backpacks on the outer edge of the center with unknown items. . .\n";
sleep(6); cout << "\nYou start to hear a countdown. . ."; cout << "\n"; cout << "\n3"; sleep(2);
cout << "\n2"; sleep(2); cout << "\n1"; sleep(2); cout << "\n"; sleep(2); cout << "\nA cannon has fired, the Hunger Games have started!\n";
sleep(3); cout << "\nEveryone starts running around you, where do you want to run?\n\n1. Cornucopia\n2. Backpack\n3. Forest\n4. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 4)) {
if (selection == 4) {
cout << "\nYour Inventory is currently empty\n";
cout << "\n1. Cornucopia\n2. Backpack\n3. Forest\n4. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Cornucopia\n2. Backpack\n3. Forest\n4. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch(selection) {
case 1 : {
cout << "\nYou run to the Cornucopia and pass by everyone, you have a short amount of time before someone notices you, you grab a backpack and a " << user.get_wp() << " and run.\n";
sleep(6); cout << "\nHere are your updated stats:\n"; sleep(3);
user.add_df(20); user.add_st(20); user.sub_sp(20);
cout << "\nDefense - " << user.get_df() << "\nSpeed - " << user.get_sp() << "\nStrength - " << user.get_st() << "\nCamouflage - " << user.get_cf() << "\n\n";
user.add_iv("Rope"); user.add_iv("Empty water bottle"); user.add_iv("Knife"); user.add_iv("Matches"); user.add_iv(user.get_wp());
encounter1(user);
break;
}
case 2 : {
cout << "\nYou run to the backpacks around the Cornucopia, you have a short amount of time before someone notices you, you grab a backpack and run.\n";
sleep(6); cout << "\nHere are your updated stats:\n"; sleep(3);
user.add_df(10); user.add_st(10); user.sub_sp(10);
cout << "\nDefense - " << user.get_df() << "\nSpeed - " << user.get_sp() << "\nStrength - " << user.get_st() << "\nCamouflage - " << user.get_cf() << "\n\n";
user.add_iv("Rope"); user.add_iv("Empty water bottle"); user.add_iv("Knife"); user.add_iv("Matches");
encounter1(user);
break;
}
case 3 : {
cout << "\nYou run straight to the forest to avoid conflict, you pick up nothing.\n";
sleep(6); cout << "\nHere are your updated stats:\n"; sleep(3);
cout << "\nDefense - " << user.get_df() << "\nSpeed - " << user.get_sp() << "\nStrength - " << user.get_st() << "\nCamouflage - " << user.get_cf() << "\n\n";
encounter1(user);
break;
}
}
}
void encounter1(Tribute user) {
int selection;
sleep(2); cout << "While running to the forest, you see someone ahead of you. What do you want to do?\n\n1. Attack\n2. Run other way\n3. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 3)) {
if (selection == 3) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Attack\n2. Run other way\n3. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Attack\n2. Run other way\n3. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
if (!if_dead(user.get_st(), 80)) {
sleep(2); cout << "\nYou successfully eliminated the other tribute.\n";
encounter2(user);
}
else { dead("another tribute"); }
break;
}
case 2 : {
if (!if_dead(user.get_sp(), 80)) {
sleep(2); cout << "\nYou successfully avoided the other tribute.\n";
encounter2(user);
}
else { dead("another tribute"); }
break;
}
}
}
void encounter2(Tribute user) {
int selection;
sleep(2); cout << "\nIt starts to get dark, what do you want to do?\n\n1. Take cover\n2. Hunt for other people\n3. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 3)) {
if (selection == 3) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Take cover\n2. Hunt for other people\n3. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Take cover\n2. Hunt for other people\n3. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
if (!if_dead(user.get_cf(), 60)) {
sleep(2); cout << "\nYou successfully took cover for the night.\n";
encounter3(user);
}
else { dead("another tribute"); }
break;
}
case 2 : {
if (!if_dead(user.get_st(), 60)) {
sleep(2); cout << "\nYou found another tribute and eliminated them. You picked up armor and put it on. You then went to sleep for the night.\n";
user.add_iv("Armor"); user.add_df(20);
encounter3(user);
}
else { dead("another tribute"); }
break;
}
}
}
void encounter3(Tribute user) {
int selection;
sleep(2); cout << "\nYou wake up parched and in need of water, what do you want to do?\n\n1. Find water\n2. Ignore your body\n3. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 3)) {
if (selection == 3) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Find water\n2. Ignore your body\n3. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Find water\n2. Ignore your body\n3. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
sleep(2); cout << "\nYou climb up a tree and find the nearest water source. You drink up and refill any containers you have.\n";
if (user.sub_iv("Empty water bottle")) {
user.add_iv("Full water bottle");
}
encounter4(user);
break;
}
case 2 : { dead("dehydration"); break; }
}
}
void encounter4(Tribute user) {
int selection;
sleep(2); cout << "\nAfter getting water, you see a group of tributes approaching you from the other side of the pond, what do you want to do?\n\n1. Defend yourself\n2. Run away\n3. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 3)) {
if (selection == 3) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Defend yourself\n2. Run away\n3. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Defend yourself\n2. Run away\n3. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
if (!if_dead(user.get_df(), 40)) {
sleep(2); cout << "\nYou successfully defended your position from the team of tributes. The other tributes had other weapons and armor. You take the armor and move on.\n";
user.add_df(20);
if (!user.sub_iv("Armor")) {
user.add_iv("Armor");
}
encounter5(user);
}
else { dead("other tributes"); }
break;
}
case 2 : {
if (!if_dead(user.get_sp(), 40)) {
sleep(2); cout << "\nYou successfully ran away from the team of tributes.\n";
encounter5(user);
}
else { dead("other tributes"); }
break;
}
}
}
void encounter5(Tribute user) {
int selection;
sleep(2); cout << "\nAfter encountering the team of tributes, you realize you are hungry and scavenge. You find an apple and darkblue berries. What do you want to do?\n\n1. Eat apple\n2. Eat berries\n3. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 3)) {
if (selection == 3) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Eat apple\n2. Eat berries\n3. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Eat apple\n2. Eat berries\n3. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
sleep(2); cout << "\nYou eat the apple and move on.\n";
encounter6(user);
break;
}
case 2 : { dead("nightlock berries"); break; }
}
}
void encounter6(Tribute user) {
int selection;
sleep(2); cout << "\nThe sky quickly becomes dark and you realize that the Hunger Games are coming to an end. . .\n";
sleep(4); cout << "\nYou start to hear growls behind you in the forest, what do you want to do?\n\n1. Defend yourself\n2. Run towards Cornucopia\n3. Hide in nearby bushes\n4. Check Inventory\n\nYour Selection is: ";
while ((!(cin >> selection)) || (selection < 1) || (selection >= 4)) {
if (selection == 4) {
cout << "\n"; user.get_iv();
cout << "\n\n1. Defend yourself\n2. Run towards Cornucopia\n3. Hide in nearby bushes\n4. Check Inventory\n\nYour Selection is: ";
continue;
}
cout << "\nSorry, wrong selection. Please try again:\n";
cout << "\n1. Defend yourself\n2. Run towards Cornucopia\n3. Hide in nearby bushes\n4. Check Inventory\n\nYour Selection is: ";
cin.clear();
cin.ignore(123, '\n');
}
switch (selection) {
case 1 : {
if (!if_dead(user.get_df(), 20)) {
sleep(2); cout << "\nYou successfully defended your position from the muts, and hear crys far away from other tributes.\n";
win();
}
else { dead("muts"); }
break;
}
case 2 : {
if (!if_dead(user.get_sp(), 20)) {
sleep(2); cout << "\nYou successfully ran away from the muts, and hear crys far away from other tributes.\n";
win();
}
else { dead("muts"); }
break;
}
case 3 : {
if (!if_dead(user.get_cf(), 20)) {
sleep(2); cout << "\nYou successfully hid from the muts and was undetected, you hear crys far away from other tributes.\n";
win();
}
else { dead("muts"); }
break;
}
}
}
void win() {
sleep(2); cout << "\nCongratulations! You have won the 74th Annual Hunger Games!\n\n";
}
void dead(string cod) {
sleep(2); cout << "\nYou died from " << cod << ". Better luck next time!\n\n";
}