-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
2810 lines (2548 loc) · 71.2 KB
/
game.cpp
File metadata and controls
2810 lines (2548 loc) · 71.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
/*************************************************************************************************
HEADER SECTION
*************************************************************************************************/
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
/*************************************************************************************************
GLOBAL VARIABLE DECLARATION
*************************************************************************************************/
union REGS i, o;
int playertype=0, gamemode=0;
int tpos[36][2], tn=99, ttn; //tn=tiles no., ttn=total tiles no of the board
int tstatus[36][3]; //[][0] for no of imagefile, [][1] for loaded, [][2] for matched
int cli=0; // currently loaded image. cannot be more than 2
int p1p=0; //player1 point
char username[21];
int m=0, mm=0, bonus=0; //m=matches, mm=misses
int playtime; //time used to complete the game
//structure declaration for reading score data from file
struct score{ char name[21]; int point; };
//relative path of image file used in game
char imagefile[18][100] =
{
"Graphics\\Sun.txt", "Graphics\\Flag.txt",
"Graphics\\Bomb.txt", "Graphics\\Busy.txt",
"Graphics\\Yin.txt", "Graphics\\Comp.txt",
"Graphics\\Cross.txt", "Graphics\\Fist.txt",
"Graphics\\Guitar.txt", "Graphics\\Heart.txt",
"Graphics\\Trash.txt", "Graphics\\Tick.txt",
"Graphics\\Diamond.txt", "Graphics\\Moon01.txt",
"Graphics\\Skull_02.txt", "Graphics\\OneEye.txt",
"Graphics\\Pen.txt", "Graphics\\Seagate.txt",
};
//(done)
#define INTR 0x09
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
void int_open(void);
void int_close(void);
void anitext(int x, int y, char text[500]);
void interrupt (*oldhandler) (__CPPARGS);
void interrupt handler(__CPPARGS);
void interrupt handler(__CPPARGS)
{
int n;
disable();
n=inport(0x60);
if((n&0x00ff)==0x0041)
exit(1);
enable();
oldhandler();
}
void pclose(void)
{
closegraph();
enable();
oldhandler();
int_close();
delay(2000);
anitext(11, 10, "Thank you for using this software. Hope you have enjoyed it.");
delay(500);
}
#pragma exit pclose
//Prototyping of mouse functions
int initmouse(void);
void getmousepos(int *button, int *x, int *y);
void showmouseptr(void);
void hidemouseptr(void);
//Prototyping of functions
void round_tiles(int x, int y);
void board(int type);
void loadimage(void);
void set_tn(void);
void inittiles(int tno);
void round_rectangle(int x, int y, int w, int h, int round);
void menu_button(int x, int y, int w, int h);
void image(int x, int y, char filename[100]);
void credit_title(int y, char text[100]);
void credit_text(int y, char text[100]);
void pturn(int turn);
int quit(void);
void music(int type);
void instext(int i);
void score_read(int mode, score tempscore[10])
{
int i;
char temp[4]; //for atoi function
FILE *f;
if(mode==1)
f = fopen("Easy.scf", "r");
else if(mode==2)
f = fopen("Normal.scf", "r");
else if(mode==3)
f = fopen("Hard.scf", "r");
for (i=0; i<10; i++)
{
fgets(temp, 2, f);
fgets(tempscore[i].name, 21, f);
fgets(temp, 4, f);
tempscore[i].point = atoi(temp);
}
fclose(f);
}
void score_write(int mode, score tempscore[10])
{
int i;
FILE *f;
if(mode==1)
f = fopen("Easy.scf", "w");
else if(mode==2)
f = fopen("Normal.scf", "w");
else if(mode==3)
f = fopen("Hard.scf", "w");
fprintf(f, "\n");
for (i=0; i<10; i++)
{
fprintf(f, "%s", tempscore[i].name);
fprintf(f, "%3d", tempscore[i].point);
fprintf(f, "\n");
}
fclose(f);
}
int score_update(void)
{
int i, j; //for looping
int t1point, t2point;
char t1name[21], t2name[21];
score temp[10]; //structure
score_read(gamemode, temp);
if (p1p>temp[9].point)
{
//drawing graphics for taking username as input
cleardevice();
hidemouseptr();
//draw background
setbkcolor(LIGHTBLUE);
setfillstyle(11, BLUE);
bar(0, 0, getmaxx(), getmaxy());
setfillstyle(1, BLUE);
bar(159, 139, 479, 339);
setcolor(WHITE);
rectangle(159+7, 139+7, 479-7, 339-7);
rectangle(159+9, 139+9, 479-9, 339-9);
int txtw; //for textwidth() function
settextstyle(4, 0, 0);
txtw = textwidth("Congratulations");
outtextxy(159+(320-txtw)/2, 150, "Congratulations");
settextstyle(2, 0, 6);
outtextxy(180, 190, "You have the highest score.");
outtextxy(180, 210, "Please enter your name.");
settextstyle(2, 0, 6);
outtextxy(180, 240, "Your name here:");
username[0] = '\0';
//textbox control
setfillstyle(1, LIGHTBLUE);
bar(180, 260, 180+220, 260+20);
rectangle(180, 260, 180+220, 260+20);
outtextxy(190, 260, strcat(username, "_"));
//draws menu button with OK text
menu_button(270, 290, 100, 25);
setcolor(RED);
settextstyle(8, 0, 1);
txtw = textwidth("OK");
outtextxy(270+(100-txtw)/2, 287, "OK");
showmouseptr();
int mb, mx, my, cc=0; //cc = charcounter
char ch;
music(2);
while(1)
{
getmousepos(&mb, &mx, &my);
if((mb &1)==1)
{
if (mx>=270 && mx<=270+100 && my>=290 && my<=290+25 && cc>0)
{ music(4); break; }
}
if (kbhit())
{
ch = getch();
if (ch>31 && ch<127 && cc<20)
{
music(4);
hidemouseptr();
username[cc] = ch;
cc++;
//textbox control
setcolor(WHITE);
setfillstyle(1, LIGHTBLUE);
bar(180, 260, 180+220, 260+20);
rectangle(180, 260, 180+220, 260+20);
settextstyle(2, 0, 6);
outtextxy(190, 260, strcat(username, "_"));
showmouseptr();
}
else if (ch==8 && cc!=0)
{
music(4);
hidemouseptr();
username[cc-1] = '\0';
cc--;
//textbox control
setcolor(WHITE);
setfillstyle(1, LIGHTBLUE);
bar(180, 260, 180+220, 260+20);
rectangle(180, 260, 180+220, 260+20);
settextstyle(2, 0, 6);
outtextxy(190, 260, strcat(username, "_"));
showmouseptr();
}
else if (ch==13 && cc>0)
{ music(4); break; }
}
}
//this code fills the username arrey with space
if (cc<20)
{
for(i=cc; i<20; i++)
username[i] = ' ';
}
username[20] = '\0';
for(i=0; i<10; i++)
{
if(p1p>temp[i].point)
{
//code for update the structure
int flag1 = 1;
for (j=i; j<10; j++)
{
if(!flag1)
{
//saving ith data to temp2
strcpy(t2name, temp[j].name);
t2point = temp[j].point;
//Overwriting ith data with (i-1)th data
strcpy(temp[j].name, t1name);
temp[j].point = t1point;
strcpy(t1name, t2name);
t1point = t2point;
}
if(flag1)
{
strcpy(t1name, temp[j].name);
t1point = temp[j].point;
strcpy(temp[j].name, username);
temp[j].point = p1p;
flag1 = 0;
}
}
break;
}
}
score_write(gamemode, temp);
return 3;
}
else
return 0;
}
void screen0_fn1(void);
void screen1_fn1(void);
void screen3_fn1(void);
void screen3_fn2(int button);
void screen5_fn1(void);
void screen6_fn1(void);
void screen6_fn2(void);
int sp_game(void)
{
cleardevice();
hidemouseptr();
setbkcolor(LIGHTBLUE);
setfillstyle(11, BLUE);
bar(0, 0, getmaxx(), getmaxy());
board(gamemode); //int value depends on the gamemode variable
inittiles(gamemode);
//draw the curret game status
round_rectangle(20, 190, 110, 100, 10);
setfillstyle(1, LIGHTBLUE);
floodfill(20, 190, WHITE);
int txtwidth;
char ch[10], ch1;
setfillstyle(1, RED);
bar(20, 190, 130, 220);
settextstyle(8, 0, 1);
txtwidth = textwidth("Player 1");
outtextxy(20+(110-txtwidth)/2, 190, "Player 1");
settextstyle(2, 0, 0);
outtextxy( 30, 230, "Matches");
outtextxy(110, 230, itoa(0, ch, 10));
outtextxy( 30, 245, "Misses");
outtextxy(110, 245, itoa(0, ch, 10));
outtextxy( 30, 260, "Bonus");
outtextxy(110, 260, itoa(0, ch, 10));
outtextxy( 30, 275, "Time (sec)");
outtextxy(110, 275, itoa(0, ch, 10));
showmouseptr();
int mb, mx, my;
int mcount=0, bcount=0; //mcount=match tiles count, bcount=bonus count
int pt=98, ct=99; //previous tile and current tile
int i, q;
p1p=0, playtime=0; //player1 point
m=0, mm=0; //m=matches, mm=misses
bonus=0, bcount=0;
tn=99;
long int s_time=0, e_time=0, te_time=0, ts_time=0;
int tpt; //tmp play time
randomize();
while(1)
{
getmousepos(&mb, &mx, &my);
ts_time = time(NULL);
if ((mb &1)==1)
{
if (tn==99)
s_time = time(NULL);
set_tn();
if (tn!=88) //no tiles clicked
{
pt = ct;
ct = tn;
}
loadimage();
if (cli==2)
{
cli=0;
//mis matched
if (tstatus[ct][0]!=tstatus[pt][0])
{
hidemouseptr();
delay(1000);
setfillstyle(1, BLUE);
bar(tpos[pt][0], tpos[pt][1], tpos[pt][0]+30, tpos[pt][1]+40);
bar(tpos[ct][0], tpos[ct][1], tpos[ct][0]+30, tpos[ct][1]+40);
round_tiles(tpos[pt][0], tpos[pt][1]);
round_tiles(tpos[ct][0], tpos[ct][1]);
tstatus[ct][1] = 0;
tstatus[pt][1] = 0;
showmouseptr();
mm = mm+1;
bcount = 0;
//update info bar for mm
setfillstyle(1, LIGHTBLUE);
settextstyle(2, 0, 0);
bar(110, 245, 130, 260);
outtextxy(110, 245, itoa(mm, ch, 10));
}
//matched
else if (tstatus[ct][0]==tstatus[pt][0])
{
hidemouseptr();
music(1);
delay(300);
setfillstyle(1, BLUE);
bar(tpos[pt][0], tpos[pt][1], tpos[pt][0]+30, tpos[pt][1]+40);
bar(tpos[ct][0], tpos[ct][1], tpos[ct][0]+30, tpos[ct][1]+40);
tstatus[ct][2] = 1;
tstatus[pt][2] = 1;
mcount = mcount+2;
showmouseptr();
m = m+1;
bcount = bcount+1;
if (bcount==3)
{
bonus = bonus+1;
bcount = 0;
//update info bar for bonus
setfillstyle(1, LIGHTBLUE);
settextstyle(2, 0, 0);
bar(110, 260, 130, 275);
outtextxy(110, 260, itoa(bonus, ch, 10));
}
//update info bar for m
setfillstyle(1, LIGHTBLUE);
settextstyle(2, 0, 0);
bar(110, 230, 130, 245);
outtextxy(110, 230, itoa(m, ch, 10));
}
}
if (mcount==ttn)
{
e_time = time(NULL);
playtime = e_time-s_time;
return 9; //shows the scores
//code for plays end
//score will come to show
}
}
te_time = time(NULL);
if(tn!=99 && tn!=88)
{
tpt = te_time-s_time;
if((te_time-ts_time)>=1)
{
setfillstyle(1, LIGHTBLUE);
settextstyle(2, 0, 0);
bar(110, 275, 130, 290);
outtextxy(110, 275, itoa(tpt, ch, 10));
}
}
if (kbhit())
{
ch1 = getch();
if (ch1==27)
{
q = quit();
if (q==1)
{
cli = 0;
return 0;
}
else if (q==2)
{
//goto previous state
hidemouseptr();
setfillstyle(11, BLUE);
bar(150, 0, 490, getmaxy());
board(gamemode);
for (i=0; i<ttn; i++)
{
if (tstatus[i][2]==1)
{
setfillstyle(1, BLUE);
bar(tpos[i][0], tpos[i][1], tpos[i][0]+30, tpos[i][1]+40);
}
if (tstatus[i][1]==1 && tstatus[i][2]==0)
image(tpos[i][0], tpos[i][1], imagefile[tstatus[i][0]]);
}
showmouseptr();
}
}
}
}
}
int dp_game(void)
{
cleardevice();
hidemouseptr();
setbkcolor(LIGHTBLUE);
setfillstyle(11, BLUE);
bar(0, 0, getmaxx(), getmaxy());
board(gamemode); //int value depends on the gamemode variable
inittiles(gamemode);
//draw the total match of player1
round_rectangle(20, 190, 110, 100, 10);
setfillstyle(1, LIGHTBLUE);
floodfill(20, 190, WHITE);
//draw the total match of player2
round_rectangle(510, 190, 110, 100, 10);
setfillstyle(1, LIGHTBLUE);
floodfill(510, 190, WHITE);
int txtwidth, txth;
char ch[10], ch1; //convert int var. to string
int p1m=0, p2m=0; //player 1 match, player2 match
int playerturn=1;
int mb, mx, my;
int mcount=0; //mcount=match tiles count, bcount=bonus count
int pt=98, ct=99; //previous tile and current tile
int q, i;
tn = 99;
//drawing player1 and player2
pturn(playerturn);
//no of mathing tiles for both player
settextstyle(10, 0, 0);
txtwidth = textwidth(itoa(p1m, ch, 10));
outtextxy(20+(110-txtwidth)/2, 220, itoa(p1m, ch, 10));
txtwidth = textwidth(itoa(p2m, ch, 10));
outtextxy(510+(110-txtwidth)/2, 220, itoa(p2m, ch, 10));
showmouseptr();
while(1)
{
getmousepos(&mb, &mx, &my);
if ((mb &1)==1)
{
set_tn();
if (tn!=88)
{
pt = ct;
ct = tn;
}
loadimage();
if (cli==2)
{
cli=0;
//mis matched
if (tstatus[ct][0]!=tstatus[pt][0])
{
hidemouseptr();
delay(1000);
setfillstyle(1, BLUE);
bar(tpos[pt][0], tpos[pt][1], tpos[pt][0]+30, tpos[pt][1]+40);
bar(tpos[ct][0], tpos[ct][1], tpos[ct][0]+30, tpos[ct][1]+40);
round_tiles(tpos[pt][0], tpos[pt][1]);
round_tiles(tpos[ct][0], tpos[ct][1]);
tstatus[ct][1] = 0;
tstatus[pt][1] = 0;
if (playerturn==1)
playerturn = 2;
else if (playerturn==2)
playerturn = 1;
pturn(playerturn);
showmouseptr();
}
//matched
else if (tstatus[ct][0]==tstatus[pt][0])
{
hidemouseptr();
music(1);
delay(300);
setfillstyle(1, BLUE);
bar(tpos[pt][0], tpos[pt][1], tpos[pt][0]+30, tpos[pt][1]+40);
bar(tpos[ct][0], tpos[ct][1], tpos[ct][0]+30, tpos[ct][1]+40);
tstatus[ct][2] = 1;
tstatus[pt][2] = 1;
mcount = mcount+2;
if(playerturn==1)
{
p1m++;
//update the value of p1m
setfillstyle(1, LIGHTBLUE);
bar(20, 221, 130, 290);
settextstyle(10, 0, 0);
txtwidth = textwidth(itoa(p1m, ch, 10));
outtextxy(20+(110-txtwidth)/2, 220, itoa(p1m, ch, 10));
}
else if(playerturn==2)
{
p2m++;
//update the value of p2m
setfillstyle(1, LIGHTBLUE);
bar(510, 221, 620, 290);
settextstyle(10, 0, 0);
txtwidth = textwidth(itoa(p2m, ch, 10));
outtextxy(510+(110-txtwidth)/2, 220, itoa(p2m, ch, 10));
}
showmouseptr();
}
}
}
if (p1m==20 || p2m==20)
{
//declare which player has won
setfillstyle(1, BLUE);
if (gamemode==1)
bar(209, 109, 429, 369);
else if (gamemode==2)
bar(159, 109, 479, 369);
else if (gamemode==3)
bar(159, 49, 479, 429);
settextstyle(1, 0, 0);
if (p1m>p2m)
{
//p1 wins
txtwidth = textwidth("Player 1 wins!");
txth = textheight("Player 1 wins!");
while(1)
{
for (i=2; i<16; i++)
{
setcolor(i);
outtextxy((getmaxx()-txtwidth)/2, (getmaxy()-txth)/2, "Player 1 wins!");
sound(i*100);
delay(200);
}
if(kbhit())
{
nosound();
return 0;
}
}
}
else if (p2m>p1m)
{
//p2 wins
txtwidth = textwidth("Player 2 wins!");
txth = textheight("Player 2 wins!");
while(1)
{
for (i=2; i<16; i++)
{
setcolor(i);
outtextxy((getmaxx()-txtwidth)/2, (getmaxy()-txth)/2, "Player 2 wins!");
sound(i*100);
delay(200);
}
if(kbhit())
{
nosound();
return 0;
}
}
}
}
if (mcount==ttn)
{
hidemouseptr();
board(gamemode);
inittiles(gamemode);
mcount = 0;
showmouseptr();
}
if (kbhit())
{
ch1 = getch();
if (ch1==27)
{
q = quit();
if (q==1)
{
cli = 0;
return 0;
}
else if (q==2)
{
//goto previous state
hidemouseptr();
setfillstyle(11, BLUE);
bar(150, 0, 490, getmaxy());
board(gamemode);
for (i=0; i<ttn; i++)
{
if (tstatus[i][2]==1)
{
setfillstyle(1, BLUE);
bar(tpos[i][0], tpos[i][1], tpos[i][0]+30, tpos[i][1]+40);
}
if (tstatus[i][1]==1 && tstatus[i][2]==0)
image(tpos[i][0], tpos[i][1], imagefile[tstatus[i][0]]);
}
showmouseptr();
}
}
}
}
}
int screen0(void)
{
cleardevice();
hidemouseptr();
setbkcolor(LIGHTBLUE);
setfillstyle(11, BLUE);
bar(0, 0, getmaxx(), getmaxy());
//Draws the logo of the game
image(0, 0, "Graphics\\Title.txt");
settextstyle(2, 0, 0);
setcolor(LIGHTGRAY);
outtextxy(110, 6, "version 1.4");
round_rectangle(getmaxx()/2-110, 80, 220, 15, 10);
round_rectangle(getmaxx()/2-110, 125, 220, 200, 10);
int txtwidth; //determines width of button text for allignment
int mb, mx, my; //var for detect mouse position
settextstyle(4, 0, 0);
txtwidth = textwidth("Game Menu");
outtextxy(getmaxx()/2-(txtwidth/2), 65, "Game Menu");
//draws menu buttons for 5 menus
menu_button((getmaxx()/2)-100, 130, 200, 30);
menu_button((getmaxx()/2)-100, 170, 200, 30);
menu_button((getmaxx()/2)-100, 210, 200, 30);
menu_button((getmaxx()/2)-100, 250, 200, 30);
menu_button((getmaxx()/2)-100, 290, 200, 30);
settextstyle(1, 0, 2);
setcolor(BLUE);
txtwidth = textwidth("New Game");
outtextxy(getmaxx()/2-(txtwidth/2), 130, "New Game");
txtwidth = textwidth("Instructions");
outtextxy(getmaxx()/2-(txtwidth/2), 170, "Instructions");
txtwidth = textwidth("High Scores");
outtextxy(getmaxx()/2-(txtwidth/2), 210, "High Scores");
txtwidth = textwidth("Credit");
outtextxy(getmaxx()/2-(txtwidth/2), 250, "Credit");
txtwidth = textwidth("Exit");
outtextxy(getmaxx()/2-(txtwidth/2), 290, "Exit");
int button=1, flag=1; //tell which button currently selected
char ch; //tracees the value of key hit
showmouseptr();
delay(200);
while(1)
{
if(flag)
{
if (button==1)
{
delay(50);
screen0_fn1();
setcolor(RED);
txtwidth = textwidth("New Game");
outtextxy(getmaxx()/2-(txtwidth/2), 130, "New Game");
}
else if (button==2)
{
delay(50);
screen0_fn1();
setcolor(RED);
txtwidth = textwidth("Instructions");
outtextxy(getmaxx()/2-(txtwidth/2), 170, "Instructions");
}
else if (button==3)
{
delay(50);
screen0_fn1();
setcolor(RED);
txtwidth = textwidth("High Scores");
outtextxy(getmaxx()/2-(txtwidth/2), 210, "High Scores");
}
else if (button==4)
{
delay(50);
screen0_fn1();
setcolor(RED);
txtwidth = textwidth("Credit");
outtextxy(getmaxx()/2-(txtwidth/2), 250, "Credit");
}
else if (button==5)
{
delay(50);
screen0_fn1();
setcolor(RED);
txtwidth = textwidth("Exit");
outtextxy(getmaxx()/2-(txtwidth/2), 290, "Exit");
}
flag = 0;
}
getmousepos(&mb, &mx, &my);
if ((mb &0)==0)
{
if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=130 && my<=130+30)
{ button = 1; flag = 1; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=170 && my<=170+30)
{ button = 2; flag = 1; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=210 && my<=210+30)
{ button = 3; flag = 1; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=250 && my<=250+30)
{ button = 4; flag = 1; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=290 && my<=290+30)
{ button = 5; flag = 1; }
}
if (kbhit())
{
ch = getch();
if (ch==72 && button>=1)
{
button--;
if (button==0)
button = 5;
flag = 1;
}
else if (ch==80 && button<=5)
{
button++;
if (button==6)
button = 1;
flag = 1;
}
else if (ch=='N' || ch=='n')
{ button = 1; flag = 1; }
else if (ch=='I' || ch=='i')
{ button = 2; flag = 1; }
else if (ch=='S' || ch=='s')
{ button = 3; flag = 1; }
else if (ch=='C' || ch=='c')
{ button = 4; flag = 1; }
else if (ch=='E' || ch=='e')
{ button = 5; flag = 1; }
else if (ch==13)
{
if (button==1)
{ music(4); return 1; }
else if (button==2)
{ music(4); return 2; }
else if (button==3)
{ music(4); return 3; }
else if (button==4)
{ music(4); return 4; }
else if (button==5)
{ music(4); return 5; }
}
else if (ch==27)
{ music(4); return 5; }
}
if ((mb &1)==1)
{
if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=130 && my<=130+30)
{ music(4); return 1; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=170 && my<=170+30)
{ music(4); return 2; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=210 && my<=210+30)
{ music(4); return 3; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=250 && my<=250+30)
{ music(4); return 4; }
else if (mx>=getmaxx()/2-100 && mx<=getmaxx()/2-100+200 && my>=290 && my<=290+30)
{ music(4); return 5; }
}
}
}
int screen1(void)
{
//clearing screen and drawing background
cleardevice();
hidemouseptr();
setbkcolor(LIGHTBLUE);
setfillstyle(11, BLUE);
bar(0, 0, getmaxx(), getmaxy());
//Draws the logo of the game
image(0, 0, "Graphics\\Title.txt");
settextstyle(2, 0, 0);
setcolor(LIGHTGRAY);
outtextxy(110, 6, "version 1.4");
round_rectangle(getmaxx()/2-110, 80, 220, 15, 10);
round_rectangle(getmaxx()/2-110, 125, 220, 160, 10);
int txtwidth; //determines width of button text for allignment
int mb, mx, my; //var for detect mouse position
//draw menu name
settextstyle(4, 0, 0);
txtwidth = textwidth("Player Type");
outtextxy(getmaxx()/2-(txtwidth/2), 65, "Player Type");
//draws single player
setcolor(LIGHTGRAY);
rectangle(getmaxx()/2-100, 140, getmaxx()/2+100, 140+34);
setfillstyle(1, BLUE);
floodfill(getmaxx()/2-100+2, 140+2, LIGHTGRAY);
image(getmaxx()/2-100+10, 140+1, "Graphics\\1 Player.txt");
settextstyle(1, 0, 2);
setcolor(WHITE);
outtextxy(getmaxx()/2-100+15+32, 143, "Single Player");
//draw double player
setcolor(LIGHTGRAY);
rectangle(getmaxx()/2-100, 190, getmaxx()/2+100, 190+34);
setfillstyle(1, BLUE);
floodfill(getmaxx()/2-100+2, 190+2, LIGHTGRAY);
image(getmaxx()/2-100+10, 190+1, "Graphics\\2 Player.txt");
settextstyle(1, 0, 2);
setcolor(WHITE);
outtextxy(getmaxx()/2-100+15+32, 193, "Double Player");
//draw OK and Cancel button
menu_button((getmaxx()/2)-100, 240, 90, 30);
txtwidth = textwidth("OK");
setcolor(BLUE);
outtextxy(((getmaxx()/2)-100)+(90-txtwidth)/2, 241, "OK");
menu_button((getmaxx()/2)+10, 240, 90, 30);
txtwidth = textwidth("Cancel");
setcolor(BLUE);
outtextxy(((getmaxx()/2)+10)+(90-txtwidth)/2, 241, "Cancel");
if (playertype==1)
{
setfillstyle(1, LIGHTBLUE);
floodfill(219+2, 140+2, LIGHTGRAY);
image(219+10, 140+1, "Graphics\\1 Player.txt");
settextstyle(1, 0, 2);
setcolor(WHITE);
outtextxy(219+15+32, 143, "Single Player");
}
else if (playertype==2)
{
setfillstyle(1, LIGHTBLUE);
floodfill(219+2, 190+2, LIGHTGRAY);
image(219+10, 190+1, "Graphics\\2 Player.txt");
settextstyle(1, 0, 2);
setcolor(WHITE);
outtextxy(219+15+32, 193, "Double Player");
}
int button=1; //tell which button currently selected
char ch; //tracees the value of key hit
showmouseptr();
delay(200);
while(1)
{
if (button==1)
{
setcolor(RED);
txtwidth = textwidth("OK");
outtextxy(((getmaxx()/2)-100)+(90-txtwidth)/2, 241, "OK");
delay(50);
screen1_fn1();
}
else if (button==2)
{
setcolor(RED);
txtwidth = textwidth("Cancel");
outtextxy(((getmaxx()/2)+10)+(90-txtwidth)/2, 241, "Cancel");
delay(50);
screen1_fn1();
}
getmousepos(&mb, &mx, &my);
if ((mb &0)==0)
{
if (mx>=219 && mx<=219+90 && my>=240 && my<=240+30)
button = 1;
else if (mx>=329 && mx<=329+90 && my>=240 && my<=240+30)
button = 2;
}
if (kbhit())
{
ch = getch();
if (ch=='O' || ch=='o')
button = 1;
else if (ch=='C' || ch=='c')
button = 2;
else if (ch==13)
{
if (button==1 && playertype!=0)
{ music(4); return 6; }//goto mode select screen
else if (button==2)
{ music(4); return 0; }//goto main menu
}
else if (ch=='S' || ch=='s')
{
playertype = 1;