-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDungeonEscape.cpp
624 lines (565 loc) · 15.5 KB
/
DungeonEscape.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
//Zeke Morton
//Escape
#include<iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
class User //Modularization class
{
public:
void add_armor (string armor_found, int defense);
void add_weapon(string weapon_found, int attack);
int damage_taken (int damage);
void restore_health();
int get_attack();
int get_defense();
int get_health();
void check_user_death();
bool check_defeated(string name);
void add_defeat(string name);
void show_enemies();
private:
int health = 100;
int attack_power = 5;
int defense_power = 5;
vector <string> armor_list; //structure1: vector
vector <string> weapon_list;
string enemies_defeated [15] = {}; //structure2: array
};
int User::get_attack()
{
return attack_power;
}
int User::get_defense()
{
return defense_power;
}
int User::get_health()
{
return health;
}
bool User::check_defeated( string name)
{
bool defeated = false;
for (int i = 0; i < 15;i++)
{
if (enemies_defeated[i] == name)
{
defeated = true;
}
}
return defeated;
}
void User::show_enemies()
{
cout<<"You have defeated these enemies: ";
int counter =0;
for (int i = 0; i < 15;i++)
{
if (enemies_defeated[i] != "")
{
cout<<enemies_defeated[i]<<endl;
counter++;
}
}
if (counter >0)
{
cout<<endl<<"You've defeated "<<counter<<" enemies, Good Job!"<<endl;
}
}
void User::add_defeat(string name)
{
for (int i = 0;i<15;i++)
{
if (enemies_defeated[i] == "")
{
enemies_defeated[i] = name;
break;
}
}
}
void User::add_armor (string armor_found, int defense)
{
bool new_item = true;
for (int i = 0;i < armor_list.size();i++)
{
if (armor_list.at(i) == armor_found)
{
new_item = false;
}
}
if (new_item)
{
defense_power += defense;
armor_list.push_back(armor_found);
cout<<armor_found<<" has been added to inventory."<<endl;
cin.get();
cout<<"Defense has been raised by "<<defense<<" points."<<endl;
cin.get();
}
else
{
cout<<"You already have that armor, so you put it back."<<endl;
cin.get();
}
}
void User::add_weapon (string weapon_found, int attack)
{
bool new_item = true;
for (int i = 0;i < weapon_list.size();i++)
{
if (weapon_list.at(i) == weapon_found)
{
new_item = false;
}
}
if (new_item)
{
attack_power += attack;
weapon_list.push_back(weapon_found);
cout<<weapon_found<<" has been added to inventory."<<endl;
cin.get();
cout<<"Attack has been raised by "<<attack<<" points."<<endl;
cin.get();
}
else
{
cout<<"You already have that weapon, so you put it back."<<endl;
cin.get();
}
}
int User::damage_taken (int damage)
{
health -= damage;
return health;
}
void User::restore_health()
{
health = 100;
}
class Monster
{
public:
int get_attack();
int get_defense();
int get_health();
int damage_taken(int damage);
void set_stats(int hp, int ap,int dp,string n, string weak);
bool check_monster_death();
string get_name();
string get_weakness();
private:
int health;
int attack;
int defense;
string weakness;
string name;
};
int Monster::get_health()
{
return health;
}
string Monster::get_weakness()
{
return weakness;
}
string Monster::get_name()
{
return name;
}
int Monster::damage_taken (int damage)
{
health -= damage;
return health;
}
int Monster::get_attack()
{
return attack;
}
int Monster:: get_defense()
{
return defense;
}
void Monster::set_stats(int hp, int ap,int dp, string n, string weak)
{
health = hp;
attack = ap;
defense = dp;
name = n;
weakness = weak;
}
void room1 (User* user);
int main()
{
cout<<" Dungeon Escape "<<endl;
cout<<"The game is played by using keys 1-4"<<endl;
cout<<"The console is held with cin.get(), so just press enter to continue."<<endl;
cin.get();
User user;
User* user_ptr = &user; //effective use of pointers through out program
srand(time(0));
room1(user_ptr);
}
void User::check_user_death()
{
if (health <= 0 )
{
string temp;
cout<<"You have died"<<endl;
cin.get();
show_enemies();
cin.get();
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
main();
}
}
bool Monster::check_monster_death()
{
if (health <= 0 )
{
return true;
}
else
{
return false;
}
}
void battle(User* user, Monster monster) //Modularization: function
{
bool dead = user->check_defeated(monster.get_name());
if (dead)
{
cout<<"You have already defeated "<<monster.get_name()<<endl;
}
int chance, damage;
int choice;
string hit;
while (!dead)
{
cout<<"Where would you like to attack the "<<monster.get_name()<<"?"<<endl;
cout<<"1) Head"<<endl;
cout<<"2) Torso"<<endl;
cout<<"3) Legs"<<endl;
cout<<"4) Arms"<<endl;
cin>>choice;
switch (choice)
{
case 1:
hit = "Head";
break;
case 2:
hit = "Torso";
break;
case 3:
hit = "Legs";
break;
case 4:
hit = "Arms";
break;
}
chance = rand () % 4+2;
if (hit == monster.get_weakness())
{
chance *= 2;
}
damage = user->get_attack() *chance - monster.get_defense() ;
if (damage < 0)
{
damage = 18;
}
cout<<"You strike monster and deal "<<damage<<" points of damage."<<endl;
if (hit == monster.get_weakness())
{
cout<<"It's super effective!"<<endl;
}
cin.get();
monster.damage_taken(damage);
dead = monster.check_monster_death();
if (dead)
{
cout<<"You have defeated "<<monster.get_name()<<endl;
user->add_defeat(monster.get_name());
}
if (!monster.check_monster_death())
{
chance = rand () % 4+2;
damage = monster.get_attack() * chance - user->get_defense();
if (damage < 1)
{
damage = 13;
}
cout<<"The monster strikes you and deals "<<damage<<" points of damage."<<endl;
cin.get();
user->damage_taken(damage);
user->check_user_death();
}
}
user->restore_health();
}
void escape(User* user)
{
cout<<"You find yourself outside with lush fields of green."<<endl;
cout<<"This is the happiest you have ever been, you have escaped."<<endl;
cin.get();
user->show_enemies();
cout<<"Play agin?"<<endl;
cin.get();
main();
}
void room2 (User* user);
void room1 (User* user)
{
int choice;
cout<<"You awake in a dark room"<<endl;
while (true)
{
cout<<"What do you want to do?"<<endl;
cout<<"1) Walk towards the door."<<endl;
cout<<"2) Look around the room."<<endl;
cout<<"3) Turn on the lights."<<endl;
cout<<"4) Check the window."<<endl;
cin>>choice;
switch (choice)
{
case 1:
{
cout<<"You exit the room."<<endl;
room2(user);
break;
}
case 2:
{
cout<<"You find leather gloves on the floor."<<endl;
user->add_armor("leather gloves", 4);
break;
}
case 3:
{
cout<<"After turning on the lights, you relize that you have awoken several bats"<<endl;
cout<<"They begin to attack!"<<endl;
Monster bats;
bats.set_stats(50, 5, 4, "Venemous Bats", "Head");
battle(user, bats);
cout<<"You find a large bat fang on the ground."<<endl;
cin.get();
user->add_weapon("Bat Fang", 4);
cout<<"You decide to get out of the room before more bats wake up."<<endl;
room2(user);
break;
}
case 4:
{
cout<<"You check the window and its locked, dang"<<endl;
cin.get();
break;
}
}
}
}
void room4 (User* user);
void room3 (User* user)
{
int choice;
Monster skeleton;
skeleton.set_stats(250, 20, 10, "Skeleton King", "Torso");
cout<<"You find yoursel in a large open room."<<endl;
cin.get();
cout<<"There is a large throne with a giant skeleton sitting in it."<<endl;
cin.get();
while (true)
{
cout<<"What would you like to do?"<<endl;
cout<<"1) Approach Skeleton."<<endl;
cout<<"2) Go back to way you came."<<endl;
cout<<"3) Go through the door on the side of the room."<<endl;
cout<<"4) Look around."<<endl;
cin>>choice;
switch (choice)
{
case 1:
{
int opt;
cout<<"As you approch the Skeleton, he begins to move."<<endl;
cin.get();
cout<<"He states: 'Come closer and you will surely perish'"<<endl;
cout<<"Continue? (1 to continue)"<<endl;
cin>>opt;
if (opt ==1)
{
battle(user, skeleton);
cout<<"The Skeleton King screams out in pain and sudenly vanishes into thin air."<<endl;
cin.get();
cout<<"You hear an unlocking sound come from the door on the other side of the room."<<endl;
}
break;
}
case 2:
{
room2(user);
break;
}
case 3:
{
if (user->check_defeated("Skeleton King"))
{
room4(user);
}
else
{
cout<<"The door is locked, you cannot go that way."<<endl;
}
break;
}
case 4:
{
cout<<"You look behind the throne and see a golden helmet."<<endl;
cin.get();
user->add_armor("Golden Helemt", 20);
break;
}
}
}
}
void room4 (User* user)
{
int choice;
Monster spider;
spider.set_stats(300, 15, 30, "Arachnais", "Head");
cout<<"You find yoursel in a large open room."<<endl;
cin.get();
cout<<"There is an ominous feeling about the room...."<<endl;
cin.get();
cout<<"You Notice two doors beside the one you came in."<<endl;
while (true)
{
cout<<"What would you like to do?"<<endl;
cout<<"1) Head towards the large door to the outside."<<endl;
cout<<"2) Go towards the other set of large doors."<<endl;
cout<<"3) Go through the smaller set of stairs."<<endl;
cout<<"4) Look around."<<endl;
cin>>choice;
switch (choice)
{
case 1:
{
int opt;
cout<<"As you approch the Exit, you hear a loud rumbling sound."<<endl;
cin.get();
cout<<"A giant spider descends from the ceiling."<<endl;
cout<<"There is no time to escape, you must fight!"<<endl;
if (!user->check_defeated(spider.get_name()))
{
battle(user, spider);
cout<<"The withers away into dust."<<endl;
cin.get();
cout<<"You find a the spiders venoumous fangs."<<endl;
user->add_weapon("Arachnais Fang", 12);
}
cout<<"You are now able to reach the exit."<<endl;
escape(user);
break;
}
case 2:
{
room2(user);
break;
}
case 3:
{
room3(user);
break;
}
case 4:
{
cout<<"You find Mighty Boots"<<endl;
cin.get();
user->add_armor("Mighty Boots", 18);
break;
}
}
}
}
void room2 (User* user)
{
int choice;
Monster statue;
statue.set_stats(150, 10, 30, "Statue King", "Legs");
cout<<"You find yoursel in a large hallway"<<endl;
cin.get();
cout<<"There is a large statue at the center of the hallway, \na large door at the other side."<<endl;
cout<<"There is also a smaller door on the side of the hallway."<<endl;
cin.get();
while (true)
{
cout<<"What would you like to do?"<<endl;
cout<<"1) Examine the statue."<<endl;
cout<<"2) Run down the hallway towards the large door as quickly as possible"<<endl;
cout<<"3) Go through the smaller door on the side of the hall."<<endl;
cout<<"4) Look around."<<endl;
cin>>choice;
switch (choice)
{
case 1:
{
int pull;
cout<<"You look more closely at the statue and see that there is a large lever."<<endl;
cout<<"Pull it? (Press 1 to pull)"<<endl;
cin>>pull;
if (pull == 1)
{
cout<< "You Pull the lever ans a secret compartment opens up"<<endl;
cout<< "You cannot help but look inside....."<<endl;
cout<<"You found the mythical sword Excaliber!"<<endl;
user->add_weapon("Excaliber", 25);
}
break;
}
case 2:
{
int chance, run;
chance = rand() % 50;
cout<<"As you pass the large statue, it begins to move towards you."<<endl;
cin.get();
cout<<"Would you like to turn and fight, or continue running? (1 to keep running)"<<endl;
cin>>run;
if (run != 1)
{
chance = 0;
}
if (chance > 25)
{
cout<<"You barely managed to reach the door and slip through"<<endl;
cin.get();
cout<<"You hear a large thud right as the door closes from the statues weapon."<<endl;
room4(user);
}
else
{
cout<<"The statue cuts you off from the door, you have no choice but to fight."<<endl;
cin.get();
battle(user, statue);
cout<<"You managed to survive a gruling battle"<<endl;
cin.get();
cout<<"You make your way to the door"<<endl;
room4(user);
}
break;
}
case 3:
{
room3(user);
break;
}
case 4:
{
cout<<"You look under the rug and find a trap door."<<endl;
cin.get();
cout<<"You lift the latch and find Precious Armor"<<endl;
cin.get();
user->add_armor("Precious Armor", 25);
break;
}
}
}
}