-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalprojectbackup.cpp
More file actions
2303 lines (1985 loc) · 65.2 KB
/
finalprojectbackup.cpp
File metadata and controls
2303 lines (1985 loc) · 65.2 KB
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 <conio.h>
#include <thread>
#include <chrono>
#include <windows.h>
#include <fstream>
#include <cstdlib>
//#include <mmsystem.h>//sound
#include <ctime>
#include <limits> // check validity for inputs (data type)
using namespace std;
#define RESET "\033[0m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#pragma comment(lib , "winmm.lib")
struct GAME{
string name;
int score = 0;
double time = 0;
char theme = '1';
};
struct BULLET{
int x;
int y;
bool active = 0;
};
struct ENEMY_BULLET {
int x;
int y;
bool active = false;
};
struct BOMBS {
int x;
int y;
bool active = false;
};
time_t start_time;
int health = 3;
const int game = 100;
const int MAX_BULLET = 1;
const int MAX_BOMBS = 1;
const int MAX_ENEMY_BULLET = 7;
int enemy_step = 0;
bool moveRight = true;
int enemy_speed = 2;
int screen_hight = 20;
int screen_width = 20;
const string PLAYER = "🅯";
const string E1 = "㉈";
const string E2 = "㉉";
const string E3 = "㉋";
const string E4 = "🞋";
const string SHOOT = "•";
const string ENENMY_SHOOT = "↓";
bool special_enemy_active = false;
int special_enemy_x = 0;
int special_enemy_y = 0;
int special_enemy_speed = 1;
int special_enemy_timer = 0;
BULLET bullet[MAX_BULLET];
ENEMY_BULLET enemy_bullets[MAX_ENEMY_BULLET];
BOMBS bombs[MAX_BOMBS];
GAME current_game;
string** game_board = nullptr;
void printCharacterByCharacter(const string& text, int delay);
void How_to_play();
void board_makear();
void time_and_score();
void health_bar();
void display_board();
void heart_board();
void star_board();
void triangle_board();
void free_board();
void hide_cursor();
void displayMenu(const int currentOption, const string options[], const string descriptions[], const int totalOptions);
void main_menu();
void show_cursor();
void newgame();
void themes();
void move_player(int direction_x);
void pause_menu(bool& running);
void reset_cursor();
void game_loop(char& theme);
void play_shoot_sound();
void player_shoots();
void move_bullets();
void move_enemies(bool& running);
void move_special_enemy();
void handle_special_enemy();
void health_bar();
void save_game();
void savedata(const string& playerName, int score);
void load_game();
void display_leaderboard();
void enemy_shoots();
void move_enemy_bullets(bool& running);
bool check_win();
bool check_win2();
void getValidatedInput();
void load_game();
bool check_board();
void move_boomb();
void reset_game_info();
void board_makear2();
void display_board2();
void heart_board2();
void star_board2();
void triangle_board2();
void move_bullets2();
void game_loop2(char& theme);
void displayLoadingAnimation();
bool check_board2();
void move_enemies2(bool&running);
void enemy_shoots2();
void player_shoot_bomb();
void handle_store(bool& running);
void handle_bombs();
void explode_bomb(int bomb_x, int bomb_y);
int main()
{
system("cls");
hide_cursor();
main_menu();
show_cursor();
return 0;
}
void hide_cursor()
{
cout << "\033[?25l";
cout.flush();
}
void displayLoadingAnimation()
{
const char* loadingChars = "|/-\\";
for (int i = 0; i < 10; i++)
{
cout << "\rLoading... " << GREEN << loadingChars[i % 4] << RESET << flush;
Sleep(100);
}
cout << "\rLoading complete! " << endl;
}
void displayMenu(const int currentOption, const string options[], const string descriptions[], const int totalOptions)
{
//PlaySound(TEXT("space-266642 (online-audio-converter.com).wav") , NULL , SND_FILENAME | SND_ASYNC | SND_LOOP);
system("cls");
cout <<GREEN << R"(
(_) | |
___ _ __ __ _ ___ ___ _ _ ____ ____ _ __| | ___ _ __ ___
/ __| '_ \ / _` |/ __/ _ \ | | '_ \ \ / / _` |/ _` |/ _ \ '__/ __|
\__ \ |_) | (_| | (_| __/ | | | | \ V / (_| | (_| | __/ | \__ \
|___/ .__/ \__,_|\___\___| |_|_| |_|\_/ \__,_|\__,_|\___|_| |___/
| |
|_|
)" << RESET << endl;
cout <<CYAN<<"╔════════════════╗" << endl;
for (int i = 0; i < totalOptions; i++)
{
if (i == currentOption)
{
cout <<CYAN<<" \033[1;37;42m " << options[i] <<CYAN<<" \033[0m " << endl;
}
else
{
cout <<CYAN<<" " << options[i] << " " << endl;
}
}
cout <<CYAN<<"╚════════════════╝" << endl;
cout <<GREEN<<"\n" << "Description: " << descriptions[currentOption] << RESET<<endl;
//PlaySound(0 , 0 , 0);
}
void main_menu()
{
const int totalOptions = 5;
string options[totalOptions] =
{
"New Game",
"Load Game",
"Leaderboard",
"How to Play",
"Exit"
};
string descriptions[totalOptions] =
{
"Start a new game from scratch.",
"Load a previously saved game.",
"View the top scores and achievements.",
"Learn how to play the game.",
"Exit the program."
};
int currentOption = 0;
// playSound();
while (true) {
displayMenu(currentOption, options, descriptions, totalOptions);
char input = _getch();
if (input == 'w' || input == 'W') {
Beep(523, 100);
currentOption--;
if (currentOption < 0) currentOption = totalOptions - 1;
} else if (input == 's' || input == 'S') {
Beep(523, 100);
currentOption++;
if (currentOption >= totalOptions) currentOption = 0;
} else if (input == '\r') {
Beep(600, 150);
system("cls");
displayLoadingAnimation();
cout << "You selected: " << options[currentOption] << endl;
switch (currentOption) {
case 0:
newgame();
break;
case 1:
load_game();
break;
case 2:
display_leaderboard();
break;
case 3:
How_to_play();
break;
case 4:
cout<<RED<<"GOODBYE"<<RESET <<"🖐🏻"<<endl;
return;
}
break;
}
Sleep(100);
}
}
void show_cursor()
{
cout << "\033[?25h";
cout.flush();
}
void printCharacterByCharacter(const string& text, int delay = 50)
{
for (char c : text)
{
cout <<BLUE<<c;
cout.flush();
this_thread::sleep_for(chrono::milliseconds(delay));
}
}
void How_to_play()
{
system("cls");
const string spaceInvadersInstructions = R"(
The goal of Space Invaders is to defeat waves of descending aliens while avoiding their attacks. You must eliminate all the aliens before they reach the bottom of the screen.
Controls:
• Move Left/Right: Use the left and right arrow keys to move your spaceship horizontally.
• Shoot: Press the spacebar to fire bullets at the aliens.
Gameplay:
1. Start the Game: Begin by pressing the start button. The game will display the first wave of aliens.
2. Aliens Movement: Aliens move horizontally across the screen and gradually descend. They will change direction when they hit the edge of the screen.
3. Shooting Aliens: Aim and shoot at the aliens. Each alien has a different point value, and some may take multiple hits to defeat.
4. Defensive Barriers: Use the barriers on the screen for cover. They can absorb some shots from the aliens but will be destroyed over time.
5. Levels: After clearing a wave, a new wave will appear, often with increased speed and difficulty.
6. Game Over: The game ends when an alien reaches the bottom of the screen or when you lose all your lives.
Tips:
• Stay Mobile: Keep moving to avoid enemy fire and to position yourself better for shooting.
• Aim for Higher Points: Target the more valuable aliens first to maximize your score.
• Practice Timing: Learn the patterns of the aliens to improve your shooting accuracy.
Enjoy your battle against the invaders!
Goodluck soldier 😊
)";
printCharacterByCharacter(spaceInvadersInstructions, 50);
cout <<endl;
cout<<GREEN<<"press a key to return to the menu"<<RESET<<endl;
char key = getch();
main_menu();
}
void newgame()
{
reset_game_info();
start_time = time(0);
system("cls");
cout<<GREEN<<" ╔═══╦════════════════╗"<<endl;
cout<<" ║1. ║ QUICK GAME ║"<<endl;
cout<<" ║2. ║ CUSTOMIZE GAME ║"<<endl;
cout<<" ║3. ║ RETURN TO MENU ║"<<endl;
cout<<" ╚═══╩════════════════╝"<<RESET<<endl;\
char option = getch();
string name;
char theme = '1';
theme = current_game.theme;
current_game.score = 0;
current_game.time = 0;
screen_hight = 20;
screen_width = 20;
switch (option)
{
case '1':
cout<<MAGENTA<<"ENTER YOUR NAME : "<<endl;
cin >> name;
current_game.name = name;
cout<<RESET<<endl;
system("cls");
board_makear();
game_loop(theme);
break;
case '2':
cout<<"please choose your game board themes "<<endl;
themes();
theme = getch();
cout<<MAGENTA<<"ENTER YOUR NAME : "<<endl;
cin >> name;
current_game.name = name;
cout <<"PLEASE CUSTOMIZE YOUR BOARD SIZE (SQUARE BOARD ONLY)"<<endl;
cout<<"screen_hight : " ;
cin >> screen_hight;
getValidatedInput();
cout<<endl<<"screen_width : ";
cin >> screen_width;
getValidatedInput();
while(screen_hight != screen_width || screen_width > 40 || screen_hight > 40)
{
cout<<RED<<"WE NEED SAME NUMBER AND SMALLER THAN 40 TO MAKE YOUR BOARD : "<<endl;
cout<<MAGENTA<<"screen_hight : " ;
cin >> screen_hight;
getValidatedInput();
cout<<endl<<"screen_width : ";
cin >> screen_width;
getValidatedInput();
}
cout<<RESET<<endl;
system("cls");
board_makear();
game_loop(theme);
break;
case '3':
main_menu();
break;
default :
newgame();
break;
}
}
void themes()
{
cout<<"1. classic board"<<endl;
cout<<MAGENTA<<"╔═════╗"<<endl;
cout<<"║ ║"<<endl;
cout<<"╚═════╝"<<RESET<<endl;
cout<<"2.hearts board"<<endl;
cout<<RED<<" ♡♡♡♡♡♡♡"<<endl;
cout<<endl;
cout<<endl;
cout<<" ♡♡♡♡♡♡♡"<<RESET<<endl;
cout<<"3. triangles board"<<endl;
cout<<BLUE<<" ⏶⏶⏶⏶⏶⏶⏶"<<endl;
cout<<endl;
cout<<endl;
cout<<" ⏷⏷⏷⏷⏷⏷⏷"<<RESET<<endl;
cout<<"4. stars board"<<endl;
cout<<YELLOW<<" ✮✮✮✮✮✮✮"<<endl;
cout<<endl;
cout<<endl;
cout<<" ✮✮✮✮✮✮✮"<<RESET<<endl;
}
void display_leaderboard()
{
system("cls");
ifstream file("scoreboard.txt");
const int maxplayers = 100;
string name[maxplayers];
int scores[maxplayers];
int count = 0;
if (file.is_open() )
{
while (file >> name[count] >> scores[count])
{
count++;
}
file.close();
}
else
{
cout << "Error: Could not open leaderboard file." << endl;
return;
}
for (int i = 0; i < count - 1; ++i)
{
for (int j = 0; j < count - i - 1; ++j)
{
if (scores[j] < scores[j + 1])
{
int tempScore = scores[j];
scores[j] = scores[j + 1];
scores[j + 1] = tempScore;
string tempName = name[j];
name[j] = name[j + 1];
name[j + 1] = tempName;
}
}
}
cout <<MAGENTA<<"Leaderboard:" << endl;
cout <<CYAN<<"-----------------------" << endl;
for (int i = 0; i < count; ++i)
{
cout <<MAGENTA<<name[i] << " : " << scores[i] <<RESET<< endl;
cout <<CYAN<<"-----------------------" << endl;
}
if (count == 0)
{
cout <<RED<<"No leaderboard data available." << endl;
}
cout<<GREEN<<"press a key to return to the menu"<<RESET<<endl;
char key = getch();
main_menu();
}
void board_makear()
{
if (game_board != nullptr)
{
free_board();
}
game_board = new string*[screen_hight];
for (int i = 0; i < screen_hight; i++)
{
game_board[i] = new string[screen_width];
}
for (int i = 0; i < screen_hight; i++) {
for (int j = 0; j < screen_width; j++) {
game_board[i][j] = ' ';
}
}
game_board[screen_hight - 1][screen_width / 2] = PLAYER;
for (int i = 0 ; i < 4; i++)
{
for (int j = 0; j < screen_width /2; j++)
{
if(i == 1) game_board[1][j] = E3;
else if(i == 2 ) game_board[2][j] = E2;
else if (i == 3) game_board[3][j] = E1;
}
}
for(int i = screen_hight-3 ; i > screen_hight - 5 ; i-- )
{
for(int j = 0 ; j < screen_width ; j +=2)
{
game_board[i][j] = "3";
}
}
}
void time_and_score()
{
reset_cursor();
time_t now = time(0);
int elapsed_time = static_cast<int>(difftime(now, start_time));
current_game.time = elapsed_time;
cout << GREEN << "Score: " << current_game.score <<endl;
cout << YELLOW << "Time: " << elapsed_time << "s" << RESET <<endl;
}
void display_board()
{
int h = 2 * screen_hight;
while(h != -3)
{
if(h == 2 * screen_hight) cout<<MAGENTA<<"╔";
else if(h == -2 ) cout<<"╗"<<RESET<<endl;
else cout<<"═";
h--;
}
for (int i = 0; i < screen_hight; i++)
{
for (int j = 0; j < screen_width; j++)
{
if (j == 0) cout<<MAGENTA<<"║";
if(game_board[i][j]== E3) cout<<YELLOW<<game_board[i][j]<<" ";
else if(game_board[i][j] == E2) cout<<GREEN<<game_board[i][j]<<" ";
else if(game_board[i][j] == E1) cout <<BLUE<<game_board[i][j]<<" ";
else if((i == screen_hight - 3 || i == screen_hight - 4) && game_board[i][j] == "3" ) cout<<CYAN<<"╳" <<" ";
else if((i == screen_hight - 3 || i == screen_hight - 4) && game_board[i][j] == "2" ) cout<<YELLOW<<"╳" <<" ";
else if((i == screen_hight - 3 || i == screen_hight - 4) && game_board[i][j] == "1" ) cout<<MAGENTA<<"╳" <<" ";
else if((i == screen_hight - 3 || i == screen_hight - 4) && game_board[i][j] == "0" ) cout<<RED<<"╳" <<" ";
else if(game_board[i][j] == SHOOT)cout<<MAGENTA<<game_board[i][j]<<" ";
else if(game_board[i][j] == E4)cout<<RED<<game_board[i][j]<<" ";
else cout <<RESET<<game_board[i][j] <<" ";
if(j == screen_width - 1 ) cout<<MAGENTA<<" ║"<<RESET;
}
cout << endl;
}
h = 2 * screen_hight;
while(h != -3)
{
if(h == 2 * screen_hight) cout<<MAGENTA<<"╚";
else if(h == -2 ) cout<<"╝"<<RESET<<endl;
else cout<<"═";
h--;
}
}
void health_bar()
{
if(health > 0)
{
cout << " " << BLUE << "Health: ";
for (int i = 2; 0 <= i ; i--)
{
switch (i)
{
case 0 :
if(health > i)
cout<< "🧡"<<" ";
else
cout<< " "<<" ";
break;
case 1 :
if(health > i)
cout<< "💛"<<" ";
else
cout<< " "<<" ";
break;
case 2 :
if(health > i)
cout<<"💚"<<" ";
else
cout<< " "<<" ";
break;
}
}
cout<<endl;
}
else
{
cout<<RED<<"╔══════════════════╗"<<endl;
cout<<"║ GAME OVER ║"<<endl;
cout<<"╚══════════════════╝"<<RESET<<endl;
cout<<GREEN<<"press a key to return to the menu"<<RESET<<endl;
char key = getch();
main_menu();
}
}
void savedata(const string& playerName, int score)
{
{
ofstream file("scoreboard.txt", std::ios::app);
if (file.is_open())
{
file << playerName << " " << score << endl;
file.close();
}
else
{
cout << "Error: Unable to save leaderboard." << endl;
}
}
}
void save_game()
{
ofstream file("save_game.txt" , std::ios::out);
if (!file.is_open())
{
cout << RED << "Error: Could not save the game!" << RESET << endl;
return;
}
file<<"Screen hight "<<screen_hight<<endl;
file<<"Screen width "<<screen_width<<endl;
file<<"Theme "<<current_game.theme<<endl;
file << "Name " << current_game.name << endl;
file << "Score " << current_game.score << endl;
file << "Health " << health << endl;
file << "TimeElapsed " << difftime(time(0), start_time) << endl;
file << "Bullets " << endl;
for (int i = 0; i < MAX_BULLET; i++)
{
file << bullet[i].x << " " << bullet[i].y << " " << bullet[i].active << endl;
}
file << "GameBoard : " << endl;
for (int i = 0; i < screen_hight; i++)
{
for (int j = 0; j < screen_width; j++)
{
//
file << game_board[i][j] << " ";
}
file << endl;
}
file.close();
cout << GREEN << "Game saved successfully!" << endl;
cout<<"press a key to return to the menu ..."<<RESET<<endl;
char key = getch();
}
void free_board()
{
for (int i = 0; i < screen_hight; i++)
{
delete[] game_board[i];
}
delete[] game_board;
game_board = nullptr;
}
void move_player(int direction)
{
int player_x = -1;
for (int j = 0; j < screen_width; j++)
{
if (game_board[screen_hight - 1][j] == PLAYER)
{
player_x = j;
break;
}
}
if (player_x == -1) return;
game_board[screen_hight - 1][player_x] = " ";
int new_x = player_x + direction;
if (new_x >= 0 && new_x < screen_width)
{
game_board[screen_hight - 1][new_x] = PLAYER;
}
else
{
game_board[screen_hight - 1][player_x] = PLAYER;
}
}
void pause_menu(bool& running)
{
system("cls");
cout<<BLUE<<"╔═══╦═══════════════╗"<<endl;
cout<<"║1. ║ RESUME ║"<<endl;
cout<<"║2. ║ SAVE AND EXIT ║"<<endl;
cout<<"║3. ║ STORE ║"<<endl;
cout<<"║4. ║ EXIT ║"<<endl;
cout<<"╚═══╩═══════════════╝"<<RESET<<endl;\
char option = getch();
switch (option)
{
case '1' :
system("cls");
break;
case '2' :
save_game();
running = 0;
savedata(current_game.name, current_game.score);
current_game.score = 0;
bullet[0].active = false;
free_board();
main_menu();
break;
case '3':
handle_store(running);
break;
case '4' :
running = 0;
savedata(current_game.name, current_game.score);
current_game.score = 0;
bullet[0].active = false;
free_board();
main_menu();
break;
default :
pause_menu(running);
break;
}
}
void reset_cursor()
{
cout << "\033[H";
cout.flush();
}
void game_loop(char& theme )
{
int game_speed = 35;
bool running = true;
current_game.time= 0;
current_game.score = 0;
while (running)
{
reset_cursor();
time_and_score();
switch (theme)
{
case '1' :
display_board();
break;
case '2' :
heart_board();
break;
case '3' :
triangle_board();
break;
case '4' :
star_board();
break;
default :
newgame();
break;
}
move_bullets();
handle_bombs();
move_enemies(running);
move_enemy_bullets(running);
move_special_enemy();
handle_special_enemy();
check_win();
health_bar();
if(!check_win)
{
running = false;
}
srand(time(0));
if (rand() % 10 < 2)
{
enemy_shoots();
}
if (_kbhit())
{
char key =tolower(getch());
switch (key)
{
case 'a':
move_player(-1);
break;
case 'd':
move_player(1);
break;
case ' ':
player_shoots();
break;
case 'b':
player_shoot_bomb();
break;
case 'p':
pause_menu(running);
break;
}
}
if(current_game.score % 60 == 0) game_speed -= 10;
this_thread::sleep_for(chrono::milliseconds(game_speed));
if(check_board())
{
cout<<GREEN<<"Perfect "<<current_game.name<<" you are done this level"<<endl;
cout<<"Score : "<<current_game.score<<endl;
cout<<"Time : "<<current_game.time<<endl;
cout<<"Do you want go to next level? (press Y for yes or any key to back menu)"<<RESET<<endl;
char key = tolower(getch());
if(key == 'y')
{
system("cls");
free_board();
reset_game_info();
board_makear2();
running = false;
bullet[1].active = false;
for(int i = 0 ; i < MAX_ENEMY_BULLET ; i++)
{
enemy_bullets[i].active = false;
}
game_loop2(theme);
break;
}
else
{
main_menu();
}
}
}
}
void play_shoot_sound()
{
Beep(1000, 100);
}
void player_shoots()
{
for (int i = 0; i < MAX_BULLET; i++)
{
if (!bullet[i].active)
{
for (int j = 0; j < screen_width; j++)
{
if (game_board[screen_hight - 1][j] == PLAYER)
{
bullet[i] = {j, screen_hight - 2, true};
game_board[bullet[i].y][bullet[i].x] = SHOOT;
play_shoot_sound();
break;
}
}
break;
}
}
}
void move_bullets()
{
for (int i = 0; i < MAX_BULLET; i++)
{
if (bullet[i].active)
{
game_board[bullet[i].y][bullet[i].x] = " ";
if (bullet[i].y > 0)
{
bullet[i].y--;
if (game_board[bullet[i].y][bullet[i].x] == E1)
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
current_game.score += 10;
}
else if (game_board[bullet[i].y][bullet[i].x] == E2)
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
current_game.score += 20;
}
else if (game_board[bullet[i].y][bullet[i].x] == E3)
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
current_game.score += 40;
}
else if (game_board[bullet[i].y][bullet[i].x] == "3")
{
game_board[bullet[i].y][bullet[i].x] = "2";
bullet[i].active = false;
}
else if (game_board[bullet[i].y][bullet[i].x] == "2")
{
game_board[bullet[i].y][bullet[i].x] = "1";
bullet[i].active = false;
}
else if (game_board[bullet[i].y][bullet[i].x] == "1")
{
game_board[bullet[i].y][bullet[i].x] = "0";
bullet[i].active = false;
}
else if (game_board[bullet[i].y][bullet[i].x] == "0")
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
}
else if(game_board[bullet[i].y][bullet[i].x] == E4)
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
current_game.score += 100;
}
else if(game_board[bullet[i].y][bullet[i].x] == ENENMY_SHOOT)
{
game_board[bullet[i].y][bullet[i].x] = " ";
bullet[i].active = false;
}
else
{
game_board[bullet[i].y][bullet[i].x] = SHOOT;
}
}
else
{
bullet[i].active = false;