-
Notifications
You must be signed in to change notification settings - Fork 1
/
AGON.BAK
1705 lines (1460 loc) · 33.5 KB
/
AGON.BAK
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 FILES USED
*********************************************************************/
#include<graphics.h>
#include<fstream.h>
#include<process.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
/*********************************************************************
FUNCTIONS USED
*********************************************************************/
void dice(); //FUNCTION FOR ROLLING THE DICE
void draw(); //FUNCTION TO DRAW THE HEXAGON
void rules(); //FUNCTION TO DISPLAY RULES OF THE GAME
void loadin(); //FUNCTION TO DISPALY LOADING
void credits(); //FUNCTION TO DISPLAY CREDITS
void file_del(); //FUNCTION TO DELETE FILE
void file_list(); //FUNCTION TO SHOW SAVE FILES
void file_save(); //FUNCTION TO SAVE THE GAME
void clr_match(); //FUNCTION TO CHECK FOR SAME CLR
void game_choose(); //FUNCTION TO CHOOSE THE GAME
void modi(int); //FUNCTION FOR POSTION MODIFICATION
void clr_chs(int); //FUNCTION TO CHOOSE COLOUR FOR COINS
void hexagon(int,int); //FUNCTION TO CHANGE THE COORDINATES
void position(int*,int*); //FUNCTION TO PRINT THE POSITIONS
void graphics_screen(); //FUNCTION TO INITALISE GRA[HICS
int moves(); //FUNCTION TO CHECK FOR CORRECT MOVES
int lstrw(); //FUNCTION MOVE TO LAST ROW
int capchk(); //FUNCTION TO CHECK FOR CAPTURE
int game_cho(); //FUNCTION TO CHOOSE THE GAME IN START
int file_read(); //FUNCTION TO READ THE SAVE FILE
int winchk(int); //FUNCTION TO CHECK FOR WIN
int poschag(int); //FUNCTION FOR POISTION CHANGING
/*********************************************************************
GLOBAL VARIABLES
*********************************************************************/
const int plyr[2]={1,2};
char nm[2][30],fl_nm[30],grp[50]="c:\\turboc3\\bgi",ch;
int poly[14],rw1,cl1,rw2,cl2,ply=1,flag,cho,new_gm=0;
int clr1=4,clr2=2,bkclr=8,count=0;
fstream file;
int p1rw[7]={0,0,4,4,8,9,10},p1cl[7]={0,4,0,9,7,0,3};
int p2rw[7]={0,1,2,6,6,10,10},p2cl[7]={2,6,0,0,9,1,5};
/*********************************************************************
Representation of the inital board positions as a variable
*********************************************************************/
int pos[11][11]={
/* 0 */ { 11,0,2,0,1,0, -1,-1,-1,-1,-1},
/* 1 */ { 0,0,0,0,0,0,2, -1,-1,-1,-1},
/* 2 */ { 2,0,0,0,0,0,0,0, -1,-1,-1},
/* 3 */ { 0,0,0,0,0,0,0,0,0, -1,-1},
/* 4 */ { 1,0,0,0,0,0,0,0,0,1, -1},
/* 5 */ { 0,0,0,0,0,0,0,0,0,0,0 },
/* 6 */ { 2,0,0,0,0,0,0,0,0,2, -1},
/* 7 */ { 0,0,0,0,0,0,0,0,0, -1,-1},
/* 8 */ { 0,0,0,0,0,0,0,1, -1,-1,-1},
/* 9 */ { 1,0,0,0,0,0,0, -1,-1,-1,-1},
/* 10*/ { 0,2,0,1,0,22, -1,-1,-1,-1,-1}};
/*********************************************************************
CLASS DECLRATION
*********************************************************************/
class save
{
private:
char nm[2][30];
int count,ply;
int clr1,clr2,bkclr;
int p1rw[7],p1cl[7];
int p2rw[7],p2cl[7];
int pos[11][11];
public:
save(); //constuctor
void copy_to(); //to copy from global to class
void copy_4m(); //to copy from class to global
} s,nw_gme;
/*********************************************************************
CONSTRUCTOR OF CLASS
*********************************************************************/
save::save()
{
int i,j,k=5;
strcpy(nm[0],"Player 1");
strcpy(nm[1],"Player 2");
count=0;
ply=1;
clr1=4;
clr2=2;
bkclr=8;
for(i=0;i<7;i++)
p1rw[i]=p1cl[i]=p2rw[i]=p1cl[i]=0;
p1rw[2]=p1rw[3]=p1cl[1]=4;
p1rw[6]=p2rw[5]=p2rw[6]=10;
p1rw[5]=p1cl[3]=p2cl[4]=9;
p2rw[3]=p2rw[4]=p2cl[1]=6;
p2rw[2]=p2cl[0]=2;
p2rw[1]=p2cl[5]=1;
p1rw[4]=8;
p1cl[4]=7;
p1cl[6]=3;
p2cl[6]=5;
for(i=0;i<11;i++)
for(j=0;j<11;j++)
pos[i][j]=0;
pos[0][0]=11;
pos[10][5]=22;
pos[0][4]=pos[4][0]=pos[4][9]=pos[8][7]=pos[9][0]=pos[10][3]=1;
pos[0][2]=pos[1][6]=pos[2][0]=pos[6][0]=pos[6][9]=pos[10][1]=2;
for(i=0;i<5;i++)
for(j=6+i;j<11;j++)
pos[i][j]=-1;
for(j=10;j>5;j--)
{
for(i=10;i>k;i--)
pos[i][j]=-1;
cout<<endl;
k++;
}
}
/*********************************************************************
CLASS FUNTION COPY_TO
*********************************************************************/
void save::copy_to()
{
int i,j;
strcpy(nm[0],::nm[0]);
strcpy(nm[1],::nm[1]);
count=::count;
ply=::ply;
clr1=::clr1;
clr2=::clr2;
bkclr=::bkclr;
for(i=0;i<7;i++)
{
p1rw[i]=::p1rw[i];
p1cl[i]=::p1cl[i];
p2rw[i]=::p2rw[i];
p2cl[i]=::p2cl[i];
}
for(i=0;i<11;i++)
for(j=0;j<11;j++)
pos[i][j]=::pos[i][j];
}
/*********************************************************************
CLASS FUNTION COPY_4M
*********************************************************************/
void save::copy_4m()
{
int i,j;
strcpy(::nm[0],nm[0]);
strcpy(::nm[1],nm[1]);
::count=count;
::ply=ply;
::clr1=clr1;
::clr2=clr2;
::bkclr=bkclr;
for(i=0;i<7;i++)
{
::p1rw[i]=p1rw[i];
::p1cl[i]=p1cl[i];
::p2rw[i]=p2rw[i];
::p2cl[i]=p2cl[i];
}
for(i=0;i<11;i++)
for(j=0;j<11;j++)
::pos[i][j]=pos[i][j];
}
/*********************************************************************
FUNCTION TO INITALISE GRA[HICS
*********************************************************************/
void graphics_screen()
{
int gd=DETECT,gm,ec;
initgraph(&gd,&gm,grp);
ec=graphresult();
if(ec!=grOk) // an error occurred
{
cout<<"\"Graphics error:\" \n"<<grapherrormsg(ec)<<endl;
cout<<"Enter ur Graphics dir:-\n";
gets(grp);
graphics_screen();
}
}
/*********************************************************************
MAIN FUNCTION
*********************************************************************/
void main()
{
clrscr();
int run=1;
nw_gme.copy_to();
int chk,mov,cap,i,poschg,gm_ch;
char sav;
count=::count;
if(run)
loadin(); //calling of loadin
gm_ch=game_cho(); //calling of game choose
if(gm_ch==1)
goto cont;
else if(gm_ch==-1)
{
if(run)
credits(); //callin of credits
getch();
exit(0);
}
if(run)
{
rules(); //calling of rules function
clrscr();
dice(); //calling of dice function
clr_chs(0); //calling of colour function
clr_chs(1); //calling of colour function
clr_match(); //calling of clr_match
}
else
cout<<"MUKESH"<<endl; //will never get displayed
cont: //Graphics initialisation
graphics_screen();
if(gm_ch==1)
{
cout<<"\nplayer 1's coins are of the colour"<<endl;
setfillstyle(1,clr1);
fillellipse(300,25,10,10);
cout<<"\n\nplayer 2's coins are of the colour"<<endl;
setfillstyle(1,clr2);
fillellipse(300,70,10,10);
getch();
cleardevice();
}
draw(); //calling of draw function
modi(1); //calling of modi function
do
{
gotoxy(1,1);
for(i=0;i<28;++i)
cout<<"\t\t\t\t\t\t "<<endl;
if(count%2==0)
{
gotoxy(1,1);
cout<<"player 1"<<endl;
ply=1;
}
else
{
gotoxy(1,1);
cout<<"player 2"<<endl;
ply=2;
}
top: cout<<"enter r and c to \"move from\""<<endl;
cin>>rw1>>cl1;
//getting inputs of move from inital coordinates
if(pos[rw1][cl1]==0||pos[rw1][cl1]==(-1))
{
cout<<"entered coordinates are wrong"<<endl
<<"enter the coordinates again"<<endl;
goto top;
}
again: cout<<"enter r and c to \"move to\""<<endl;
cin>>rw2>>cl2;
//getting inputs of move to final coordinates
mov=moves(); //calling of moves function
if(mov==0)
{
cout<<"\"illegal move\" you can only move"<<endl
<<"one step at a time"<<endl;
goto again;
}
poschg=poschag(1); //calling of poschag function
if(poschg==1)
{
cout<<"illegal move"<<endl
<<"try again"<<endl;
goto top;
}
cap=capchk(); //calling of capchk function
if(cap==1||cap==3)
{
if(cap==1)
if(ply==2)
ply--;
else
ply++;
cout<<"your \"queen\" has been captured"<<endl
<<"your queen will be moved by"<<endl
<<"your \"opponent\""<<endl;
poschag(0);
}
else if(cap==2||cap==4)
{
if(cap==2)
if(ply==2)
ply--;
else
ply++;
cout<<"your \"guard\" has been captured"<<endl
<<"your guard will be moved "<<endl
<<"by \"you\""<<endl;
poschag(0);
}
chk=winchk(ply); //calling of winchk function
if(chk==1)
{
if(count%2==0)
cout<<nm[0]<<" has WON the game"<<endl;
else
cout<<nm[1]<<" has WON the game"<<endl;
getch();
delay(800);
exit(0);
}
cout<<"do u want to continue ('y')"<<endl;
cin>>ch;
if(ch=='x')
exit(0);
else if(ch=='s')
file_save(); //saving the game
else if(ch!='y'&&ch!='Y')
game_choose(); //main menu calling
count++;
}while(ch=='y'||ch=='Y'||ch=='s'||ch=='S');
getch();
cout<<"MUKESH"<<endl;
}
/*********************************************************************
FUNCTION TO DISPLAY LOADING
*********************************************************************/
void loadin()
{
clrscr();
graphics_screen(); //initialsing graphics
outtextxy(150,325,"please wait while the game is Loading......");
settextstyle(4,0,6);
outtextxy(225,100,"AGON");
bar(45,364,601,386);
setfillstyle(1,0);
bar(46,365,600,385);
gotoxy(7,24);
for(int i=0;i<69;i++)
{
cout<<(char)176;
if(i<32)
delay(500-15*i);
else
delay(50);
}
settextstyle(0,0,1);
outtextxy(200,425,"press any key to continue !!");
getch();
closegraph();
}
/*********************************************************************
FUNCTION TO DISPLAY RULES OF THE GAME
*********************************************************************/
void rules()
{
cout<<endl<<"\t\t\t\t\"RULES\""<<endl<<endl
<<"\tEach player has one Queen and six Guards"<<endl
<<"\twhich are placed on the outer ring of the board"<<endl<<endl
<<"\tThe goal of each player is to put the Queen on the center"<<endl
<<"\tand surround her with her Guards"<<endl<<endl
<<"\tThe first player being selected by the throw of a die"<<endl<<endl
<<"\tPieces can only be moved one cell forwards or sideways"<<endl
<<"\tthey cannot be moved back away from the center of the board"<<endl
<<"\tOnly a Queen may move onto the centre cell"<<endl<<endl
<<"\tIf you try to move your oppnents piece you wil loose your turn"<<endl<<endl
<<"\tIf a Guard is trapped between two opposing pieces,"<<endl
<<"\tthe owner of the captured Guard must move it"<<endl
<<"\tto any cell of his own choosing on the outermost ring"<<endl<<endl
<<"\tIf a Queen is trapped between two opposing pieces"<<endl
<<"\tthe owner of a captured Queen must move it to any cell"<<endl
<<"\tof his opponent's choosing"<<endl;
getch();
delay(800);
cout<<"MUKESH"<<endl;
}
/*********************************************************************
FUNCTION FOR ROLLING THE DICE
*********************************************************************/
void dice()
{
int i,ran[2];
randomize();
cout<<"enter the player 1's name:"<<endl;
gets(nm[0]);
cout<<"enter the player 2's name:"<<endl;
gets(nm[1]);
roll: for(i=0;i<2;++i)
{
cout<<endl<<nm[i]<<endl
<<"the dice is being rolled"<<endl
<<"and the no obtained is"<<endl;
delay(700);
ran[i]=(random(6)+1);
cout<<ran[i]<<endl;
delay(700);
}
if(ran[0]==ran[1])
{
cout<<"both players have got the \"same\""<<endl
<<"number on the dice, so \"rolling again\""<<endl;
delay(700);
goto roll; //to roll dice again
}
if(ran[0]>ran[1])
cout<<endl<<nm[0]<<" wins the \"first chance\""<<endl;
else
cout<<endl<<nm[1]<<" wins the \"first chance\""<<endl;
cout<<endl<<"You are the \"first Player\""<<endl;
getch();
}
/*********************************************************************
FUNCTION TO CHOOSE COLOUR FOR COINS & BOARD
*********************************************************************/
void clr_chs(int bk)
{
int i=0;
char cho='n';
char ch[14][3]={"1","2","3","4","5","6","7","8"
,"9","10","11","12","13","14"};
clrscr();
if(!bk) //coin's colour
{
cout<<"Do you want to choose colours for your coins"<<endl
<<"by Default"<<endl
<<"Player 1 gets \"RED\" coins"<<endl
<<"Player 2 gets \"GREEN\" coins"<<endl
<<"do you want to change ?? (y\\n)"<<endl;
cin>>cho;
}
else //board's colour
{
cout<<"Do you want to choose colours for the board"<<endl
<<"by Default"<<endl
<<"board has \"GRAY\" colour"<<endl
<<"do you want to change ?? (y\\n)"<<endl;
cin>>cho;
}
if(cho!='y')
return;
graphics_screen(); //intialise graphics
if(!bk) //colour of coins
{
cout<<"\t\t Enter the colours you want"
<<"for your coins"<<endl;
}
else //colour of board
{
cout<<"\t\tEnter the board colour you want"<<endl;
}
for(i=0;i<6;i++)
{
outtextxy(88+80*i,185,ch[i]);
outtextxy(88+80*i,285,ch[i+6]);
}
for(i=0;i<6;i++)
{
setcolor(i+1);
setfillstyle(1,i+1);
fillellipse(90+i*80,160,20,20);
}
for(i=8;i<14;i++)
{
setcolor(i+1);
setfillstyle(1,i+1);
fillellipse(90+(i-8)*80,260,20,20);
}
setcolor(15);
setfillstyle(1,15);
fillellipse(90+80*2,360,20,20);
outtextxy(85+80*2,385,ch[12]);
setcolor(15);
setfillstyle(1,16);
fillellipse(90+80*3,360,19,19);
outtextxy(85+80*3,385,ch[13]);
enter: gotoxy(1,5);
if(!bk) //colour of coins
{
cout<<nm[0]<<"-choose the colour :";
cin>>clr1;
cout<<nm[1]<<"-choose the colour :";
cin>>clr2;
if((clr1==clr2)||(clr1>14||clr2>14))
{
gotoxy(1,5);
for(i=0;i<4;i++)
cout<<"\t\t\t\t\t\t\t\t"<<endl;
gotoxy(1,4);
cout<<"enter again as chooses are wrong or same"<<endl;
goto enter;
}
if(clr1>6)
clr1+=2;
if(clr2>6)
clr2+=2;
}
else //colour of board
{
cout<<"enter the colour"<<endl;
cin>>bkclr;
if(bkclr>14)
{
gotoxy(1,5);
for(i=0;i<4;i++)
cout<<"\t\t\t\t\t\t\t\t"<<endl;
gotoxy(1,4);
cout<<"enter again as choose is wrong"<<endl;
goto enter;
}
if(bkclr>6)
bkclr+=2;
}
cout<<"MUKESH"<<endl;
closegraph();
}
/*********************************************************************
FUNCTION TO CHECK FOR SAME COLOUR OF COINS & BOARD
*********************************************************************/
void clr_match()
{
if((clr1!=bkclr)&&(clr2!=bkclr))
return;
cout<<"colour of the coin and board are same"<<endl
<<"enter them again and make sure dey are diff"<<endl;
getch();
clr_chs(0); //chosing colour of coins
clr_chs(1); //chosing colour of board
clr_match(); //colour match
}
/*********************************************************************
FUNCTION TO CHOOSE THE GAME IN START
*********************************************************************/
int game_cho()
{
int fr;
char ch;
gm: cho=0;
cout<<"Do you you want to :-"<<endl
<<"1.Play the new game"<<endl
<<"2.Play the saved game "<<endl
<<"3.Any other key to exit"<<endl
<<"enter ur choice:";
cin>>cho;
if(cho==1)
{
nw_gm: clrscr();
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t";
cout<<" NEW GAME STARTED";
return(0);
}
else if(cho==2)
{
fr=file_read();
if(fr==0)
goto nw_gm;
else
return(1);
}
else
{
cout<<"are u sure u wanna exit this amazing game??"<<endl;
cin>>ch;
if(ch!='y')
{
clrscr();
goto gm;
}
}
return(-1);
}
/*********************************************************************
FUNCTION TO CHOOSE THE GAME
*********************************************************************/
void game_choose()
{
int fr;
char ch1,ch12='y',ch123,sav,cho12;
gm: cho=0;
if(ch12!='y')
cho=50;
closegraph();
cout<<"Do you you want to :-"<<endl
<<"1.Play the new game"<<endl
<<"2.Continue current game"<<endl
<<"3.Save the current game"<<endl
<<"4.See the saved games"<<endl
<<"5.Play the saved game "<<endl
<<"6.Delete a exirsting file"<<endl
<<"7.Read the instructions"<<endl
<<"8.Choose ur coin colour"<<endl
<<"9.Choose board colour"<<endl
<<"\nAny other key to exit"<<endl
<<"\nenter ur choice:";
cin>>cho12;
cho=(char)cho12;
if(cho==49)
{
cout<<"do u wanna exit this game and start a new one"<<endl;
cin>>ch1;
if(ch1=='y')
{
cout<<"do u wanna save the currnet game ??"<<endl;
cin>>ch123;
if(ch123=='y')
file_save();
else
cout<<"the current game is not saved"<<endl;
nw_gm: clrscr();
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t";
cout<<" \"NEW GAME STARTED\"";
nw_gme.copy_4m();
new_gm=1;
count=-1;
ch='y';
getch();
}
else
goto gm;
}
else if(cho==50)
{
ch='y';
}
else if(cho==51)
{
file_save();
ch='y';
}
else if(cho==52)
{
file_list();
getch();
ch='y';
}
else if(cho==53)
{
fr=file_read();
if(fr==0)
goto nw_gm;
else
{
count--;
ch='y';
}
}
else if(cho==54)
{
file_del();
clrscr();
ch='y';
}
else if(cho==55)
{
rules();
ch='y';
}
else if(cho==56)
{
clr1=4;
clr2=2;
clr_chs(0);
clr_match();
graphics_screen();
draw(); //calling of draw function
modi(1); //calling of modi function
ch='y';
}
else if(cho==57)
{
bkclr=8;
clr_chs(1);
clr_match();
graphics_screen();
draw(); //calling of draw function
modi(1); //calling of modi function
ch='y';
}
else
{
cout<<"are u sure u wanna exit this amazing game??"<<endl;
cin>>ch12;
if(ch12!='y')
{
ch='y';
graphics_screen();
draw(); //calling of draw function
modi(1); //calling of modi function
return;
}
cout<<"do u want to save be4 exiting ??"<<endl;
cin>>sav;
if(sav=='y')
file_save();
getch();
credits();
getch();
exit(0);
}
graphics_screen();
draw(); //calling of draw function
modi(1); //calling of modi function
if(new_gm==1)
{
fillellipse(450,65,5,5);
fillellipse(430,145,5,5);
}
}
/*********************************************************************
FUNCTION TO SHOW SAVE FILES
*********************************************************************/
void file_list()
{
char file_nm[30];
file.open("txtfl_MK.txt",ios::in|ios::out);
if(!file)
{
cout<<"No Saved files found"<<endl
<<"Press any key to continue"<<endl;
getch();
return;
}
cout<<"the existing save files are:"<<endl;
while(!file.eof())
{
file.getline(file_nm,30,'\n');
cout<<file_nm<<endl;
}
file.close();
}
/*********************************************************************
FUNCTION TO SAVE THE GAME
*********************************************************************/
void file_save()
{
char names[30],ch;
int f_flag=0,rep=0;
file_list();
cout<<"enter file name to save as"<<endl;
gets(fl_nm);
strcpy(names,fl_nm);
strcat(fl_nm,".dat");
ofstream tochk(fl_nm,ios::nocreate);
if(tochk)
{
cout<<"file already exists"<<endl
<<"do u want to replace old file"<<endl;
cin>>ch;
if(ch=='y')
{
f_flag=1;
rep=1;
}
}
else
f_flag=1;
tochk.close();
if(!f_flag)
return;
count++;
s.copy_to();
count--;
file.open(fl_nm,ios::out|ios::binary);
if(!file)
{
cout<<"file not opened save"<<endl;
flag=0;
getch();
return;
}
file.write((char*)&s,sizeof(s));
file.close();
if(!rep)
{
file.open("txtfl_MK.txt",ios::app);
if(!file)
{
cout<<"text file not opened"<<endl;
getch();
return;
}
if(file)
{
file<<names<<"\n";
cout<<"save successful"<<endl;
}
file.close();
}
getch();
return;
}
/*********************************************************************
FUNCTION TO READ FROM SAVE FILE
*********************************************************************/
int file_read()
{
file_list();
cout<<"enter file name to read from"<<endl;
gets(fl_nm);
strcat(fl_nm,".dat");
file.open(fl_nm,ios::in|ios::binary);
if(!file)
{
cout<<"file does not exist read"<<endl;
getch();
return(0);
}
file.read((char*)&s,sizeof(s));
s.copy_4m();
cout<<"data retreaved successfully"<<endl;
file.close();
getch();
return(1);
}
/*********************************************************************
FUNCTION TO DELETE A FILE
*********************************************************************/
void file_del()
{
char name[30],buff[30];
file_list();
cout<<"enter the file name which u wanna delete"<<endl;
gets(name);
strcpy(fl_nm,name);
strcat(name,".dat");
file.open(name,ios::in);
if(!file)
{
cout<<"file does not exist delete"<<endl;
getch();
return;
}
file.close();
ofstream temp("temp.txt",ios::out);
if(!temp)
{
cout<<"temp file does not exist"<<endl;
getch();