-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane.c
1716 lines (1695 loc) · 51.9 KB
/
plane.c
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 <ncurses.h> //adding ncurses //
#include <unistd.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define Min_X_GamePlay 0 // gameplay window //
#define Min_Y_GamePlay 0
#define GamePlay_COLS 150
#define GamePlay_LINES 57
#define Min_X_Detail 150 // detail window //
#define Min_Y_Detail 0
#define Detail_COLS 36
#define Detail_LINES 28
#define Min_X_Pause 150 // pause window //
#define Min_Y_Pause 28
#define Pause_COLS 36
#define Pause_LINES 29
#define Min_X_Info 70 // pause window //
#define Min_Y_Info 18
#define Info_COLS 45
#define Info_LINES 20
typedef struct Player player;
typedef struct Plane plane;
typedef struct Ship ship;
typedef struct Bullet bullet;
typedef struct Helicopter helicopter;
typedef struct LeftBody leftBody ;
typedef struct RightBody rightBody;
typedef struct Fuel fuel;
WINDOW *detail;
WINDOW *gameplay;
WINDOW *Pause;
int PLANE = 1;
int SPEED = 11;
struct Player
{
char name[50]; // name string //
int age; // player age //
int score; // player score //
char datetime[50]; // time & date of the game start //
int GameLevel;
int PlaneType;
};
struct Plane
{
int fuel; // plane fuel //
int bodyX[8]; // body x's //
int bodyY[8]; // body y's //
int life; // plane life //
char body[8][14]; // plane body //
char lastBody[8][14];
};
struct Ship
{
int bodyX[4]; // body x's //
int bodyY[4]; // body y's //
char body[4][11];
char lastBody[4][11];
};
struct Bullet
{
int x; // bullet x's //
int y; // bullet y's //
int lastX;
int lastY;
};
struct LeftBody
{
int leftSideBodyX[10]; // gameBody x's //
int leftSideBodyY[10]; // gameBody y's //
char body[10][12];
char lastBody[10][12];
};
struct RightBody
{
int rightSideBodyX[10]; // gameBody x's //
int rightSideBodyY[10]; // gameBody y's //
char body[10][12];
char lastBody[10][12];
};
struct Fuel
{
int bodyX[2]; // fuel body x's //
int bodyY[2]; // fuel body y's //
char body[2][5];
char lastBody[2][5];
};
struct Helicopter
{
int bodyX[6]; // helicopter body x's //
int bodyY[6]; // helicopter body y's //
char body[6][10];
char lastBody[6][10];
};
void MainMenu() ;
void StartGame () ;
void HowToPlay() ;
void About();
int ExitGame();
void ScoresTable();
void PrintMainMenu(int choice);
void SaveScore(player guest);
void PrintSettingsMenu ( int choice );
void SettingsMenu();
void ChooseYourPlane();
void ChangeGameSpeed();
void StartSound();
void ShipDestroySound();
void HelicopterDestroySound();
void GameOverSound();
void PlaneHitSound();
void ThanksSound();
void FuelFillSound();
void removeShip(ship *titanic);
void initialization (plane *f35, player *guest, ship titanic[], leftBody LB[], rightBody RB[], fuel gasoline[] , helicopter MQ8[] , int PLANE ) ;
int main() /* Main */
{
initscr(); // enter ncurses //
curs_set(0); // disable curser show on terminal //
start_color(); // starting colour //
keypad(stdscr,TRUE); // enable kayboard //
init_pair(99, COLOR_WHITE, COLOR_BLACK);
Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 640);
wbkgd(stdscr, COLOR_PAIR(99));
echo(); // enable echo on the screen //
cbreak(); // cbreak mode ( ctrl + c ) //
raw(); // disable line buffering //
MainMenu();
endwin(); // end ncurses mode //
return 0;
}
void MainMenu()/* Game Manu */
{
int key;
int choice = 0;
StartSound();
PrintMainMenu(choice);
noecho();
do
{
key = getch();
switch(key)
{
case KEY_DOWN:
choice++;
if(choice > 5 ) choice = 0;
break;
case KEY_UP:
choice--;
if(choice < 0) choice = 5 ;
break;
default:
break;
}
PrintMainMenu(choice);
}
while(key != '\n');
echo();
wclear(stdscr);
refresh();
if (choice == 0) StartGame(); // Starting Game //
if (choice == 1) ScoresTable(); // show scores //
if (choice == 2) HowToPlay(); // tuturial for play //
if (choice == 3) SettingsMenu(); // Game Settings //
if (choice == 4) About(); // about writer //
if (choice == 5) ExitGame(); // exit game //
refresh();
}
void PrintSettingsMenu ( int choice )/*Settings Menu */
{
char SettingsItems[3][20];
int i;
strcpy(SettingsItems[0] , "GAME SPEED");
strcpy(SettingsItems[1] , "PLANE SHAPE");
strcpy(SettingsItems[2] , "BACK");
for(i=0; i<3; i++)
{
if( i == choice )
attron( A_REVERSE | A_BOLD);
mvaddstr ( 10+(i*3) , COLS/2-55 , SettingsItems[i] );
attroff( A_REVERSE | A_BOLD);
}
refresh();
}
void SettingsMenu()/*Settings Menu */
{
wclear(stdscr);
wrefresh(stdscr);
refresh();
nodelay(stdscr , 0 );
int PLANE;
int input;
int choice = 0 ;
PrintSettingsMenu(choice);
noecho();
do{
input = getch();
switch(input)
{
case KEY_DOWN :
choice++;
if(choice > 2 ) choice = 0;
break;
case KEY_UP :
choice--;
if(choice < 0) choice = 2 ;
break;
default:
break;
}
PrintSettingsMenu(choice);
}
while (input != '\n');
echo();
wclear(stdscr);
if(choice == 0 )
{
ChangeGameSpeed();
}
if(choice == 1 )
{
ChooseYourPlane();
}
if(choice == 2 )
{
MainMenu();
}
}
void ChangeGameSpeed()
{
wclear(stdscr);
refresh();
int input;
int S=0 , L=1;
do
{
nodelay(stdscr , 1 );
input = getch();
attron(A_REVERSE);
mvprintw(20 , 30 , "<");
mvprintw(20 , 40 , ">");
attroff(A_REVERSE);
if(S==0)
{
mvprintw( 20 , 31 , " ");
mvprintw( 20 , 34 , "EASY");
SPEED = 13;
}
if(S==1)
{
mvprintw( 20 , 31 , " ");
mvprintw( 20 , 32 , "MEDIUM");
SPEED = 9;
}
if(S==2)
{
mvprintw( 20 , 31 , " ");
mvprintw( 20 , 34 , "HARD");
SPEED = 4;
}
switch(input)
{
case KEY_RIGHT :
S++;
if (S>2) S=0;
break;
case KEY_LEFT :
S--;
if (S<0) S=2;
break;
default:
break;
}
}
while (input != '\n');
refresh();
if(S==0 || S==1 || S==2) SettingsMenu();
}
void PrintMainMenu(int choice)/* Print Menu */
{
init_pair(101,COLOR_GREEN,COLOR_BLACK);
init_pair(130,COLOR_CYAN,COLOR_BLACK);
int i ;
char titles[6][25];
strcpy(titles[0],"S T A R T G A M E") ;
strcpy(titles[1],"S C O R E S") ;
strcpy(titles[2],"H O W T O P L A Y") ;
strcpy(titles[3],"S E T T I N G S");
strcpy(titles[4],"A B O U T");
strcpy(titles[5],"E X I T");
wclear(stdscr);
char wlc[6][57];
char jt[21][71];
FILE *w = fopen("welcome.txt" , "r"); /* welcome shape in welcome */
for(i=0 ; i<6 ; i++)
{
fgets(wlc[i] , sizeof(wlc[i]) , w );
attron(COLOR_PAIR(101));
mvprintw(2+i , 65 , "%s" , wlc[i]);
refresh();
attroff(COLOR_PAIR(101));
}
fclose(w);
FILE *jet = fopen("jet_21_70.txt" , "r"); /* plane shape in welcome */
for(i=0 ; i<21 ; i++)
{
fgets(jt[i] , sizeof(jt[i]) , jet );
attron(COLOR_PAIR(130) | A_BOLD );
mvprintw(10+i , 100 ,"%s" , jt[i]);
attroff(COLOR_PAIR(130) | A_BOLD );
}
fclose(jet);
mvprintw(4 , 87 , "W E L C O M E");
mvprintw(5 , 83, "Written By : H4D1B1K3Y");
for(i=0; i<6; i++)
{
if( i == choice )
attron( A_REVERSE | A_BOLD);
if(i==0) mvaddstr( 20 , 35 , titles[0]);
if(i==1) mvaddstr( 22 , 38 , titles[1]);
if(i==2) mvaddstr( 24 , 35 , titles[2]);
if(i==3) mvaddstr( 26 , 37 , titles[3]);
if(i==4) mvaddstr( 28 , 39 , titles[4]);
if(i==5) mvaddstr( 30 , 40 , titles[5]);
attroff( A_REVERSE | A_BOLD);
}
refresh();
}
int RandomFunction()/* Generate Random Numbers between 127 & 14 */
{
napms(70);
int t;
srand(time(0)); // srand function for randomize by time //
do t = ((rand()%1000)*5*9/8)%185/2 ;
while ( t > 127 || t< 14 );
return t ;
}
void MyTypeFunction (WINDOW *win, int y, int x, char text[])/*Fantasy Type function with insch tool */
{
char *t;
int len = strlen(text);
t = text;
while (len)
{
wmove ( win, y, x );
winsch(win, *(t+len-1));
wrefresh(win);
napms(30);
len--;
}
}
void HowToPlay()/* How To Play For Players */
{
wclear(stdscr); // clear the standard screen //
refresh();
attron(A_BOLD); // bold attribute //
MyTypeFunction(stdscr, 10,10,"-Welcome To RiverRaid Game");
MyTypeFunction(stdscr, 11,10,"-You Have To Move The Plane & Save It From Crashes By \"W\" - \"A\" - \"S\" - \"D\" Buttons");
MyTypeFunction(stdscr, 12,10,"-If U Collapse The Jungle You Will Loose One Life");
MyTypeFunction(stdscr, 13,10,"-If U Collapse The Ships & Helicopters You Will Loose One Life");
MyTypeFunction(stdscr, 14,10,"-You Can Shoot & Destroy The Ships & Helicopters By Tapping \"H\" Button");
MyTypeFunction(stdscr, 15,10,"-The Plane's Fuel Increasing By The Time & If That Became Empty You Will Die");
MyTypeFunction(stdscr, 16,10,"-You Can Use Fuels Which Puted In the Way To Fill The Plane's Fuel");
MyTypeFunction(stdscr, 20 , 10 , "press any key to continue...");
attroff(A_BOLD); // turn off attribute //
nodelay ( stdscr, 0); // wait for input //
getch(); // get input //
MainMenu(); // goto main menu //
}
void About()/*About Writer */
{
wclear(stdscr);
attron(A_BOLD);
MyTypeFunction(stdscr, 10, 10, "Written By : H4D1B1K3Y");
MyTypeFunction(stdscr, 11, 10, "Computer Engeeniring Student At Zanjan University");
MyTypeFunction(stdscr, 12, 10, "Midterm Project - Dec 2017");
MyTypeFunction(stdscr, 13, 10, "Many Thanks To My Teacher : Mr. Hossein Mohammadi & Our Class Assistant : Mr. Amir Ghasemi");
MyTypeFunction(stdscr, 14, 10, "Send Feedback");
MyTypeFunction(stdscr, 15, 10, "[email protected]");
MyTypeFunction(stdscr, 16, 10, "www.telegram.me/hadibikey");
MyTypeFunction(stdscr, 20, 10, "Press Any Key to continue ...");
attroff(A_BOLD);
refresh();
nodelay ( stdscr, 0 );
getch();
MainMenu();
}
void ScoresTable()/*Show Scores */
{
int i;
wclear(stdscr);
wrefresh(stdscr); // refresh standard screen //
init_pair(129 , COLOR_YELLOW , COLOR_BLACK );
init_pair(130 , COLOR_CYAN , COLOR_BLACK );
init_pair(131 , COLOR_GREEN , COLOR_BLACK );
init_pair(132 , COLOR_WHITE , COLOR_BLACK );
attron(A_BOLD);
attrset(COLOR_PAIR(129));
mvprintw(10,20,"NAME");
attrset(COLOR_PAIR(130));
mvprintw(10,40,"AGE");
attrset(COLOR_PAIR(131));
mvprintw(10,60,"SCORE");
attrset(COLOR_PAIR(132));
mvprintw(10,80,"DATE");
FILE *ScoresTable = fopen("scores.hd" , "r+"); // opening scores file //
player pl[30];
fread(pl, sizeof(player) , 30 , ScoresTable ); // reading structures from file and putting into array //
fclose(ScoresTable);
for(i=0 ; i<30 ; i++)
{
attrset(COLOR_PAIR(129));
mvprintw(12+i , 20 , "%s" , pl[i].name ); // print names //
attrset(COLOR_PAIR(130));
mvprintw(12+i , 40 , "%d" , pl[i].age ); // print ages //
attrset(COLOR_PAIR(131));
mvprintw(12+i , 60 , "%d" , pl[i].score ); // print scores //
attrset(COLOR_PAIR(132));
mvprintw(12+i , 80 , "%s" , pl[i].datetime ); // print date of play //
}
MyTypeFunction(stdscr , 50 , 20 , "press any key to continue ... ");
attroff(A_BOLD);
nodelay(stdscr , 0 );
char ch = getch() ;
MainMenu();
refresh();
}
void RecievePlayerInformation(player *guest)/*recieve player information */
{
wclear(gameplay);
wclear(detail);
wclear(Pause);
wbkgd(gameplay, COLOR_BLACK ) ; // make //
wbkgd(detail, COLOR_BLACK) ; // window //
wbkgd(Pause,COLOR_BLACK) ; // colorful //
wrefresh(detail) ;
wrefresh(gameplay) ;
wrefresh(Pause) ;
WINDOW *info; // make window pointer //
info=newwin(Info_LINES , Info_COLS , Min_Y_Info , Min_X_Info ); // creating information window //
init_pair(100,COLOR_WHITE,COLOR_GREEN) ;
wbkgd(info,COLOR_PAIR(100)) ;
wattron(info, A_BOLD ) ;
MyTypeFunction(info,2,2,"PLAYER NAME :") ;
mvwscanw(info,2,16,"%s",&guest->name); // recieve name //
MyTypeFunction(info,4,2,"PLAYER AGE :") ;
mvwscanw(info,4,15,"%d",&guest->age) ; // recieve age //
napms(35);
wrefresh(info);
mvwprintw(info,12,2,"WELL DONE!") ;
napms(35) ;
wrefresh(info);
mvwprintw(info,14,2,"LET'S PLAY %s . . . ", guest->name);
napms(35);
wrefresh(info);
napms(35);
wattroff(info, A_BOLD );
delwin(info); // deleting information window //
wrefresh(gameplay);
}
void UpdateDetails(player guest, plane f35)/*Updating info on detail window */
{
init_pair(103,COLOR_BLACK,COLOR_YELLOW);
init_pair(105,COLOR_RED, COLOR_YELLOW);
wbkgd(detail,COLOR_PAIR(103));
wattron(detail, A_BOLD);
mvwprintw(detail,2,2,"%s",guest.datetime);
mvwprintw(detail,3,2,"PLAYER NAME : %s",guest.name);
mvwprintw(detail,4,2,"PLAYER AGE : %d",guest.age);
mvwprintw(detail,5,2,"PLAYER SCORE : %d",guest.score);
mvwprintw(detail,19,1,"FUEL:");
mvwprintw(detail,16,1,"LIFE:");
wattron(detail, COLOR_PAIR(105));
mvwprintw(detail,25,2,"Press P to Pause The Game");
mvwprintw(detail,26,2,"Press Q to Quit The Game");
wattroff(detail, COLOR_PAIR(105) | A_BOLD );
wrefresh(detail);
}
int ExitGame()/*exit game */
{
char c;
wclear(stdscr);
refresh();
attron(A_BOLD);
MyTypeFunction(stdscr,28 , 77, "ARE YOU SURE WANT TO EXIT ?? Y/N");
attroff(A_BOLD);
while (1)
{
nodelay ( stdscr, 1 );
noecho();
c = getch();
echo();
if ( c == 'y' || c == 'Y')
{
wclear(stdscr);
ThanksSound();
attron(A_BOLD);
MyTypeFunction(stdscr, 28, 82 , "Thanks For Playing ..." );
attroff(A_BOLD);
refresh();
napms(1000);
endwin();
exit(0);
}
if ( c == 'n' || c == 'N') MainMenu();
else continue;
}
}
void ExtraGame(plane *f35 , player *guest ,int *ask )
{
if(guest->score>=15)
{
int temp = guest->score;
mvwprintw(detail,5,18," ");
wrefresh(detail);
guest->score = temp - 15 ;
f35->life +=2 ;
*ask = 1;
}
else if(guest->score < 14)
{
wattron(Pause , A_BOLD);
MyTypeFunction(Pause , 11 , 2 , "YOU DONT HAVE ENOUGH SCORE!");
wattroff(Pause , A_BOLD);
wrefresh(Pause);
}
}
void Crashed(player *guest , plane *f35)/*game over */
{
SaveScore(*guest); /* save scores */
GameOverSound(); /* game over sound */
int k ;
int ask=0;
char c;
init_pair(110, COLOR_WHITE, COLOR_MAGENTA);
init_pair(111, COLOR_YELLOW, COLOR_MAGENTA);
init_pair(112, COLOR_CYAN, COLOR_MAGENTA );
Pause = newwin (Pause_LINES , Pause_COLS , Min_Y_Pause , Min_X_Pause );
wclear(Pause);
wbkgd(Pause, COLOR_PAIR(110));
wattron(Pause, A_BOLD);
MyTypeFunction(Pause,7,2,"1-PLAY AGAIN");
MyTypeFunction(Pause,8,2,"2-EXIT");
MyTypeFunction(Pause,9,2,"3-EXTRA GAME");
wattroff(Pause, A_BOLD);
wrefresh(Pause);
while(1)
{
napms(6);
k++;
if ( k %150 == 0 )
{
wattron (Pause, A_BOLD | COLOR_PAIR(111));
mvwprintw(Pause,6,2,"YOU LOOSE !!");
wattroff (Pause, A_BOLD | COLOR_PAIR(111));
wrefresh(Pause);
napms(500);
wattron ( Pause, A_BOLD | COLOR_PAIR(112));
mvwprintw(Pause,6,2,"YOU LOOSE !!");
wattroff (Pause, A_BOLD | COLOR_PAIR(112));
}
nodelay ( Pause, 1 );
noecho();
c = wgetch(Pause);
echo();
if (c == '1')
{
StartGame();
}
if (c == '2')
ExitGame();
if (c == '3'){
ExtraGame(&(*f35) , &(*guest) , &ask );
if (ask == 1 ){
wclear(Pause);
wrefresh(Pause);
break;
}
}
else continue ;
wrefresh(Pause);
}
}
void GamePaused()/*- pause game */
{
char c;
int k;
Pause = newwin (Pause_LINES , Pause_COLS , Min_Y_Pause , Min_X_Pause );
init_pair(110, COLOR_WHITE, COLOR_MAGENTA);
wbkgd(Pause, COLOR_PAIR(110));
while (1)
{
napms(6);
k++;
wattron(Pause, A_BOLD);
if (k % 220 == 0)
{
MyTypeFunction(Pause, 2 , 2 , " PAUSED!! ");
}
mvwprintw(Pause, 4, 2, "press R to resume");
mvwprintw(Pause, 6, 2, "press Q to Quit");
wattroff(Pause, A_BOLD);
nodelay(Pause, 1);
noecho();
c = wgetch(Pause);
echo();
if ( c == 'R' || c == 'r' )
{
wclear(Pause);
wrefresh(Pause);
break;
}
if ( c == 'q' || c == 'Q')
{
wattron(Pause, A_BOLD);
MyTypeFunction(Pause,8,2,"Quiting...");
wattron(Pause, A_BOLD);
wrefresh(Pause);
ThanksSound();
napms(2000);
endwin();
exit(0);
}
else continue;
}
}
void PrintJungle(leftBody *LB, rightBody *RB , int n )/* print jungles */
{
int i ;
init_pair(113, COLOR_BLACK, COLOR_GREEN);
init_pair(120 , COLOR_BLACK , COLOR_YELLOW);
for ( i = 0 ; i < 10 ; i++)/* clear jungles first */
{
mvwprintw(gameplay, LB->leftSideBodyY[i], LB->leftSideBodyX[i], LB->lastBody[i]);
mvwprintw(gameplay, RB->rightSideBodyY[i], RB->rightSideBodyX[i], RB->lastBody[i]);
}
for ( i = 0 ; i < 10 ; i++)/* Y's + 1 */
{
if(RB->rightSideBodyY[i]>=56 || LB->leftSideBodyY[i]>=56)
{
RB->rightSideBodyY[i] = 0 ;
LB->leftSideBodyY[i] = 0 ;
}
RB->rightSideBodyY[i]++;
LB->leftSideBodyY[i]++;
}
for ( i = 0 ; i <10 ; i++)/* finally print them */
{
if (n%2==0)wattron ( gameplay , COLOR_PAIR(113) | A_BOLD);
if (n%2!=0)wattron ( gameplay , COLOR_PAIR(120) | A_BOLD);
mvwprintw(gameplay , RB->rightSideBodyY[i], RB->rightSideBodyX[i] , "%s", RB->body[i]) ;
mvwprintw(gameplay , LB->leftSideBodyY[i], LB->leftSideBodyX[i] , "%s", LB->body[i]) ;
wrefresh(gameplay);
wattroff (gameplay, COLOR_PAIR(113) | COLOR_PAIR(120) | A_BOLD );
}
wrefresh( gameplay );
}
void SortScores(player pl[])/*sort scores in the array */
{
int h , t ;
player temp;
for(h=0; h<30; h++)
for(t=0; t<30; t++)
if (pl[h].score > pl[t].score)/* insertion sort */
{
temp = pl[h];
pl[h] = pl[t];
pl[t] = temp;
}
}
void SaveScore(player guest)/* save the score */
{
int i ;
player pl[30];/* first , we have a array of player structures */
for(i=0 ; i<30 ; i++)/* free them */
{
strcpy(pl[i].name , "" ) ;
pl[i].score = 0 ;
pl[i].age = 0 ;
strcpy(pl[i].datetime , "") ;
}
FILE *s2 = fopen("scores.hd" , "r+");/*open scores file */
fread(pl, sizeof(player) , 30 , s2 );/*read them to array */
fclose(s2);
if(guest.score >= pl[29].score)/* adding the score to array */
pl[29]=guest;
SortScores(pl);/* sorting them */
FILE *s3 = fopen("scores.hd" , "w");
fwrite(pl , sizeof(player) , 30 , s3 ) ; /* writing to the file , sorted */
fclose(s3);
}
void UpdatePrintPlane(plane *f35 , char c , int PLANE )/* update & print plane */
{
int pl;
if (PLANE == 1 ) pl = 5 ;
if (PLANE == 2 ) pl = 8 ;
init_pair(109, COLOR_RED, COLOR_BLUE) ;
init_pair(108, COLOR_YELLOW, COLOR_BLUE) ;
init_pair(117 , COLOR_WHITE , COLOR_BLUE) ;
int i;
for ( i = 0 ; i < pl ; i++)
mvwprintw(gameplay, f35->bodyY[i], f35->bodyX[i],f35->lastBody[i]);
if (c == 'A' || c == 'a' )
for ( i = 0 ; i<pl ; i++)
(f35->bodyX[i])--;
if (c == 'D' || c == 'd')
for (i = 0 ; i<pl ; i++)
(f35->bodyX[i])++;
if ( c == 'W' || c == 'w')
for ( i = 0 ; i<pl ; i++)
(f35->bodyY[i])--;
if ( c == 'S' || c == 's')
for (i = 0 ; i<pl ; i++ )
(f35->bodyY[i])++;
if (PLANE == 1 )
{
wattron(gameplay , A_BOLD | COLOR_PAIR(117));
mvwprintw(gameplay, f35->bodyY[0], f35->bodyX[0],f35->body[0]);
wattroff(gameplay , COLOR_PAIR(117));
wattron(gameplay, COLOR_PAIR(108));
mvwprintw(gameplay, f35->bodyY[1], f35->bodyX[1],f35->body[1]);
mvwprintw(gameplay, f35->bodyY[2], f35->bodyX[2],f35->body[2]);
mvwprintw(gameplay, f35->bodyY[3], f35->bodyX[3],f35->body[3]);
wattrset(gameplay, COLOR_PAIR(109));
mvwprintw(gameplay, f35->bodyY[4], f35->bodyX[4],f35->body[4]);
wattroff(gameplay, A_BOLD| COLOR_PAIR(108) | COLOR_PAIR(109));
}
if (PLANE == 2 )
{
wattron(gameplay , A_BOLD | COLOR_PAIR(108));
for(i=0 ; i<pl ; i++)
mvwprintw(gameplay, f35->bodyY[i], f35->bodyX[i],f35->body[i]);
wattroff(gameplay , A_BOLD | COLOR_PAIR(108));
}
}
void UpdatePrintShips ( ship *titanic)
{
int i ;
for ( i = 0 ; i < 4 ; i++ )
{
mvwprintw ( gameplay, titanic->bodyY[i], titanic->bodyX[i], "%s", titanic->lastBody[i]);
wrefresh(gameplay);
}
init_pair(104, COLOR_RED, COLOR_BLUE );
for ( i = 0 ; i < 4 ; i++ )
{
titanic->bodyY[i]++ ;
}
for ( i = 0 ; i < 4 ; i++ )
{
wattron(gameplay, COLOR_PAIR(104) | A_BOLD );
mvwprintw(gameplay, titanic->bodyY[i], titanic->bodyX[i],"%s", titanic->body[i]);
wattroff(gameplay, COLOR_PAIR(104) | A_BOLD);
wrefresh(gameplay);
}
}
void UpdatePrintFuels(fuel *gasoline)
{
init_pair(115, COLOR_WHITE, COLOR_BLACK );
int i;
for(i = 0 ; i < 2 ; i++)
{
mvwprintw(gameplay, gasoline->bodyY[i], gasoline->bodyX[i],gasoline->lastBody[i]);
wrefresh(gameplay);
}
for(i=0 ; i<2 ; i++)
{
gasoline->bodyY[i]++;
}
for(i = 0 ; i < 2 ; i++)
{
wattron(gameplay, A_BOLD | COLOR_PAIR(115));
mvwprintw(gameplay, gasoline->bodyY[i], gasoline->bodyX[i], gasoline->body[i]);
wattroff(gameplay, A_BOLD | COLOR_PAIR(115));
wrefresh(gameplay);
}
}
void HelicopterShoot( bullet a500[] , bullet b500[] , int bullA , int bullB)
{
int o ;
for(o=0 ; o<=bullA ; o++ )
{
mvwprintw( gameplay , a500[o].y , a500[o].x , " ");
a500[o].y++;
wattron(gameplay , COLOR_PAIR(123) | A_BOLD );
mvwprintw( gameplay , a500[o].y , a500[o].x , "*");
wattroff(gameplay , COLOR_PAIR(123) | A_BOLD );
}
for(o=0 ; o<=bullB ; o++ )
{
mvwprintw( gameplay , b500[o].y , b500[o].x , " ");
b500[o].y++;
wattron(gameplay , COLOR_PAIR(123) | A_BOLD );
mvwprintw( gameplay , b500[o].y , b500[o].x , "*");
wattroff(gameplay , COLOR_PAIR(123) | A_BOLD );
}
}
void PlaneShoot(bullet c500[] , int b)
{
int i ;
for(i=0 ; i <= b ; i++)
{
mvwprintw(gameplay, c500[i].y , c500[i].x ," ");
c500[i].y--;
wattron(gameplay, A_BOLD | COLOR_PAIR(107));
mvwprintw(gameplay, c500[i].y, c500[i].x, "|" );
wattroff(gameplay, A_BOLD | COLOR_PAIR(107));
}
}
void ShipAndHelicopterDestroyCheck(bullet c500[] , ship titanic[] , player *guest , plane *f35 ,int b , helicopter MQ8[])
{
int k , i , t ;
for(k=0 ; k<4 ; k++)
for(i = 0 ; i<=b ; i++)
for(t = 0 ; t < 7 ; t++)
{
if (( ( c500[i].y == titanic[k].bodyY[3] && c500[i].x == titanic[k].bodyX[3]+t) || (c500[i].y == titanic[k].bodyY[2] && (c500[i].x == titanic[k].bodyX[2] || c500[i].x == titanic[k].bodyX[2]+8 )) ) || ((c500[i].y == titanic[k].bodyY[3]-1 && c500[i].x == titanic[k].bodyX[3]+t) || (c500[i].y == titanic[k].bodyY[2]-1 && (c500[i].x == titanic[k].bodyX[2]-1 || c500[i].x == titanic[k].bodyX[2]+8 ))))
{
ShipDestroySound();
mvwprintw(gameplay , c500[i].y , c500[i].x , " ");
c500[i].y = -60;
guest->score++;
UpdateDetails(*guest,*f35);
wrefresh(detail);
for ( i = 0 ; i<4 ; i++)
{
mvwprintw(gameplay, titanic[k].bodyY[i], titanic[k].bodyX[i],"%s", titanic[k].lastBody[i]);
}
wrefresh(gameplay);
titanic[k].bodyX[0] = RandomFunction();
titanic[k].bodyX[1] = titanic[k].bodyX[0] - 3 ;
titanic[k].bodyX[2] = titanic[k].bodyX[0] - 3 ;
titanic[k].bodyX[3] = titanic[k].bodyX[0] - 2 ;
titanic[k].bodyY[3] = -5 ;
titanic[k].bodyY[2] = -6 ;
titanic[k].bodyY[1] = -7 ;
titanic[k].bodyY[0] = -8 ;
UpdatePrintShips(&titanic[k]);
}
}
for ( k = 0 ; k<2 ; k++ )
for(i = 0 ; i<=b ; i++)
for(t = 0 ; t < 7 ; t++ )
{
if ((c500[i].y == MQ8[k].bodyY[5] && c500[i].x == MQ8[k].bodyX[5]) || (c500[i].y == MQ8[k].bodyY[5] && c500[i].x == MQ8[k].bodyX[5]+1) || (c500[i].y == MQ8[k].bodyY[5] && c500[i].x == MQ8[k].bodyX[5]+2) || (c500[i].y == MQ8[k].bodyY[4] && c500[i].x == MQ8[k].bodyX[4]+t) )
{
HelicopterDestroySound();
mvwprintw(gameplay , c500[i].y , c500[i].x , " ");
c500[i].y = -60;
guest->score+=3;
UpdateDetails(*guest,*f35);
wrefresh(detail);
for ( i = 0 ; i<6 ; i++)
{
mvwprintw(gameplay, MQ8[k].bodyY[i], MQ8[k].bodyX[i]," ");
}
wrefresh(gameplay);
MQ8[k].bodyX[0] = RandomFunction();
MQ8[k].bodyX[1] = MQ8[k].bodyX[0] ;
MQ8[k].bodyX[2] = MQ8[k].bodyX[0] - 1 ;
MQ8[k].bodyX[3] = MQ8[k].bodyX[0] - 2 ;
MQ8[k].bodyX[4] = MQ8[k].bodyX[0] - 2 ;
MQ8[k].bodyX[5] = MQ8[k].bodyX[0] ;
MQ8[k].bodyY[0] = -5+1;
MQ8[k].bodyY[1] = -4+1;
MQ8[k].bodyY[2] = -3+1;
MQ8[k].bodyY[3] = -2+1;
MQ8[k].bodyY[4] = -1+1;
MQ8[k].bodyY[5] = -0+1;
wrefresh(gameplay);
}
}
}
void removeShip(ship *titanic)
{
int i;
for ( i = 0 ; i<4 ; i++)
{
mvwprintw(gameplay, titanic->bodyY[i], titanic->bodyX[i],"%s", titanic->lastBody[i]);
}
titanic->bodyY[0]=-10;
titanic->bodyY[1]=-9;
titanic->bodyY[2]=-8;
titanic->bodyY[3]=-7;
wrefresh(gameplay);
}
void PlaneCrashCheck(ship titanic[], plane *f35 , player *guest , helicopter MQ8[] )
{
int k, p ;
for( k = 0 ; k<4 ; k++)
for( p = 0 ; p < 7 ; p++)
{
if ((f35->bodyY[0] == titanic[k].bodyY[3] && f35->bodyX[0] == titanic[k].bodyX[3]+p)){
f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);
}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1] == titanic[k].bodyX[3]+p)){
removeShip(&titanic[k]);
PlaneHitSound();
f35->life--;
}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1]+1 == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1]+2== titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1]+4 == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1]+5 == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[1] == titanic[k].bodyY[3] && f35->bodyX[1]+6 == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[2] == titanic[k].bodyY[3] && f35->bodyX[2] == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
else if ((f35->bodyY[2] == titanic[k].bodyY[3] && f35->bodyX[2]+8 == titanic[k].bodyX[3]+p))
{f35->life--;
PlaneHitSound();
removeShip(&titanic[k]);}
UpdateDetails( *guest , *f35 );
wrefresh(detail);
if (f35->life == 0 ) Crashed(&(*guest) , &(*f35));
}
}
void FuelCheck(plane *f35, fuel *gasoline)
{
int i, j, p ;
if (gasoline->bodyY[0] >= 58 )
{
gasoline->bodyY[0] =-35;
gasoline->bodyY[1] =-34;
gasoline->bodyX[0] = RandomFunction();
gasoline->bodyX[1] = gasoline->bodyX[0] -1 ;
}
for( i = 0 ; i < 4 ; i++)
{
if ( (gasoline->bodyY[1] == f35->bodyY[0] && gasoline->bodyX[1]+i == f35->bodyX[0]+1 ) || (gasoline->bodyY[1] == f35->bodyY[1] && gasoline->bodyX[1]+i == f35->bodyX[0]+2) )
{
FuelFillSound();
f35->fuel = 100 ;
for(p = 0 ; p < 2 ; p++)
mvwprintw(gameplay, gasoline->bodyY[p], gasoline->bodyX[p], gasoline->lastBody[p]);
gasoline->bodyY[0] =-50;
gasoline->bodyY[1] =-49;
gasoline->bodyX[0] = RandomFunction();
gasoline->bodyX[1] = gasoline->bodyX[0] -1 ;
}
for( j = 0 ; j < 7 ; j++)
{
if (gasoline->bodyY[1] == f35->bodyY[1] && gasoline->bodyX[1]+i == f35->bodyX[1]+j )
{
f35->fuel = 100 ;
for(p = 0 ; p < 2 ; p++)
mvwprintw(gameplay, gasoline->bodyY[p], gasoline->bodyX[p], gasoline->lastBody[p]);
gasoline->bodyY[0] =-50;
gasoline->bodyY[1] =-49;
gasoline->bodyX[0] = RandomFunction();
gasoline->bodyX[1] = gasoline->bodyX[0] -1 ;
}
}
}
}
void MyTimer(int *ds , int *s , int *m , player *guest)
{
init_pair(119 , COLOR_RED, COLOR_YELLOW);
wattron(detail , A_BOLD | COLOR_PAIR(119));
(*ds)++;
if ((*ds)>9)
{
(*ds)=0;
(*s)++;
if ((*s)>59)
{