-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodes.h
746 lines (690 loc) · 26.4 KB
/
modes.h
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
#pragma once
#include "fundamentals.h"
#include "helper.h"
// #include "display.h"
#include "maze.h"
void timer()
{
int timeLimit = 30; // Time limit in seconds
// Timer logic
std::time_t start_time = std::time(nullptr); // Get current time
std::time_t current_time;
std::time_t end_time = start_time + timelimit;
while (true)
{
// Check the time
current_time = time(nullptr);
if (current_time >= end_time)
{
// clearing the screen and showing Time's up!
system("cls");
cout << "\nTime's up! Game Over.\n";
cout << "your score is as follows . " << score;
break;
}
gotoxy(1, 1);
// Display time remaining to the player
cout << "Time remaining: " << end_time - current_time << " seconds";
// this_thread::sleep_for(chrono::seconds(1));
}
}
void movePlayerwithtimer(int x, int y, char c)
{
changeSystemColor();
enableBGText(BACKGROUND_SILVER);
int timeLimit = 30; // Time limit in seconds
// Timer logic
std::time_t start_time = std::time(nullptr); // Get current time
std::time_t current_time;
std::time_t end_time = start_time + timelimit;
while (true)
{
current_time = time(nullptr);
if (current_time >= end_time)
{
// clearing the screen and showing Time's up!
system("cls");
Sleep(1000);
cout << "\nTime's up! Game Over.\n";
cout << "your score is " << score;
cout << endl;
score = 0;
superman.health = 100;
mazeRows = 8;
mazeCols = 14;
cout << "Press any key continue.";
_getch();
throw runtime_error("BreakException");
// exit(0);
}
gotoxy(2, 4);
// Display time remaining to the player
cout << "Time remaining: " << end_time - current_time << " seconds";
// this_thread::sleep_for(chrono::seconds(1));
gotoxy(x, y);
std::cout << c;
if (_kbhit())
{
char key = _getch();
gotoxy(x, y);
std::cout << ' '; // Clear previous position
int prevX = x;
int prevY = y;
// Move the player based on arrow key input
switch (key)
{
case 72: // Up Arrow key code
prevY = y;
y--;
break;
case 80: // Down Arrow key code
prevY = y;
y++;
break;
case 75: // Left Arrow key code
prevX = x;
x--;
break;
case 77: // Right Arrow key code
prevX = x;
x++;
break;
case 27: // ESCAPE key
system("cls");
throw std::runtime_error("BreakException");
// goto StartOfGame;
break;
default:
break;
}
// Check for collisions with walls or obstacles
if ((
(getASCIIAtPosition(x, y) == -37) || // giving -37 for solid block as ascii value
(getCharacterAtPosition(x, y) == '|') ||
(getCharacterAtPosition(x, y) == '*')))
{
x = prevX;
y = prevY;
}
// CHECKING FOR THW
for (int i = 0; i < numberOfEnemies; i++)
{
encounterEnemy(x, enemiesArray[i].x, y, enemiesArray[i].y);
}
// for checking if there is chest at this position.
for (int i = 0; i < numberOfChests; i++)
{
encounterChest(x, chestsArray[i].x, y, chestsArray[i].y);
}
// condition to check whether the player has reached out of the maze or not.
if (getCharacterAtPosition(x, y) == 'E')
{
system("cls");
cout << "Congratulations! You have won the game." << endl;
cout << "Now proceed to the next level." << endl;
Sleep(400);
break;
} // now display a portal at the final destination.
}
}
timelimit += 15;
}
void combat(Player *b, Monster *a)
{
// printing line only for the purpose of formatting
cout << endl;
centerText(a->name);
cout << endl;
Sleep(5000);
changeSystemColor();
string combatOptions[4] = {"Attack", "Defend", "Special Move", "SKIP ENEMY"};
// change turn of each
bool turnchanger = true;
srand(time(NULL));
while (true)
{
system("cls");
cout << "\033[31m+==========================+\033[0m" << endl;
cout << "| Monster's Health = " << a->health << " |" << endl;
cout << "| Player's Health = " << b->health << " |" << endl;
cout << "\033[31m+==========================+\033[0m" << endl;
// clearing the screen everytime to show the newstats.
Sleep(2000);
if (b->health <= 0)
{
string lostmessage = "YOU LOST!!!!!!!!!|N YOU WERE UNABLE TO DEAL WITH THE GUARDIAN OF THIS PATH";
animateText(lostmessage);
cout << endl;
score = 0;
superman.health = 100;
mazeRows = 8;
mazeCols = 14;
cout << "Press any key continue.";
_getch();
throw runtime_error("BreakException");
// exit(0);
break;
}
else if (a->health <= 0)
{
string message = "You won the battle. You have killed the Monster. \n Now you pass to the next level. \nBeware of the future dangers ";
animateText(message);
cout << endl;
break;
}
// creating the variables for the task of performing the choices.
int respons;
int attack;
int monsterresponse;
int monsterattack = 0;
// asking the user what they want to do and getting their answer.
// creating a variable bool to change the tufn of the attacks by the Monster and the player.
if (turnchanger)
{
// displayOptions(combatOptions, 3);
int d = displayOptions(combatOptions, 4);
switch (d)
{
case 0:
{
attack = rand() % 10;
cout << "Monster lost " << attack << " amount of health." << endl;
a->health -= attack;
break;
}
case 1:
{
int heal;
cout << "you have choosen to defend the attack of the enemy." << endl;
heal = 1 + rand() % 3;
if (heal == 1)
{
cout << "you have restored 9 points of health. " << endl;
b->health += 9;
}
else
{
cout << "defense failed. You have to face the damage." << endl;
b->health -= monsterattack;
}
break;
}
case 2:
{
attack = 5 + (rand() % 20);
string specialAttack = "USING THE SPECIAL ATTACK OF THE PLAYER"
"\nRight execution will deal massive damage to the enemy.";
(specialAttack);
cout << "the damage to the enemy is as follows. " << attack << endl;
a->health -= attack;
break;
}
case 3:
{
string choose = "YOU SOMEHOW MANAGED TO ESCAPE THE ENEMY\n"
"BUT DUE TO HARSHILY RUNNING TO ESCAPE YOU LOST 15 POINTS OF HEALTH";
animateText(choose);
b->health -= 15;
// using the return go back to caller function and continue the next portion of hte storyline.
return;
}
default:
break;
}
// giving the boolean variable the signal to change the turn.
turnchanger = false;
Sleep(2000);
system("cls");
}
else if (!turnchanger)
{
string monterturn = "NOW THIS IS MONSTER'S TURN . \n LET's SEE WHAT THE MONSTER DOES";
cout << endl;
animateText(monterturn);
monsterresponse = 1 + rand() % 3;
if (monsterresponse == 1)
{
monsterattack = 1 + rand() % 10;
cout << "the Monster attacked and you lost " << monsterattack << " health." << endl;
b->health -= monsterattack;
}
else if (monsterresponse == 2)
{
// increasing the Monster's health by 5 to make the battle difficult.
cout << "The Monster healed your attack. and restored 5 points of health" << endl;
a->health += 5;
}
else
{
cout << "The Monster used its special ability, which deals massive damage!" << endl;
monsterattack = 15;
cout << "now you have lost " << monsterattack << " of health." << endl;
b->health -= monsterattack;
}
// giveng the turn back to the player.
turnchanger = true;
Sleep(6000);
system("cls");
}
}
}
void movePlayer(int x, int y, char c)
{
// changeSystemColor();
enableBGText(BACKGROUND_SILVER);
// Character representing the player
while (true)
{
gotoxy(x, y);
std::cout << c;
// using the _kbhit to detect which key is being hit by hte uer.
if (_kbhit())
{
char key = _getch();
gotoxy(x, y);
std::cout << ' ';
// Clear previous position
int prevX = x;
// Move the player based on arrow key input
int prevY = y;
switch (key)
{
case 72: // Up Arrow key code
prevY = y;
y--;
break;
case 80: // Down Arrow key code
prevY = y;
y++;
break;
case 75: // Left Arrow key code
prevX = x;
x--;
break;
case 77: // Right Arrow key code
prevX = x;
x++;
break;
case 27: // ESCAPE key
system("cls");
throw std::runtime_error("BreakException");
// goto StartOfGame;
break;
default:
break;
}
if (
(getASCIIAtPosition(x, y) == -37) || // getting -37 for solid block as ascii value
(getCharacterAtPosition(x, y) == 'S'))
{
x = prevX;
y = prevY;
}
// for checking if there is enemy at this position.
for (int i = 0; i < numberOfEnemies; i++)
{
encounterEnemy(x, enemiesArray[i].x, y, enemiesArray[i].y);
}
// for checking if there is chest at this position.
for (int i = 0; i < numberOfChests; i++)
{
encounterChest(x, chestsArray[i].x, y, chestsArray[i].y);
}
// introducing the createria for facing a Monster.
// this feature will only be able if the player is playing the storyline mode
// if (levelno >= 5 && levelno < 11)
if (levelno >= 11 && levelno < 11)
{
if (getCharacterAtPosition(x, y) == 'E' && response == 1)
{
system("cls");
centerText("+=====================================================================+");
cout << endl;
centerText(" get ready to face the Monster that protects the endway of this path.");
cout << endl;
Monster currentmonster = monsters[e];
combat(&superman, ¤tmonster);
Sleep(2000);
system("cls");
e++;
break;
}
}
// condition to check whether the player has reached out of the maze or not.
if (getCharacterAtPosition(x, y) == 'E')
{
system("cls");
cout << "Congratulations! You have won the game." << endl;
cout << "Now proceed to the next level." << endl;
Sleep(400);
break;
} // now display a portal at the final destination.
}
}
}
void storyline()
{
system("cls");
changeSystemColor();
loadingbar();
system("cls");
// giving the user the introduction of the storyline game.
string story = "WELCOME TO STORYLINE OF THE GAME \n NOW CHOOSE A SPECIAL CHARACTER TO PLAY WITH.\n";
animateText(story);
cin >> superman.player;
Sleep(50);
system("cls");
string introduction = "\nThis story is about a lost survivor who has lost himself in the forest. \n in order to reach out of the forest he has to pass through different mazes. \nIf he succesfully cleares all the mazes, then he finds himself out of the maze. \nThe game starts in a HUT. Player's is looking for the path out can you help him. ";
for (char &c : introduction)
{
c = toupper(c);
}
animateText(introduction);
cout << endl;
system("cls");
// cout << "\nThis story is about a lost survivor who has lost himself in the forest. " << endl;
// cout << "in order to reach out of the forest he has to pass through different mazes." << endl;
// cout << "If he succesfully cleares all the mazes, then he finds himself out of the maze. " << endl;
// cout << "The game starts in a HUT. Player's is looking for the path out can you help him. " << endl;
// system("cls");
while (true)
{
// using a switch case statement to handle the game based on the level no.
if (levelno == 1)
{
changeSystemColor();
numberOfEnemies = 3;
string level1Story = "Level 1: The Monstrous Hut\n"
"In the heart of the forest lies an old hut, shrouded in mystery. Here,\n "
"you must navigate through hidden passages and solve ancient puzzles to find the exit.\n";
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
animateText(level1Story);
gotoxy(0, 4);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 1;
mazeCols += 2;
levelno++;
system("cls");
loadingbar();
}
else if (levelno == 2)
{
score += 10;
changeSystemColor();
numberOfEnemies = 5;
system("cls");
string level2Story = "Level 2: Entering the Jungle\n"
"Emerging from the hut, you find yourself at the edge of a dense jungle. \n"
"Your senses tingle as you step into the green maze,\n with unknown dangers lurking in the shadows.\n";
animateText(level2Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 3;
levelno++;
}
else if (levelno == 3)
{
score += 10;
changeSystemColor();
numberOfEnemies = 7;
system("cls");
string level3Story = "Level 3: Jungle Survival\n"
"Deeper into the jungle, survival becomes a challenge. \n"
"Here, the maze tests your ability to find resources and\n protect yourself against the wild inhabitants of the forest.\n";
animateText(level3Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 3;
levelno++;
}
else if (levelno == 4)
{
score += 10;
changeSystemColor();
numberOfEnemies = 9;
system("cls");
string level4Story = "Level 4: Reaching the River\n"
"Beyond the jungle lies a vast river. The maze now involves crossing treacherous waters \n"
"and navigating along its unpredictable banks, full of slippery stones and hidden paths.\n";
animateText(level4Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 3;
levelno++;
}
else if (levelno == 5)
{
score += 10;
changeSystemColor();
numberOfEnemies = 11;
system("cls");
string level5Story = "Level 5: Entering the Dungeon\n"
"As you travel, you discover an entrance to an underground dungeon. \n"
"In this level, the maze becomes a labyrinth of dark, \nnarrow tunnels filled with ancient traps and cryptic symbols.\n";
animateText(level5Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 2;
levelno++;
}
else if (levelno == 6)
{
score += 10;
changeSystemColor();
numberOfEnemies = 13;
system("cls");
string level6Story = "Level 6: The Dungeon Part 2\n"
"Deeper in the dungeon, the challenges intensify. \n"
"The maze here is more complex, with dead ends and hidden doors,\n as you delve into the heart of the underground world.\n";
animateText(level6Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 2;
levelno++;
}
else if (levelno == 7)
{
score += 10;
changeSystemColor();
numberOfEnemies = 15;
system("cls");
string level7Story = "Level 7: Death Valley\n"
"Escaping the dungeon, you find yourself in Death Valley, a desolate landscape. \n"
"Here, the maze is a series of dry canyons and treacherous cliffs,\n with extreme conditions testing your endurance.\n";
animateText(level7Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 2;
mazeCols += 2;
levelno++;
}
else if (levelno == 8)
{
score += 10;
changeSystemColor();
numberOfEnemies = 17;
system("cls");
string level8Story = "Level 8: Death Bridge\n"
"Your path leads you to a precarious bridge. In this level, \n"
"you must carefully navigate across while solving puzzles\n that control the bridge's stability and path.\n";
animateText(level8Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 3;
mazeCols += 2;
levelno++;
}
else if (levelno == 9)
{
score += 10;
changeSystemColor();
numberOfEnemies = 19;
system("cls");
string level9Story = "Level 9: Dead End\n"
"Nearing the end of your journey, you enter a maze that seems to have no exit. \n"
"This level requires clever problem-solving and \nintuition to find the hidden passage leading out.\n";
animateText(level9Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
mazeRows += 4;
mazeCols += 2;
levelno++;
}
else if (levelno == 10)
{
score += 10;
changeSystemColor();
numberOfEnemies = 21;
system("cls");
string level10Story = "Level 10: Path to the Earth\n"
"In the final challenge, you must use all your acquired skills\n and knowledge to navigate the most intricate maze. \n"
"Success here means finding the path that leads back to the familiar world.\n";
animateText(level10Story);
gotoxy(0, 4);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayGame(maze);
movePlayer(superman.x, superman.y, superman.player);
// if the user completes the game then, displaying the user the message showing the victory message.
system("cls");
cout << "CONGRATULTIONS, You have Completed the game MR." << username << endl;
cout << "You have now reached back to the Earth. " << endl;
}
if (levelno == 11)
{
score += 10;
break;
}
}
}
void timetrail()
{
changeSystemColor();
system("cls");
loadingbar();
system("cls");
// giving the user the introduction when he enters the maze game.
string timetrailintro = "WELCOME TO THE TIMETRAIL MODE OF THE GAME. \n"
"IN THIS MODE YOU WILL BE GIVEN SPECIFIC TIME TO SOLVE THE MAZE.\n"
"IF YOU SOLVED THE MAZE IN THE GIVEN TIME THEN YOU WILL PROCEED TO THE NEXT MAZE.\n"
"THIS WILL CONTINUE UNTIL YOUR HEALTH BECOMES ZERO OR YOU RAN OUT OF TIME\n"
"WE HOPE THAT YOU WILL ENJOY THIS MODE OF THE GAME.\n";
animateText(timetrailintro);
// making the predefined function
superman.player = 'P';
while (true)
{
system("cls");
gotoxy(2, 9);
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
displayMaze(maze);
displayDialogueBox();
movePlayerwithtimer(superman.x, superman.y, superman.player);
// incresing the score by 20 when the user clears a maze.
score += 20;
// updatintg the size of the maze every time the user survives the game.
mazeRows += 2;
mazeCols += 3;
// After the maze is displayed, start player movement
}
}
void classic()
{
changeSystemColor();
system("cls");
loadingbar();
system("cls");
centerText("WELCOME TO THE CLASSIC MODE OF THIS GAME.");
cout << endl;
centerText("+=========================================================================+");
cout << endl;
centerText("||");
cout << endl;
centerText("In this mode, you have to survive as long as you can.");
cout << endl;
centerText("The Rules For this mode are Below : ");
cout << endl;
centerText("-> No revival");
cout << endl;
centerText("-> Score by solving only.");
cout << endl;
centerText("||");
cout << endl;
centerText("+=========================================================================+");
cout << endl;
Sleep(3000);
system("cls");
// asking the user to enter the character with which he wants to play the game.
cout << "+=================================+" << endl;
cout << "| |" << endl;
cout << "| enter your character : |" << endl;
cout << "| |" << endl;
cout << "+=================================+" << endl;
superman.player = _getch();
system("cls");
// maiking the use of the system cls to create an illusion that character is entered within the box.
cout << "+=================================+" << endl;
cout << "| |" << endl;
cout << "| enter your character : " << superman.player << " |" << endl;
cout << "| |" << endl;
cout << "+=================================+" << endl;
Sleep(1000);
while (superman.health != 0)
{
// clearing the screen every time the playerr wins the game.
system("cls");
Sleep(900);
gotoxy(0, 0);
/*cout << "+=================================+" << endl;
cout << "| Health Bar = " << superman.health << " |" << endl;
cout << "| current score = " << score << " |" << endl;
cout << "+=================================+" << endl;*/
// moving the cursor on the top to display the score on the right top most corner of the console.
vector<vector<char>> maze = generateMaze(mazeRows, mazeCols);
gotoxy(1, 4);
displayHealth();
changeSystemColor();
displayMaze(maze);
displayDialogueBox();
movePlayer(superman.x, superman.y, superman.player);
// incresing the score by 20 when the user clears a maze.
score += 20;
// updatintg the size of the maze every time the user survives the game.
mazeRows += 1;
mazeCols += 2;
}
}
void finalBoss()
{
string news;
centerText("+========================================+");
string warning = " HE HE HOO HOOO HAAA HAAA HAAA \n YOU HAVE DONE A GREAT JOB SOO FAR \n BUT NOW IT IS TIME TO DIE .\n AND THE BATTLE BEGINS";
for (char &c : warning)
{
news += c;
Sleep(800);
centerText(news);
}
system("cls");
}