-
Notifications
You must be signed in to change notification settings - Fork 0
/
mazeGame.c
902 lines (769 loc) · 27.5 KB
/
mazeGame.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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <stdbool.h>
/// Struct data for user accounts.
typedef struct UserAccount{
char name[50];
char surname[50];
char nickname[50];
char password[50];
struct UserAccount *next;
int score;
}UserAccount;
//// Sort algorithm to sort linked list.
UserAccount *sortLinkedList(UserAccount *head){
UserAccount *p;
UserAccount *q;
UserAccount *r;
UserAccount *end;
UserAccount *tmp;
for(end=NULL;end!=head->next;end=p){
for(r=p=head;p->next!=end;r=p,p=p->next){
q=p->next;
if(p->score<q->score){
p->next=q->next;
q->next=p;
if(p!=head){
r->next=q;
}
else{
head=q;
}
tmp=p;
p=q;
q=tmp;
}
}
}
return head;
}
// This functions creates a new user account node and returns its adress;
UserAccount *createAccount(char *username){
UserAccount *acc=calloc(1,sizeof(UserAccount));
printf("Enter Your Name : ");
scanf("%s",acc->name);
printf("Enter Your Surname : ");
scanf("%s",acc->surname);
strcpy(acc->nickname,username);
printf("Enter Your Password : ");
scanf("%s",acc->password);
acc->score=0;
return acc;
}
// This funciton read a txt file to represent map and returns this map as char matrix.
char **readLabyrinth(char *File_Name){
FILE *fp = fopen(File_Name, "r");
char bufferR[30];
int i=0;
int rawsize=0;
while(!feof(fp)){
fgets(bufferR, sizeof(bufferR), fp);
rawsize++;
}
bufferR[0]='\0';
fseek(fp,0,SEEK_SET);
char **labyrinth = (char **)calloc(rawsize, sizeof(char*));
while(!feof(fp)){
if (fgets(bufferR, sizeof(bufferR), fp) != NULL) {
labyrinth[i] = (char *)calloc((strlen(bufferR)+1), sizeof(char));
bufferR[strcspn(bufferR, "\n")] = '\0'; // Removing newline if present
strcpy(labyrinth[i], bufferR); // Copying content to labyrinth
i++;
}
}
fclose(fp);
return labyrinth;
}
// This function prints the whole map in a for loop
void printLabyrinth(char**lybrnth){
int i,j;
printf("# # # # # # # # # # # # \n");
for(i=0;i<6;i++){
printf("#");
for(j=0;j<10;j++){
if(lybrnth[i][j]=='X') printf(" \033[1;31m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='1') printf(" \033[1;35m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='p') printf(" \033[1;34m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='P') printf(" \033[1;34m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='e') printf(" \033[1;33m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='E') printf(" \033[1;33m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='0') printf(" \033[1;37m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='K') printf(" \033[1;36m%c\033[0m",lybrnth[i][j]);
if(lybrnth[i][j]=='C') printf(" \033[1;32m%c\033[0m",lybrnth[i][j]);
}
printf(" #\n");
}
printf("# # # # # # # # # # # # \n");
}
//This function read a data binary file , if function can't read the file , creates a new one and returns null;
UserAccount *readUserData(){
FILE *fp = fopen("userdata4.bin","rb");
if(fp==NULL){
printf("okuma hatasi");
fp = fopen("userdata4.bin","wb");
}
fseek(fp,0,SEEK_END);
if((ftell(fp)==0)){
printf("\n UserData empty!");
sleep(1);
system("cls");
return NULL;
}
rewind(fp);
UserAccount *head=calloc(1,sizeof(UserAccount));
head->next=NULL;
UserAccount *prevData=head;
UserAccount *currData;
while (fread(prevData,sizeof(UserAccount),1,fp))
{
currData=calloc(1,sizeof(UserAccount));
prevData->next=currData;
currData->next=NULL;
prevData=currData;
}
fclose(fp);
return head;
}
// This function prints the linked list
void printLinkedList(UserAccount *head){
UserAccount *ptr=head;
while(ptr!=NULL){
printf("NAME : %s , Surname : %s , NickName : %s , Password : %s \n",ptr->name,ptr->surname,ptr->nickname,ptr->password);
ptr=ptr->next;
}
}
// This function creates a new user account and it adds to linked list also save the new user account data in appending mode.
UserAccount *updateUserData(char *file_name,UserAccount *head){
FILE *fp = fopen(file_name,"ab");
if(!fp){
perror("\nERROR!");
}
UserAccount *ptr=head;
UserAccount *ptr2=head;
char username[50];
int savedUser;
do{
system("cls");
savedUser=1;
printf("\nEnter Your Username : ");
scanf("%s",username);
ptr2=head;
while(ptr2!=NULL){
if(!strcmp(ptr2->nickname,username)){
savedUser=0;
}
ptr2=ptr2->next;
}
if(savedUser==0){
printf("\nThis Username Already Taken, Pick another..");
sleep(2);
}
}while(savedUser==0);
if(head==NULL){
head=createAccount(username); // head boşssa yeni data oluştur
fwrite(head,sizeof(UserAccount),1,fp);
fclose(fp);
return head;
}
else{
printf("\nHesap olusturuluyor\n");
sleep(1);
while(ptr->next!=NULL){
ptr=ptr->next;
}
ptr->next=createAccount(username);
ptr->next->next=NULL;
fwrite(ptr->next,sizeof(UserAccount),1,fp);
fclose(fp);
return ptr->next;
}
}
// This function is for login. It takes the head of linked list and checks usernames and passwords ,
// if login is succesfull it returns the login account.
UserAccount *loginmenu(UserAccount *head){
UserAccount *loginaccount;
char username[50];
char password[50];
char a;
int flag=1;
int savedname=0;
int savedpassword=0;
do{
system("cls");
printf("**************Welcome to The Game***************\n");
printf("\t1.LOGIN\n");
printf("\t2.SIGN UP\n");
printf("\tYour choice : ");
scanf(" %c",&a);
switch (a)
{
case '1':
system("cls");
do{
system("cls");
if(head==NULL){
printf("\n User Data Empty Please Sign Up");
sleep(1);
break;
}
printf("\n\tEnter Your Username : ");
scanf("%s",username);
UserAccount *ptr=head;
UserAccount *user;
while(ptr!=NULL){
if(!strcmp(username,ptr->nickname)){
savedname=1;
user=ptr;
}
ptr=ptr->next;
}
if(savedname==1){
printf("\nUsername found\n");
sleep(2);
do{
system("cls");
printf("Enter your password :");
scanf("%s",password);
if(!strcmp(password,user->password)){
savedpassword=1;
loginaccount=user;
printf("Successfuly logged in..\n");
}
else{
printf("Invalid Password Try Again ! \n");
sleep(2);
}
}while(savedpassword==0);
}
else{
printf("\nUsername not found Try Again!");
sleep(2);
}
}while(savedname==0);
if(head!=NULL){
flag=0;
}
break;
case '2':
system("cls");
printf("signin up...\n");
loginaccount=updateUserData("userdata4.bin",head);
printf("succesfuly signed up...\n");
flag=0;
break;
default:
printf("\nInvalid option !!\n");
sleep(1);
}
}while(flag==1);
return loginaccount;
}
// This function for recursion autoplay algorithm . It checks the boundries.
// if the new location out of boundries it returns false;
bool boundryOut(int xraw , int xcol){
if(xraw<0) return false;
else if(xraw>5) return false;
else if(xcol<0) return false;
else if(xcol>9) return false;
else return true;
}
//This functions updates the user's location in for given coordinates at the map.
void updatePlayerLocation(char **labyrinth,int xraw,int xcol,int xrawOld,int xcolOld){
labyrinth[xraw][xcol]='X';
}
//This function for autogameplay. It is a recursion algorithm and it adds to stack new positions and if it finds the exit returns 1 on all stack.
//Also each step it checks for particules if there is a particules certain position it adds to collectables array to save collected particules.
//If it goes to wrong way it comebacks the start position and try a different direction
int autoGameplay(char **labyritnh,int xraw,int xcol,char **labelmatrix, int* coordinates,char *collectables,int collect_size){
// sınırları kontrol et ! eğer çıktıysa return 0;
// karadelik ise return 0;
// visited label 1 ise return 0;
// çıkış gelirse (C) return 1;
if(!boundryOut(xraw,xcol)){
return 0;
}
else if(labyritnh[xraw][xcol]=='K'){
return 0;
}
else if(labelmatrix[xraw][xcol]=='1'){
return 0;
}
else if(labyritnh[xraw][xcol]=='1'){
return 0;
}
else if(labyritnh[xraw][xcol]=='C'){
labelmatrix[xraw][xcol]='1'; //labeling 1
int tempx = coordinates[0];
int tempy = coordinates[1];
labyritnh[tempx][tempy] = '0';//making 0 past location
labyritnh[xraw][xcol] = 'X';
system("cls");
printLabyrinth(labyritnh);
printf("\n----------Exit found!!!");
sleep(2);
return 1;
}
system("cls");
printLabyrinth(labyritnh);
int i=0;
printf("\nCollected Particules : ");
while(collectables[i]!='\0'){
printf("%c,",collectables[i]); //printing collected particules en each step
i++;
}
sleep(1);
labelmatrix[xraw][xcol]='1'; //labeling positions as 1
int tempx = coordinates[0];
int tempy = coordinates[1];
labyritnh[tempx][tempy] = '0'; // making 0 past location
if(labyritnh[xraw][xcol]!='0'&&labyritnh[xraw][xcol]!='X'){
collectables[collect_size]=labyritnh[xraw][xcol]; // array for particules
collect_size++;
}
labyritnh[xraw][xcol] = 'X';
coordinates[0] = xraw;
coordinates[1] = xcol;
if(autoGameplay(labyritnh,xraw-1,xcol,labelmatrix,coordinates,collectables,collect_size)){
return 1;
}
if(autoGameplay(labyritnh,xraw,xcol+1,labelmatrix,coordinates,collectables,collect_size)){
return 1;
}
if(autoGameplay(labyritnh,xraw+1,xcol,labelmatrix,coordinates,collectables,collect_size)){
return 1;
}
if (autoGameplay(labyritnh,xraw,xcol-1,labelmatrix,coordinates,collectables,collect_size)){
return 1;
}
labelmatrix[xraw][xcol]='0';
return 0;
}
//This function is the manuel play algorithm. Each step takes an arrow input from user and checks the new positions.
//After that it updates the user location on the map.
//If user can reach the exit, it saves the collected particules and calculates the score and updates user's score and save it to userdata.
void manuelGameplay(UserAccount *loginaccount){
char gamemode; // switch case expression
int flag=0; // do while condition for menu
char *map; // map name to load
char map2[30];
do{
system("cls");
printf("\n***********MANUEL GAMEMODE**********");
printf("\n\tChoose a map :");
printf("\n\t1.MAP 1");
printf("\n\t2.MAP 2");
printf("\n\t3.MAP 3");
printf("\n\t4.Load your own map");
printf("\n\tYour Choice :");
scanf("%c",&gamemode);
switch (gamemode)
{
case '1':
map="map1.txt";
flag=1;
break;
case '2':
map="map2.txt";
flag=1;
break;
case '3':
map="map3.txt";
flag=1;
break;
case '4':
printf("\nEnter the name.txt of map that you want to play:");
scanf(" %s",map2);
map=map2;
FILE *f =fopen(map,"r");
if(f==NULL){
printf("\n There is no such a file %s !!",map);
sleep(1);
}
else flag=1;
break;
default:
printf("\nInvalid Option!!");
sleep(1);
break;
}
}while(flag==0);
system("cls");
printf("\n\tLoading your game...");
sleep(1);
system("cls");
char **labyrnth=readLabyrinth(map);
//printLabyrinth(labyrnth);
char player='X';
int playerR=2; // Player's location on the map
int playerC=1;
int i,j,k;
char a;
int flag2=0; //flag for while loops
char collection[20]={'0'};
int number_of_collects=0;
int exit=0; // exit condition
int gameover=0; // Gameover condition
int time=1;
clock_t start = clock(); //Starts the time
clock_t end = clock();
while ((end - start)/CLOCKS_PER_SEC<30&&exit!=1&&gameover!=1)
{
printf("Geri Sayim:%d\n",31-((end - start)/CLOCKS_PER_SEC));
printLabyrinth(labyrnth);
printf("\nCollected items : ");
for(k=0;k<number_of_collects;k++){
printf("%c ",collection[k]);
}
a = getch();
if (a==27)
{
printf("Cikis\n");
exit=1;
}
else
{
if(exit!=1){
do{
a = getch();
//printf("Bastiginiz ok tusu:%d\n",a);
switch (a)
{
case 'H': // UP UP UP Conditions
if(playerR-1>=0){
if(labyrnth[playerR-1][playerC]!='1'){
if(labyrnth[playerR-1][playerC]=='p'){
collection[number_of_collects]='p';
number_of_collects++;
}
else if(labyrnth[playerR-1][playerC]=='P'){
collection[number_of_collects]='P';
number_of_collects++;
}
else if(labyrnth[playerR-1][playerC]=='e'){
collection[number_of_collects]='e';
number_of_collects++;
}
else if(labyrnth[playerR-1][playerC]=='E'){
collection[number_of_collects]='E';
number_of_collects++;
}
else if(labyrnth[playerR-1][playerC]=='C'){
exit=1;
}
else if(labyrnth[playerR-1][playerC]=='K'){
gameover=1;
}
labyrnth[playerR][playerC]='0';
playerR-=1;
labyrnth[playerR][playerC]=player;
}
}
flag2=1;
break;
case 'P': // DOWN DOWN Conditions
if(playerR+1<=5){
if(labyrnth[playerR+1][playerC]!='1'){
if(labyrnth[playerR+1][playerC]=='p'){
collection[number_of_collects]='p';
number_of_collects++;
}
else if(labyrnth[playerR+1][playerC]=='P'){
collection[number_of_collects]='P';
number_of_collects++;
}
else if(labyrnth[playerR+1][playerC]=='e'){
collection[number_of_collects]='e';
number_of_collects++;
}
else if(labyrnth[playerR+1][playerC]=='E'){
collection[number_of_collects]='E';
number_of_collects++;
}
else if(labyrnth[playerR+1][playerC]=='C'){
exit=1;
}
else if(labyrnth[playerR+1][playerC]=='K'){
gameover=1;
}
labyrnth[playerR][playerC]='0';
playerR+=1;
labyrnth[playerR][playerC]=player;
}
}
flag2=1;
break;
case 'M': // RIGHT RIGHT Conditions
if(playerC+1<=9){
if(labyrnth[playerR][playerC+1]!='1'){
if(labyrnth[playerR][playerC+1]=='p'){
collection[number_of_collects]='p';
number_of_collects++;
}
else if(labyrnth[playerR][playerC+1]=='P'){
collection[number_of_collects]='P';
number_of_collects++;
}
else if(labyrnth[playerR][playerC+1]=='e'){
collection[number_of_collects]='e';
number_of_collects++;
}
else if(labyrnth[playerR][playerC+1]=='E'){
collection[number_of_collects]='E';
number_of_collects++;
}
else if(labyrnth[playerR][playerC+1]=='C'){
exit=1;
}
else if(labyrnth[playerR][playerC+1]=='K'){
gameover=1;
}
labyrnth[playerR][playerC]='0';
playerC+=1;
labyrnth[playerR][playerC]=player;
}
}
flag2=1;
break;
case 'K': // LEFT LEFT Conditions
if(playerC-1>=0){
if(labyrnth[playerR][playerC-1]!='1'){
if(labyrnth[playerR][playerC-1]=='p'){
collection[number_of_collects]='p';
number_of_collects++;
}
else if(labyrnth[playerR][playerC-1]=='P'){
collection[number_of_collects]='P';
number_of_collects++;
}
else if(labyrnth[playerR][playerC-1]=='e'){
collection[number_of_collects]='e';
number_of_collects++;
}
else if(labyrnth[playerR][playerC-1]=='E'){
collection[number_of_collects]='E';
number_of_collects++;
}
else if(labyrnth[playerR][playerC-1]=='C'){
exit=1;
}
else if(labyrnth[playerR][playerC-1]=='K'){
gameover=1;
}
labyrnth[playerR][playerC]='0';
playerC-=1;
labyrnth[playerR][playerC]=player;
}
}
flag2=1;
break;
default:
printf("\nInvalid Button");
break;
}
}while(flag2==0);
}
}
//sleep(1);
system("cls");
end=clock();
}
if(exit==1){
printf("EXITED!!\n");
printf("collected items : ");
for(k=0;k<number_of_collects;k++){
printf("%c ",collection[k]);
}
//counts for elements
int antimadde=0;
int proton=0;
int nproton=0;
int elektron=0;
int nelektron=0;
for(k=0;k<number_of_collects;k++){
if(collection[k]=='P')proton++;
else if(collection[k]=='p')nproton++;
else if(collection[k]=='E')elektron++;
else nelektron++;
}
if(nproton>proton&&elektron>nelektron){
if(nproton-proton<elektron-nelektron)antimadde=nproton-proton;
else antimadde=elektron-nelektron;
}
//reading userdata from file
UserAccount *head=readUserData();
UserAccount *ptr=head;
//calculating score and antimatters
int index=1;
while(ptr!=NULL&&strcmp(ptr->nickname,loginaccount->nickname)!=0){
index++;
ptr=ptr->next;
}
int newscore=ptr->score;
newscore+=antimadde*5 + number_of_collects;
ptr->score=newscore;
printf("\nYou have produced %d antimatters Your new score :%d ",antimadde,newscore);
FILE *newdata = fopen("userdata4.bin","wb");
if(!newdata){
perror("\nERROR!");
}
while(head->next!=NULL){
fwrite(head,sizeof(UserAccount),1,newdata); // saving updated scores data
head=head->next;
}
fclose(newdata);
}
else if(gameover==1){
printf("BLACK HOLE !");
}
else{
printf("Your Time is UP!!");
}
}
//This is the basic gamemenu we call the gameplay and login functions here.
void gamemenu(UserAccount *loginaccount,UserAccount *head){
sleep(2);
char a;
int return_Option;
int mode;
int flag3=1; // flag for while loop
UserAccount *headptr=head;
//////////// AUTOPLAY ///////////
char *collectables=calloc(20,sizeof(char)); //allocating array for collects
char **labelMatrix=calloc(6,sizeof(char**)); // an matrix for labeling player's past position
int k;
for(k=0;k<6;k++){
*(labelMatrix+k)=calloc(11,sizeof(char*));
}
int m,n,l;
int *coordinates=(int*)calloc(2,sizeof(int));
/////////////////////////////////
do
{
system("cls");
printf("\nWelcome %s\n",loginaccount->nickname);
printf("***********MENU***********\n");
printf("\t1.HOW TO PLAY\n");
printf("\t2.SCORE TABLE\n");
printf("\t3.START TO PLAY\n");
printf("\n\t Your Choice : ");
scanf(" %c",&a);
switch (a)
{
case '1':
system("cls");
printf( "1. In the maze, the following particles are present:\n"
" P+ : proton (P)\n"
" e- : electron (e)\n"
" P- : anti-proton (p)\n"
" e+ : positron (E)\n"
"2. To produce anti-hydrogen at the exit of the maze, you must only have P- and e+ particles in your possession.\n"
"3. When a particle collides with its opposite-signed counterpart, they annihilate each other.\n"
"4. Black holes are denoted by K. If you pass through the cells where black holes are present, the game ends.\n"
"5. If the user fails to reach the exit within a certain game duration, the game ends.\n"
"6. Each particules are 1 point and antimatters are 5 point.");
printf("\nTo return back press any button : ");
return_Option= getch();
break;
case '2':
system("cls");
printf("\n*******SCORE TABLE*******\n");
headptr=readUserData(); // Reading list from user data
UserAccount *ptr=headptr;
if(ptr->next!=NULL){
ptr=sortLinkedList(ptr);
}
int i=1;
while(ptr->next!=NULL){
printf("\t%d.%s Score : %d \n",i,ptr->nickname,ptr->score); //Printing Score Table
ptr=ptr->next;
i++;
}
printf("\nTo return back press any button : ");
return_Option= getch();
break;
case '3':
do{
system("cls");
printf("\n**************Game Mode****************");
printf("\n\t1.Manuel");
printf("\n\t2.Auto");
printf("\n\t3.Back to previous menu ");
printf("\n\tYour Choice : ");
scanf("%d",&mode);
switch (mode)
{
case 1:
manuelGameplay(loginaccount); // calling manuel gameplay for case 1;
sleep(1);
printf("\n Game is finished!");
printf("\nGoing back to menu...");
sleep(2);
flag3=0;
break;
case 2:
for(l=0;l<20;l++){
collectables[l]='\0';
}
for(m=0;m<6;m++){
for(n=0;n<10;n++){
labelMatrix[m][n]='0';
}
}
coordinates[0]=2;
coordinates[1]=1;
char **labyrnt=readLabyrinth("map1.txt");
autoGameplay(labyrnt,2,1,labelMatrix,coordinates,collectables,0);//calling autogameplay for case 2
int i=0;
printf("\nCollected Particules : ");
while(collectables[i]!='\0'){
printf("%c,",collectables[i]);
i++;
}
//Counts of particules
int antimadde=0;
int proton=0;
int nproton=0;
int elektron=0;
int nelektron=0;
for(k=0;k<i;k++){
if(collectables[k]=='P')proton++;
else if(collectables[k]=='p')nproton++;
else if(collectables[k]=='E')elektron++;
else nelektron++;
}
if(nproton>proton&&elektron>nelektron){
if(nproton-proton<elektron-nelektron)antimadde=nproton-proton;
else antimadde=elektron-nelektron;
}
printf("\n Produced %d Antimatters ",antimadde);
sleep(4);
break;
case 3:
flag3=0;
break;
default:
printf("\nInvalid Option Try Again !");
flag3=1;
sleep(1);
break;
}
}while(flag3==1);
break;
default:
printf("\nInvalid Option Try Again !");
sleep(1);
break;
}
} while (1);
}
int main(){
// we read data from file and create a linked list.
UserAccount *head=readUserData();
UserAccount *loginAccount;
loginAccount=loginmenu(head);// logined account or signed up
gamemenu(loginAccount,head);// Starts to play
}