/
main.cpp
869 lines (826 loc) · 24 KB
/
main.cpp
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
//including header files
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<time.h>
#include<stdlib.h>
//global user array
std::string name [30];
int password [30];
int mission [30];
int coin [30];
int extra [30];
int chance [30];
int UserAmount=0;
//global variable
int seasonamount;
std::string username;
//global word struct
struct word
{
std::string chars;
int main;
int sub;
std::string words[50];
};
//FUNCTION prototype menu
void MainMenu();
void InternalMenu();
//FUNCTION prototype login
void userAmount();
void userSet();
void showUser();
bool checkPassword(std::string user , int pass);
bool login();
//FUNCTION prototype signup
bool checkReapeat(std::string user);
void makeUser();
//FUNCTION prototype file
void reWrite();
//FUNCTION prototype Rank
void showRank();
//FUNCTION prototype InternalMenu
void WheelofLuck(std::string username);
void editProfile(std::string preuser);
// FUNCTION prototype Game
void seasonNum();
int showup(int level,std::string user,word *word);
int showLevels(std::string user,int missionOfSeason[]);
void showdown(int level,std::string user,word *word);
void challenge(word *word);
int main(){
system("clear");
srand(time(0));
userAmount();//reads the amount of users from user.txt
seasonNum();//reads the amount of seasons from level.txt
std::ifstream user ("levels.txt");//reads the whole words form level.txt and puts them in the array of stuct "word"
int seasonAmount,lines=0 ;
user >> seasonAmount;
int missionOfSeason[seasonAmount];
for(int w =0 ; w<seasonAmount ;w++){
user>> missionOfSeason[w];
lines+=missionOfSeason[w];
}
word missonLine[lines];
for(int q=0;q<lines;q++){
user>> missonLine[q].chars >>missonLine[q].main>>missonLine[q].sub;
int counter=missonLine[q].main+missonLine[q].sub;
for(int e=0;e<counter;e++){
user>>missonLine[q].words[e];
}
}
std::string Username;
short int choose=0;
userSet();
int randomnum=rand()%lines;
main:
MainMenu();
choose=0;
std::cin>>choose;
switch (choose)
{
case 1 :
makeUser();
goto main;
break;
case 2 :
if(login()==1)
{
int userIndex =0;
for( ; userIndex<UserAmount;userIndex++){
if(username.compare(name[userIndex])==0)
break;
}
sub:
system("clear");
InternalMenu();
choose=0;
std::cin >> choose;
int missionlevel=0;
switch (choose)
{
case 1:
play:
system("clear");
choose=showup(mission[userIndex],username,&missonLine[mission[userIndex]-1]);
if(choose==1){
showup(mission[userIndex],username,&missonLine[mission[userIndex]-1]);
goto play;
}
else{
goto sub;
}
case 2:
missionlevel=showLevels( username, missionOfSeason);
showdown(missionlevel,username,&missonLine[mission[userIndex]-1]);
goto sub;
break;
case 3:
system("clear");
WheelofLuck(username);
goto sub;
break;
case 4:
system("clear");
editProfile(username);
goto sub;
break;
case 5:
system("clear");
goto main;
break;
}
}
else{
system("clear");
goto main;
}
break;
case 3 :
showRank();
goto main;
break;
case 4 :
challenge(&missonLine[randomnum]);
goto main;
break;
case 5 :
exit(1);
break;
}
}
//FUNCTION menu
void MainMenu(){//shows the main menu of the game
std::cout<<"Welcome to this game:\n";
std::cout<<"******* Main Menu *******\n";
std::cout<<"1.Signup\n";
std::cout<<"2.Login\n";
std::cout<<"3.Rank\n";
std::cout<<"4.challenge\n";
std::cout<<"5.Exit\n\n";
std::cout<<"Please enter your choice:\n";
}
void InternalMenu(){//shows the internal menu of the game
std::cout<<"******* Internal Menu *******\n";
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"1.Continue game\n";
std::cout<<"2.Choose level\n";
std::cout<<"3.Wheel of Luck\n";
std::cout<<"4.Edit profile\n";
std::cout<<"5.Logout\n";
std::cout<<"\n\n";
std::cout<<"Please enter your choice:\n";
}
//FUNCTION login
void userAmount(){//reads the amount of users from user.txt
std::ifstream user ("user.txt");
int amount=0 ;
user >> amount;
UserAmount= amount;
}
void userSet(){//reads the users and their information from user.txt
std::ifstream user ("user.txt");
int temp ;
user >> temp;
int counter=0;
while(user>>name [counter]>>password[counter]>>mission[counter]>>coin[counter]>>extra[counter]>>chance[counter]){
counter++;
}
}
void showUser(){//show all the users and their information
for(int i=0;i<UserAmount;i++){
std::cout<<"name:\t"<<name[i]<<"\tpassword:\t"<<password[i]<<"\tmission:\t"<<mission[i]<<"\tcoin:\t"<<coin[i]<<"\textra:\t"<<extra[i]<<"\tchance:\t"<<chance[i]<<std::endl;
}
}
bool checkPassword(std::string user , int pass){ //check if the password is correct
int i =0;
for( ; i<UserAmount;i++)
{
if(user.compare(name[i])==0)
break;
}
if(i==UserAmount){
std::cout<< "there is no such a user name"<<std::endl;
return 0;
}
if(pass==password[i]){
return 1;
}
return 0;
}
bool login(){//checks if the user name and password are correct
system("clear");
int pass,temp;
std::cout<<"enter your username"<<std::endl;
std::cin>> username;
int i =0;
while (checkReapeat(username)==0)
{
std::cout<<"there is no such a username please enter a valid one"<<std::endl;
std::cin>>username;
}
for( ; i<UserAmount;i++){
if(username.compare(name[i])==0)
break;
}
std::cout<<"enter your password"<<std::endl;
std::cin>>pass;
if(pass==password[i]){
return 1;
}
int j =2;
while (j>0)
{
switch (j)
{
case 2:
std::cout<<"password is not correct you can try "<<j<<" more times"<<std::endl;
break;
case 1:
std::cout<<"password is not correct you can try "<<j<<" more time"<<std::endl;
break;
}
std::cin>>pass;
j--;
if(pass==password[i]){
return 1;
}
}
return 0;
}
//FUNCTION signup
bool checkReapeat(std::string user){//checks if the username is already exist
for(int i =0 ; i<UserAmount;i++)
{
if(user.compare(name[i])==0)
return 1;
}
return 0;
}
void makeUser(){//maiking new user
system("clear");
int pass,temp ;
std::string user;
std::cout<< "please enter username"<<std::endl;
std::cin>>user;
while(checkReapeat(user)==1)
{
std::cout<< "this user name has been taken please enter another username"<<std::endl;
std::cin>>user;
}
std::cout<<"enter your password"<<std::endl;
std::cin>>pass;
std::cout<<"confirm your password"<<std::endl;
std::cin>>temp;
while (temp!=pass)
{
std::cout<<"please enter the same pass word"<<std::endl;
std::cout<<"enter your password"<<std::endl;
std::cin>>pass;
std::cout<<"confirm your password"<<std::endl;
std::cin>>temp;
}
int tag =UserAmount;
UserAmount++;
name[tag]=user;
password [tag]=pass;
mission [tag]=1;
coin [tag]=0;
extra[tag]=0;
chance[tag]=0;
reWrite();
system("clear");
}
//FUNCTION file
void reWrite(){//rewrite the user.txt file
std::ofstream user ("user.txt");
user << UserAmount<<std::endl;
for (int i = 0; i < UserAmount ; i++)
{
user<<name[i]<<"\t"<<password[i]<<"\t"<<mission[i]<<"\t"<<coin[i]<<"\t"<<extra[i]<<"\t"<<chance[i]<<"\t\n";
}
}
//FUNCTION Rank
void showRank(){//show the sorted user by their mission number that they passed
system("clear");
int amount =UserAmount;
int indexSort[amount];
for(int i =0 ; i<amount;i++){
indexSort[i]=i;
}
for (int i = 0; i <amount ; i++)
{
for (int j = i+1; j <amount ; j++)
{
if(mission[indexSort[i]]<mission[indexSort[j]]){
int temp = indexSort[i];
indexSort[i]=indexSort[j];
indexSort[j]=temp;
}
}
}
for (int w = 0; w < amount; w++)
{
std::cout<<"Username:\t"<<name[indexSort[w]]<<"\t\t"<<"mission:\t"<<mission[indexSort[w]]<<std::endl;
}
std::cout<<std::endl;
std::cin.get();
system("clear");
}
//FUNCTION InternalMenu
void WheelofLuck(std::string user){//rooling the wheelofluck
int choice=0;
int i =0;
for( ; i<UserAmount;i++){
if(user.compare(name[i])==0)
break;
}
if(chance[i]==0){
std::cout<<user<<" don't have any chance for wheel of luck ."<<std::endl;
}
else
{
if(chance[i]==1){
std::cout<<user<<" has "<<chance[i]<<" chance for wheel of luck ."<<std::endl;
}
else{
std::cout<<user<<" has "<<chance[i]<<" chances for wheel of luck ."<<std::endl;
}
std::cout<<"wheel of luck has 6 kinds of awards"<<std::endl;
std::cout<<"50 coins 30% chance"<<std::endl;
std::cout<<"70 coins 20% chance"<<std::endl;
std::cout<<"90 coins 20% chance"<<std::endl;
std::cout<<"110 coins 15% chance"<<std::endl;
std::cout<<"150 coins 10% chance"<<std::endl;
std::cout<<"220 coins 5% chance"<<std::endl;
std::cout<<"would you like to roll the wheel of luck?"<<std::endl;
std::cout<<"1.yes"<<std::endl;
std::cout<<"2.no"<<std::endl<<std::endl;
std::cin>>choice;
}
if(choice==1){
chance[i]--;
int temp = (rand()%20)+1;
switch (temp)
{
case 1 ... 6:
std::cout<<user<<" won 50\n";
coin[i]+=50;
break;
case 7 ... 10:
coin[i]+=70;
std::cout<<user<<" won 70\n";
break;
case 11 ... 14:
coin[i]+=90;
std::cout<<user<<" won 90\n";
break;
case 15 ... 17:
coin[i]+=110;
std::cout<<user<<" won 110\n";
break;
case 18 ... 19:
coin[i]+=150;
std::cout<<user<<" won 150\n";
break;
case 20 :
coin[i]+=220;
std::cout<<user<<" won 220\n";
break;
}
std::cin.get();
reWrite();
}
}
void editProfile(std::string preuser){//making new user name and password for an account
int pass,temp ;
int i =0;
for( ; i<UserAmount;i++){
if(preuser.compare(name[i])==0)
break;
}
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"enter your password"<<std::endl;
std::cin>>pass;
while (pass!=password[i])
{
std::cout<<"the password is not correct\n";
std::cin>>pass;
}
std::string user;
std::cout<< "please enter new username"<<std::endl;
std::cin>>user;
while(checkReapeat(user)==1)
{
std::cout<< "this user name has been taken please enter another username"<<std::endl;
std::cin>>user;
}
std::cout<<"enter your new password"<<std::endl;
std::cin>>pass;
std::cout<<"confirm your new password"<<std::endl;
std::cin>>temp;
while (temp!=pass)
{
std::cout<<"please enter the same password"<<std::endl;
std::cout<<"enter your new password"<<std::endl;
std::cin>>pass;
std::cout<<"confirm your new password"<<std::endl;
std::cin>>temp;
}
name[i]=user;
password [i]=pass;
username=user;
reWrite();
}
// FUNCTION Game
void seasonNum(){//reads the amount of seasons from the level.txt
std::ifstream user ("levels.txt");
int temp ;
user >> temp;
seasonamount=temp;
}
int showup(int level,std::string user,word *word){//shows the words that the user has to guess
std::ifstream userFile ("levels.txt");
int seasonAmount,lines=0 ;
userFile >> seasonAmount;
int missionOfSeason[seasonAmount];
for(int w =0 ; w<seasonAmount ;w++){
userFile>> missionOfSeason[w];
}
int season =1;
int leveltemp = level;
int r=0;
for(;r<seasonAmount;r++){
if(leveltemp<=missionOfSeason[r]){
break;
}
else{
leveltemp-=missionOfSeason[r];
season++;
}
}
int i =0;
for( ; i<UserAmount;i++){
if(user.compare(name[i])==0)
break;
}
std::cout<< "season : "<<season<<"\tlevel : "<<leveltemp<<"\tcoin : "<<coin[i]<<"\textra words: "<<extra[i]<<std::endl<<std::endl;
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"mian words : "<<word->main<<"\t\tsub words : "<<word->sub<<std::endl;
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
int counterWord=0;
std::string answer;
for(int j=0;j<22;j++)
{
if(word->words[j][0]!='\0'){
counterWord++;
}
}
bool solved[counterWord]{0};
for(bool flag=0; flag==0;){
for(int j=0;j<counterWord;j++){
if(solved[j]==false)
{
for(int q=word->words[j].length();q>0;q--)
{
std::cout<<"- ";
}
std::cout<<std::endl;
}
else{
std::cout<<word->words[j]<<"\n";
}
}
std::cout<<"enter the word you want to solve"<<std::endl;
std::cin>> answer;
for(int z=0 ; z<counterWord;z++)
{
if(answer.compare(word->words[z])==0)
{
if(solved[z]==true)
{
std::cout<<"you already solved this word"<<std::endl;
std::cin.get();
}
else{
std::cout<<"you solved the word"<<std::endl;
if(word->main<(z+1)){
extra[i]++;
if(extra[i]>=6){
extra[i]-=6;
coin[i]+=50;
std::cout<<"you receive 50 coins because you give 6 extra words to the game"<<std::endl;
reWrite();
}
reWrite();
}
solved[z]=true;
std::cin.get();
}
}
}
for(int h=0 , counter=0;h<word->main;h++){
if(solved[h]==true){
counter++;
}
if(counter==word->main){
flag=1;
break;
}
}
system("clear");
std::cout<< "season : "<<season<<"\tlevel : "<<leveltemp<<"\tcoin : "<<coin[i]<<"\textra words: "<<extra[i]<<std::endl<<std::endl;
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"mian words : "<<word->main<<"\t\tsub words : "<<word->sub<<std::endl;
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
}
system("clear");
std::cout<<"congratulations you passed the mission "<<std::endl;
mission[i]++;
std::cout<<"here is your reward 100 coins"<<std::endl<<std::endl;
coin[i]+=100;
leveltemp++;
if(leveltemp>missionOfSeason[r]){
std::cout<<"you passed the season too"<<std::endl;
std::cout<<"your reward is a chance for wheel of luck"<<std::endl;
chance[i]++;
}
reWrite();
std::cout<<"would you like to play next mission?"<<std::endl;
std::cout<<"1.yes"<<std::endl;
std::cout<<"2.no"<<std::endl<<std::endl;
int choose =0;
std::cin>>choose;
return choose;
}
int showLevels(std::string user,int missionOfSeason[]){//reads the level that player wants to play
system("clear");
int result=0;
int i =0;
for( ; i<UserAmount;i++){
if(username.compare(name[i])==0)
break;
}
std::cout<<"which mission would you like to play?"<<std::endl;
for(int g=0,t=0;g<mission[i];g++){
int season =1;
int leveltemp = g+1;
for(int r=0;r<seasonamount;r++){
if(leveltemp<=missionOfSeason[r]){
break;
}
else{
leveltemp-=missionOfSeason[r];
season++;
}
}
std::cout<<g+1<<" .season "<<season<<"\tmission "<<leveltemp<<std::endl;
}
std::cout<<std::endl;
std::cin>>result;
system("clear");
for(;result<1||result>mission[i];){
std::cout<<"you have to choose a mission that you have already passed"<<std::endl;
std::cout<<"which mission would you like to play?"<<std::endl;
for(int g=0,t=0;g<mission[i];g++){
int season =1;
int leveltemp = g+1;
for(int r=0;r<seasonamount;r++){
if(leveltemp<=missionOfSeason[r]){
break;
}
else{
leveltemp-=missionOfSeason[r];
season++;
}
}
std::cout<<g+1<<" .season "<<season<<"\tmission "<<leveltemp<<std::endl;
}
std::cout<<std::endl;
std::cin>>result;
system("clear");
}
return result;
}
void showdown(int level,std::string user,word *word){
std::ifstream userFile ("levels.txt");
int seasonAmount,lines=0 ;
userFile >> seasonAmount;
int missionOfSeason[seasonAmount];
for(int w =0 ; w<seasonAmount ;w++){
userFile>> missionOfSeason[w];
}
int season =1;
int leveltemp = level;
for(int r=0;r<seasonAmount;r++){
if(leveltemp<=missionOfSeason[r]){
break;
}
else{
leveltemp-=missionOfSeason[r];
season++;
}
}
int i =0;
for( ; i<UserAmount;i++){
if(user.compare(name[i])==0)
break;
}
std::cout<< "season : "<<season<<"\tlevel : "<<leveltemp<<"\tcoin : "<<coin[i]<<"\textra words: "<<extra[i]<<std::endl<<std::endl;
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"mian words : "<<word->main<<"\t\tsub words : "<<word->sub<<std::endl;
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
int counterWord=0;
std::string answer;
for(int j=0;j<22;j++)
{
if(word->words[j][0]!='\0'){
counterWord++;
}
}
bool solved[counterWord]{0};
for(bool flag=0; flag==0;){
for(int j=0;j<counterWord;j++){
if(solved[j]==false)
{
for(int q=word->words[j].length();q>0;q--)
{
std::cout<<"- ";
}
std::cout<<std::endl;
}
else{
std::cout<<word->words[j]<<"\n";
}
}
std::cout<<"enter the word you want to solve"<<std::endl;
std::cin>> answer;
for(int z=0 ; z<counterWord;z++)
{
if(answer.compare(word->words[z])==0)
{
if(solved[z]==true)
{
std::cout<<"you already solved this word"<<std::endl;
std::cin.get();
}
else{
std::cout<<"you solved the word"<<std::endl;
solved[z]=true;
std::cin.get();
}
}
}
for(int h=0 , counter=0;h<word->main;h++){
if(solved[h]==true){
counter++;
}
if(counter==word->main){
flag=1;
break;
}
}
system("clear");
std::cout<< "season : "<<season<<"\tlevel : "<<leveltemp<<"\tcoin : "<<coin[i]<<"\textra words: "<<extra[i]<<std::endl<<std::endl;
std::cout<<"ussername : "<<username<<std::endl<<std::endl;
std::cout<<"mian words : "<<word->main<<"\t\tsub words : "<<word->sub<<std::endl;
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
}
}
void challenge(word *word){
system("clear");
std::string user1;
std::string user2;
int temp=0;
std::cout<<"enter the username of the first player"<<std::endl;
std::cin>>user1;
std::cout<<"enter the username of the second player"<<std::endl;
std::cin>>user2;
system("clear");
int user1score=0;
int user2score=0;
int usernum =-1;
std::cout<<user1<<" : "<<user1score<<"\t"<<user2<<" : "<<user2score<<std::endl;
std::cout<<"turn: "<<user1<<std::endl;
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
int counterWord=0;
std::string answer;
for(int j=0;j<22;j++)
{
if(word->words[j][0]!='\0'){
counterWord++;
}
}
bool solved[counterWord]{0};
for(bool flag=0; flag==0;){
if(temp){
if(usernum==-1){
std::cout<<"turn: "<<user1<<std::endl;
}
else{
std::cout<<"turn: "<<user2<<std::endl;
}
}
for(int j=0;j<counterWord;j++){
if(solved[j]==false){
for(int q=word->words[j].length();q>0;q--){
std::cout<<"- ";
}
std::cout<<std::endl;
}
else{
std::cout<<word->words[j]<<"\n";
}
}
std::cout<<"enter * to give up"<<std::endl;
std::cout<<"enter the word you want to solve"<<std::endl;
std::cin>> answer;
if(answer.compare("*")!=0){
for(int z=0 ; z<counterWord;z++){
if(answer.compare(word->words[z])==0){
if(solved[z]==true){
std::cout<<"this word is already solved "<<std::endl;
std::cin.get();
}
else{
if(usernum==-1){
user1score+=answer.size();
std::cout<<user1<<" solved the word"<<std::endl;
}
else{
user2score+=answer.size();
std::cout<<user2<<" solved the word"<<std::endl;
}
solved[z]=true;
std::cin.get();
}
}
}
for(int h=0 , counter=0;h<counterWord;h++){
if(solved[h]==true){
counter++;
}
if(counter==counterWord){
flag=1;
break;
}
}
system("clear");
std::cout<<user1<<" : "<<user1score<<"\t"<<user2<<" : "<<user2score<<std::endl;
if(flag==0){
for(int j=0;word->chars[j];j++)
{
std::cout<<word->chars[j]<<" ";
}
std::cout<<std::endl<<std::endl;
usernum*=-1;
temp++;
}
}
else{
system("clear");
flag=1;
if(usernum==-1){
std::cout<<user2<<" won the game"<<std::endl;
}
else{
std::cout<<user1<<" won the game"<<std::endl;
}
std::cin.get();
system("clear");
return;
}
}
if(user1score>user2score){
std::cout<<user1<<" won the game"<<std::endl;
}
else if(user1score<user2score){
std::cout<<user2<<" won the game"<<std::endl;
}
else{
std::cout<<"the game is draw"<<std::endl;
}
std::cin.get();
system("clear");
}