-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacman.cpp
2000 lines (1692 loc) · 75.3 KB
/
pacman.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
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <string>
#include <vector>
#include <conio.h>
#include <cstdlib>
#include <fstream>
#include <stack>
#include <random>
#include <time.h>
#define pacmanIcon "\u15E6"
#define ghostIcon "\u15E3"
using namespace std;
//-----------------------------------------------------------------------------------------------------------------------------
//function prototypes
void printMap(int w , int h);
void gotoxy(int x, int y);
void hidecursor();
void adjacentCell1(int x, int y, int wc, int back);
void PathFinding(int sx, int sy, int x, int y);
void deathScreen();
void difficultyMenu(int &difficulty);
void input(int w , int h , int &x , int &y , int &ghost1Color , int &ghost2Color , int &ghost3Color);
void mainMenu();
void instructions();
void createfile();
void showScoreBoard();
void updateScoreBoard(string, int);
void loadFile(int &w, int &h);
void credits();
void vintagePrint(string);
void deathBlinking();
void generateMaze(int w , int h);
void victory();
void easterEgg();
void pauseMenu(int w , int h);
void save(int, int);
void createcoordinatesFile();
void createMazeFile();
//-------------------------------------------------------------------------------------------------------------------------------------------
// declaring global variables
int pts = 0;
int difficulty;
enum eDirection {LEFT , RIGHT , UP , DOWN};
eDirection dir;
const string FILENAME = "scoreBoard.txt";
const string CREATURE = "creature.txt";
const string MAZE = "maze.txt";
int maxPoints=0;
bool frightenedMod = false;
bool isNewGame = false;
int frameCount = 0;
int initialFrame = 0;
int deathCount = 0;
int WIDTH;
int HEIGHT;
int mapColor;
int PlaceHolderMapColor;
int PacmanColor;
int primaryColor;
int secondaryColor;
int G1X;
int G1Y;
int G2X;
int G2Y;
int G3X;
int G3Y;
int x, y;
vector<char> keepTrack;
//----------------------------------------------------------------------------------------------------------------------------
char tmp_map[50][50]; // used for bfs algorithm
char map[50][50]; // a global array to store map
//--------------------------------------------------------maze stuff----------------------------------------------------------
enum Orientation{ Left, Right, Up, Down };
Orientation operator!(const Orientation& dir){
if(dir==Left || dir==Up)
return Orientation(dir+1);
else
return Orientation(dir-1);
}
struct Coords{
int x, y;
static const Coords directionOffset[]; //static const va const dar in tafavot darand ke static const faghat
// yekbar initialized mishe va baraye tamam dafaat baadi ke tabe seda mishe yeki hast
};
const Coords Coords::directionOffset[] = {
Coords{-1, 0 }, // left
Coords{ 1, 0 }, // right
Coords{ 0,-1 }, // up
Coords{ 0, 1 } // down
};
Coords operator+(const Coords& left, const Coords& right){
return Coords{left.x + right.x, left.y + right.y };
}
struct MazeCell{
char connections = 0;
bool isConnected(Orientation dir);
void connect(Orientation dir);
bool visited();
static const unsigned char connectionMask[];
};
bool MazeCell::isConnected(Orientation dir){
return connections & connectionMask[dir];
}
void MazeCell::connect(Orientation dir){
connections |= connectionMask[dir];
}
bool MazeCell::visited(){
return connections;
}
const unsigned char MazeCell::connectionMask[] = {
(1), // left
(2), // right
(4), // up
(16) // down
};
struct MazePosition; //class forward declaration
class Maze{
friend MazePosition; //can access private and protected part if this class
unsigned int width,height;
MazeCell* cells; //pointer to structure
public:
Maze(unsigned int width, unsigned int height);
MazePosition pinPoint(unsigned int x, unsigned int y);
private:
bool succsesfullyConnectedToNeighbour(Coords& cellCoords);
void connect(Coords& from, Coords& to, Orientation dir);
bool areCoordsValid(const Coords& coords) const;
MazeCell& cellAt(const Coords& coords) const;
};
void Maze::connect(Coords& from, Coords& to, Orientation dir){
cellAt(from).connect(dir);
cellAt(to).connect(!dir);
}
bool Maze::areCoordsValid(const Coords& coords) const {
return coords.x >= 0 && coords.y >= 0 && coords.x < (int)width && coords.y < (int)height; // checks if we are in the boundries of the maze
}
MazeCell& Maze::cellAt(const Coords& coords) const {
if(!areCoordsValid(coords)){cout << "hit bad";}
return cells[coords.x + coords.y*width];
}
Maze::Maze(unsigned int width, unsigned int height) : width(width), height(height) {
cells = new MazeCell[width*height];
Coords currentCellCoords{0,0};
stack<Coords> visitedCellsStack;
visitedCellsStack.push(currentCellCoords);
while(true){
if(succsesfullyConnectedToNeighbour(currentCellCoords)){
visitedCellsStack.push(currentCellCoords);
}else{
currentCellCoords = visitedCellsStack.top();
visitedCellsStack.pop();
if(visitedCellsStack.empty()) break;
}
}
}
bool Maze::succsesfullyConnectedToNeighbour(Coords& cellCoords){
random_device rd;
mt19937 eng(rd());
uniform_int_distribution<mt19937::result_type> random(1,4);
Orientation random_direction = Orientation(random(eng));
for(int i = 0; i < 4; i++){
Orientation next_rand_direction = Orientation( (random_direction + i)%4 );
Coords neighbour_coords = Coords::directionOffset[next_rand_direction] + cellCoords;
if( areCoordsValid(neighbour_coords) && !cellAt(neighbour_coords).visited() ){
connect(cellCoords, neighbour_coords, next_rand_direction);
cellCoords = neighbour_coords;
return true;
}
}
return false;
}
struct MazePosition{
const Maze& maze;
Coords currentCoords;
MazePosition(const Maze& maze, Coords coords) : maze(maze), currentCoords(coords){}
bool canGo(Orientation dir){
return maze.cellAt(currentCoords).isConnected(dir);
}
void go(Orientation dir){
if(canGo(dir))
currentCoords = currentCoords + Coords::directionOffset[dir];
}
};
MazePosition Maze::pinPoint( unsigned int x, unsigned int y){
return MazePosition(*this,Coords{(int)x, (int)y});
}
//------------------------------------------------end of maze stuff------------------------------------------------
void clearScreen(){
HANDLE hOut;
COORD Position;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = 0;
Position.Y = 0;
SetConsoleCursorPosition(hOut, Position);
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void printMap(int w , int h){ // translating ascii characters from the array map to unicode
clearScreen();
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, mapColor); //9
for(int i=0 ; i<2*h+1 ; i++){
for(int j=0 ; j<2*w+1 ; j++){
if(map[i][j]=='|'){
cout<<"█";
}
else if(map[i][j]=='_'){
cout<<"■";
}
else if(map[i][j]=='.'){
cout<<"•";
}
else if(map[i][j]=='H'){
cout<<"▄";
}
else if(map[i][j]=='C'){
SetConsoleTextAttribute(hConsole, 4);
cout<<"꘧";
SetConsoleTextAttribute(hConsole, mapColor);
}
else{
cout<<' ';
}
}
cout<<endl;
}
SetConsoleTextAttribute(hConsole, 15);
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void gotoxy(int x, int y){
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(hStdout, position);
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void hidecursor(){
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
//-------------------------------------------------------------------------------------------------------------------------------------------
struct walk{
int walk_count;
int x;
int y;
int back;
};
struct target{
int x;
int y;
};
//-------------------------------------------------------------------------------------------------------------------------------------------
vector<target> walk1_queue;
vector<target> walk2_queue;
vector<target> walk3_queue;
vector<walk> BFS1;
vector<walk> BFS2;
vector<walk> BFS3;
//-------------------------------------------------------------------------------------------------------------------------------------------
void adjacentCell1(int x, int y, int wc, int back){
if (tmp_map[y][x] == ' ' || tmp_map[y][x] == '.')
{
tmp_map[y][x] = '#';
walk tmp;
tmp.x = x;
tmp.y = y;
tmp.walk_count = wc;
tmp.back = back;
BFS1.push_back(tmp);
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void adjacentCell2(int x, int y, int wc, int back){
if (tmp_map[y][x] == ' ' || tmp_map[y][x] == '.')
{
tmp_map[y][x] = '#';
walk tmp;
tmp.x = x;
tmp.y = y;
tmp.walk_count = wc;
tmp.back = back;
BFS2.push_back(tmp);
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void adjacentCell3(int x, int y, int wc, int back){
if (tmp_map[y][x] == ' ' || tmp_map[y][x] == '.')
{
tmp_map[y][x] = '#';
walk tmp;
tmp.x = x;
tmp.y = y;
tmp.walk_count = wc;
tmp.back = back;
BFS3.push_back(tmp);
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void PathFinding1(int sx, int sy, int x, int y){
memcpy(tmp_map, map, sizeof(map));
BFS1.clear();
walk tmp;
tmp.x = sx;
tmp.y = sy;
tmp.walk_count = 0;
tmp.back = -1;
BFS1.push_back(tmp);
int i = 0;
while (i < BFS1.size()){
if (BFS1[i].x == x && BFS1[i].y == y){
walk1_queue.clear();
target tmp2;
while (BFS1[i].walk_count != 0){
tmp2.x = BFS1[i].x;
tmp2.y = BFS1[i].y;
walk1_queue.push_back(tmp2);
i = BFS1[i].back;
}
break;
}
adjacentCell1(BFS1[i].x + 1, BFS1[i].y, BFS1[i].walk_count + 1, i);
adjacentCell1(BFS1[i].x - 1, BFS1[i].y, BFS1[i].walk_count + 1, i);
adjacentCell1(BFS1[i].x, BFS1[i].y + 1, BFS1[i].walk_count + 1, i);
adjacentCell1(BFS1[i].x, BFS1[i].y - 1, BFS1[i].walk_count + 1, i);
i++;
}
BFS1.clear();
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void PathFinding2(int sx, int sy, int x, int y){
memcpy(tmp_map, map, sizeof(map));
BFS2.clear();
walk tmp;
tmp.x = sx;
tmp.y = sy;
tmp.walk_count = 0;
tmp.back = -1;
BFS2.push_back(tmp);
int i = 0;
while (i < BFS2.size()){
if (BFS2[i].x == x && BFS2[i].y == y){
walk2_queue.clear();
target tmp2;
while (BFS2[i].walk_count != 0){
tmp2.x = BFS2[i].x;
tmp2.y = BFS2[i].y;
walk2_queue.push_back(tmp2);
i = BFS2[i].back;
}
break;
}
adjacentCell2(BFS2[i].x + 1, BFS2[i].y, BFS2[i].walk_count + 1, i);
adjacentCell2(BFS2[i].x - 1, BFS2[i].y, BFS2[i].walk_count + 1, i);
adjacentCell2(BFS2[i].x, BFS2[i].y + 1, BFS2[i].walk_count + 1, i);
adjacentCell2(BFS2[i].x, BFS2[i].y - 1, BFS2[i].walk_count + 1, i);
i++;
}
BFS2.clear();
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void PathFinding3(int sx, int sy, int x, int y){
memcpy(tmp_map, map, sizeof(map));
BFS3.clear();
walk tmp;
tmp.x = sx;
tmp.y = sy;
tmp.walk_count = 0;
tmp.back = -1;
BFS3.push_back(tmp);
int i = 0;
while (i < BFS3.size()){
if (BFS3[i].x == x && BFS3[i].y == y){
walk3_queue.clear();
target tmp3;
while (BFS3[i].walk_count != 0){
tmp3.x = BFS3[i].x;
tmp3.y = BFS3[i].y;
walk3_queue.push_back(tmp3);
i = BFS3[i].back;
}
break;
}
adjacentCell3(BFS3[i].x + 1, BFS3[i].y, BFS3[i].walk_count + 1, i);
adjacentCell3(BFS3[i].x - 1, BFS3[i].y, BFS3[i].walk_count + 1, i);
adjacentCell3(BFS3[i].x, BFS3[i].y + 1, BFS3[i].walk_count + 1, i);
adjacentCell3(BFS3[i].x, BFS3[i].y - 1, BFS3[i].walk_count + 1, i);
i++;
}
BFS3.clear();
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void deathScreen(){
system("cls");
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 4);
cout<<"════════════════════════════════════════════════════════════════"<<endl; Sleep(50);
SetConsoleTextAttribute(hConsole, 12);
cout<<" __ __ ____ _ _ _____ _____ ______ _____ "<<endl; Sleep(50);
cout<<" \\ \\ / // __ \\ | | | | | __ \\|_ _|| ____|| __ \\ "<<endl; Sleep(50);
cout<<" \\ \\_/ /| | | || | | | | | | | | | | |__ | | | | "<<endl; Sleep(50);
cout<<" \\ / | | | || | | | | | | | | | | __| | | | | "<<endl; Sleep(50);
cout<<" | | | |__| || |__| | | |__| |_| |_ | |____ | |__| | "<<endl; Sleep(50);
cout<<" |_| \\____/ \\____/ |_____/|_____||______||_____/ "<<endl; Sleep(50);
cout<<" "<<endl; Sleep(50);
SetConsoleTextAttribute(hConsole, 4);
cout<<"════════════════════════════════════════════════════════════════"<<endl;
cout<<" ══════════════════════════ "<<endl;
SetConsoleTextAttribute(hConsole, 12);
cout<<" Score: "<< pts <<" "<<endl;
SetConsoleTextAttribute(hConsole, 4);
cout<<" ══════════════════════════ "<<endl;
string name;
cout<<" ══════════════════════════ "<<endl;
SetConsoleTextAttribute(hConsole, 12);
cout<<" Name:"<<endl;
SetConsoleTextAttribute(hConsole, 4);
cout<<" ══════════════════════════ "<<endl;
gotoxy(32 , 13);
cin >> name;
cout<<endl;
updateScoreBoard(name, pts);
system("pause");
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void difficultyMenu(int &difficulty){
int BorderColor = primaryColor;
int InsideColor = secondaryColor;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" ╒════════════════════════════════╕ "<<endl;
cout<<" │ ";
cout<<" ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"CHOOSE DIFFICULTY ";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"│ "<<endl;
cout<<" ╘════════════════════════════════╛ "<<endl;
SetConsoleTextAttribute(hConsole, 10);
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 2);
cout<<"1";
SetConsoleTextAttribute(hConsole, 10);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 2);
cout<<"EASY ";
SetConsoleTextAttribute(hConsole, 10);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
SetConsoleTextAttribute(hConsole, 6);
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 6);
cout<<"2";
SetConsoleTextAttribute(hConsole, 6);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 6);
cout<<"NORMAL ";
SetConsoleTextAttribute(hConsole, 6);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
SetConsoleTextAttribute(hConsole, 4);
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 12);
cout<<"3";
SetConsoleTextAttribute(hConsole, 4);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, 12);
cout<<"HARD ";
SetConsoleTextAttribute(hConsole, 4);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
switch(getch()){
case '1':
difficulty=3; break;
case '2':
difficulty=2; break;
case '3':
difficulty=1; break;
}
system("cls");
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void input(int w , int h , int &x , int &y , int &ghost1Color , int &ghost2Color , int &ghost3Color){
if(kbhit()){
switch(getch()){
case 'a':
dir=LEFT;
break;
case 's':
dir=DOWN;
break;
case 'd':
dir=RIGHT;
break;
case 'w':
dir=UP;
break;
case 'x':
pauseMenu(w,h);
printMap(w,h);
break;
}
}
switch (dir){
case UP:
if (map[y - 1][x] == '.'){
y--;
pts++;
map[y][x] = ' ';
}
else if(map[y - 1][x] == ' '){
y--;
}
else if(map[y - 1][x] == 'C'){
y--;
map[y][x] = ' ';
frightenedMod = true;
initialFrame = frameCount;
ghost1Color = 15;
ghost2Color = 15;
ghost3Color = 15;
mapColor = 15;
}
break;
case DOWN:
if (map[y + 1][x] == '.'){
y++;
pts++;
map[y][x]=' ';
}
else if(map[y + 1][x] == ' '){
y++;
}
else if(map[y + 1][x] == 'C'){
y++;
map[y][x] = ' ';
frightenedMod = true;
initialFrame = frameCount;
ghost1Color = 15;
ghost2Color = 15;
ghost3Color = 15;
mapColor = 15;
}
break;
case LEFT:
if (map[y][x - 1] == '.'){
x--;
pts++;
map[y][x]=' ';
}
else if (map[y][x - 1] == ' '){
x--;
}
else if(map[y][x - 1] == 'C'){
x--;
map[y][x] = ' ';
frightenedMod = true;
initialFrame = frameCount;
ghost1Color = 15;
ghost2Color = 15;
ghost3Color = 15;
mapColor = 15;
}
break;
case RIGHT:
if (map[y][x + 1] == '.'){
x++;
pts++;
map[y][x] = ' ';
}
else if(map[y][x + 1] == ' '){
x++;
}
else if(map[y][x + 1] == 'C'){
x++;
map[y][x] = ' ';
frightenedMod = true;
initialFrame = frameCount;
ghost1Color = 15;
ghost2Color = 15;
ghost3Color = 15;
mapColor = 15;
}
break;
default:
break;
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void pauseMenu(int w , int h){
system("cls");
int BorderColor = primaryColor;
int InsideColor = secondaryColor;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"╒═════════════════════════════════════════════════════════════════╕"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<" _______ _______ _______ __ __ _______ __ _";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"| || _ || | | |_| || _ || | | |";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"| _ || |_| || | ____ | || |_| || |_| |";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"| |_| || || ||____|| || || |";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"| ___|| || _| | || || _ |";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"| | | _ || |_ | ||_|| || _ || | | |";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"|___| |__| |__||_______| |_| |_||__| |__||_| |__|";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │"<<endl;
cout<<"│ │"<<endl;
cout<<"╘═════════════════════════════════════════════════════════════════╛"<<endl;
cout<<endl;
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"1";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"CONTINUE ";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"2";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"SAVE AND EXIT ";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
cout<<" ╒═══╤══════════════════╕ "<<endl;
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"3";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" │ ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"EXIT ";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"│ "<<endl;
cout<<" ╘═══╧══════════════════╛ "<<endl;
switch(getch()){
case '1':
printMap(w,h);
break;
case '2':
save(w, h);
vintagePrint("Adiós Amigo!\n");
system("pause");
mainMenu();
break;
case '3':
exit(0);
break;
}
SetConsoleTextAttribute(hConsole, 15);
system("cls");
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void dimension(int &w , int &h){
int BorderColor = primaryColor;
int InsideColor = secondaryColor;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" ╒════════════════════════════════╕ "<<endl;
cout<<" │ ";
cout<<" ";
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<"CHOOSE DIMENSION ";
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<"│ "<<endl;
cout<<" ╘════════════════════════════════╛ "<<endl;
cout<<endl;
int height , width;
cout<<" ════════════════════ "<<endl;
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<" Enter Width:"<<endl;
Beep(850,100);
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" ════════════════════ "<<endl;
gotoxy(42,5);
cin >> width;
cout << endl;
cout << endl;
cout<<" ════════════════════ "<<endl;
SetConsoleTextAttribute(hConsole, InsideColor);
cout<<" Enter Height:"<<endl;
Beep(850,100);
SetConsoleTextAttribute(hConsole, BorderColor);
cout<<" ════════════════════ "<<endl;
gotoxy(43,9);
cin>>height;
Sleep(100);
w=width/2;
h=height/2;
system("cls");
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void generateMaze(int w , int h){
Maze maze(w,h);
//creating a maze which is small, so it is saved in a vector called "keepTrack"
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
if(maze.pinPoint(x,y).canGo(Left)){
keepTrack.push_back('_');
}
else{
keepTrack.push_back('|');
}
if(maze.pinPoint(x,y).canGo(Down)){
keepTrack.push_back('.');
}
else{
keepTrack.push_back('_');
}
if( x==(w-1) && !maze.pinPoint(x,y).canGo(Right) ){ // the most right cell "must" be a wall to generate a "valid" maze according to h and w
keepTrack.push_back('|');
}
}
// keepTrack.push_back('\n'); // if the comment is removed, the small maze would be printed!
}
// stretching the maze
for(int i=1 ; i<2*h+1 ; i++){
for(int j=0 ; j<2*w+1 ; j++){
if((i+j)%2==0){
map[i][j]='.';
}
else{
map[i][j]=' ';
}
}
}
int k=0;
for(int i=2 ; i<2*h+1 ; i+=2){
for(int j=2 ; j<2*w+1 ; j+=2){
map[i][j]=keepTrack[k];
k++;
}
}
for(int i=1 ; i<2*h+1 ; i++){
for(int j=0 ; j<2*w+1 ; j++){
if(map[i][j]=='|' && map[i-2][j]=='|'){
map[i-1][j]='|';
}
}
}
for(int i=0 ; i<2*h+1 ; i++){
for(int j=0 ; j<2*w+1 ; j++){
if(map[i][j]==' ' && map[i][j-1]=='_' && map[i][j+1]=='_'){
map[i][j]='_';
}
}
}
for(int i=0 ; i<2*h+1 ; i++){
map[i][0]='|';
map[i][2*w]='|';
}
for(int i=0 ; i<2*w+1 ; i++){
map[0][i]='H';
map[2*h][i]='H';
}
map[2*h][2*w]='|';
map[2*h][0]='|';
//-----------------------cherry cordinating-------------------------
map[h][1]='C';
map[h][2*w - 1]='C';
map[1][w]='C';
map[2*h - 1][w]='C';
}
//-------------------------------------------------------------------------------------------------------------------------------------------
void chooseColor(){
system("cls");
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// SetConsoleTextAttribute(hConsole, 9);
cout<<" ╒══════════════════════════════════╕ "<<endl;
cout<<" │ CHOOSE COLOR │ "<<endl;
cout<<" ╘══════════════════════════════════╛ "<<endl;Sleep(200);
cout<<" ════════════════════ "<<endl;
cout<<" PRIMARY: "<<endl;
cout<<" ════════════════════ "<<endl;Sleep(200);
cout<<endl;
cout<<" ════════════════════ "<<endl;
cout<<" SECONDARY: "<<endl;
cout<<" ════════════════════ "<<endl;Sleep(200);
cout<<endl;
cout<<" ════════════════════ "<<endl;
cout<<" PACMAN: "<<endl;
cout<<" ════════════════════ "<<endl;Sleep(200);
cout<<endl;
cout<<" ════════════════════ "<<endl;
cout<<" MAP: "<<endl;
cout<<" ════════════════════ "<<endl;Sleep(200);
cout<<endl;
SetConsoleTextAttribute(hConsole, 1); cout<<" 01 = █ ";
SetConsoleTextAttribute(hConsole, 2); cout<<" 02 = █ ";
SetConsoleTextAttribute(hConsole, 3); cout<<" 03 = █ ";
SetConsoleTextAttribute(hConsole, 4); cout<<" 04 = █ ";
SetConsoleTextAttribute(hConsole, 5); cout<<" 05 = █ ";
SetConsoleTextAttribute(hConsole, 6); cout<<" 06 = █ ";
SetConsoleTextAttribute(hConsole, 7); cout<<" 07 = █ "<<endl;
cout<<endl; Sleep(200);
SetConsoleTextAttribute(hConsole, 8); cout<<" 08 = █ ";
SetConsoleTextAttribute(hConsole, 9); cout<<" 09 = █ ";
SetConsoleTextAttribute(hConsole, 10); cout<<" 10 = █ ";
SetConsoleTextAttribute(hConsole, 11); cout<<" 11 = █ ";
SetConsoleTextAttribute(hConsole, 12); cout<<" 12 = █ ";
SetConsoleTextAttribute(hConsole, 13); cout<<" 13 = █ ";
SetConsoleTextAttribute(hConsole, 14); cout<<" 14 = █ "<<endl;
SetConsoleTextAttribute(hConsole, 15);
cout<<endl;
cout<<" Disclaimer : it's resommended to do not choose colors like white for Map "<<endl;
cout<<" also if you are loading an already saved game the colors will be replaced! "<<endl;
gotoxy(39, 4);
cin>>primaryColor;
gotoxy(40, 8);
cin>>secondaryColor;
gotoxy(38, 12);
cin>>PacmanColor;
gotoxy(37, 16);
cin>>mapColor;
PlaceHolderMapColor = mapColor;
}
//-------------------------------------------------------------------------------------------------------------------------------------------
int main(){
chooseColor();
int ghost1Color = 4;
int ghost2Color = 5;
int ghost3Color = 3;
createfile();
createcoordinatesFile();