-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameIn.cpp
1849 lines (1719 loc) · 59.7 KB
/
gameIn.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
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 --------------------------> */
#include <iostream>
#include <vector> // use vector method
#include <fstream> // play with filles
#include <conio.h>
#include <windows.h> // to use system
#include <chrono> // time and date
using namespace std;
int main();
/* <-------------------------- End Header Files --------------------------> */
/*<--------------------------- Timer for Game ---------------------------->*/
/* don't touch class */
class Timer
{
LARGE_INTEGER startTime;
double fFreq;
public:
Timer()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
fFreq = (double)freq.QuadPart;
reset();
}
void reset() { QueryPerformanceCounter(&startTime); }
double getTime() const
{
LARGE_INTEGER endTime;
QueryPerformanceCounter(&endTime);
return (endTime.QuadPart - startTime.QuadPart) / fFreq; // as double
}
};
/*<--------------------------- End Timer for Game ---------------------------->*/
/* <------------------------- Screen Modification ------------------------> */
#define SCREEN_WIDTH 90
#define SCREEN_HEIGHT 26
#define WIN_WIDTH 70
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void gotoxy(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console, CursorPosition);
}
/* <------------------------- End Screen Modification --------------------> */
/*<-------------------------- Design of load ----------------------------->*/
void loadingDesign()
{
system("cls");
system("Color 4D");
cout << "\033[3;33m";
cout << "\n\n\n\n " << endl;
cout << " " << endl;
cout << " | .------. .------------. .---------. | |\\ | _________ " << endl;
cout << " | .' '. | | | | | | \\ | | | " << endl;
cout << " | | | | | | | | | \\ | | | " << endl;
cout << " | | | | | | | | | \\ | | " << endl;
cout << " | | | | | | | | | \\ | | " << endl;
cout << " | | | |------------| | | | | \\ | | ---. " << endl;
cout << " | | | | | | | | | \\ | | | " << endl;
cout << " | '. .' | | | | | | \\ | | | " << endl;
cout << " |_________ '------' | | '-----------' | | \\| |________| _ _ _ " << endl;
cout << " " << endl;
cout << " ";
cout << "\033[3;34m";
for (int i = 0; i < 102; i++)
{
cout << ":";
Sleep(15);
}
cout << "\n\n"
<< endl;
system("cls");
}
/*<-------------------------- End Design of load ----------------------------->*/
/*<------------------------- Game Score Update -------------------------------> */
// game history
int runCar = 0;
int runTicTac = 0;
int runCasino = 0;
int runWord = 0;
int runHangman = 0;
// player history
int maxCarScore = 0;
int maxWordScore = 0;
int maxHnagmanScore = 0;
int maxCasinoWin = 0;
int maxTictac = 0;
string wordHunter = "";
string hangmanHunter = "";
string casinoHunter = "";
string tictacHunter = "";
void uploadData(int carscore, string tictacname, int tictacScore, string csinoname, int casinomoney, string wordplayername, int wordscore, string hangmanplayer, int hangmanscore, int h1, int h2, int h3, int h4, int h5)
{
ofstream myfile;
myfile.open("scoredata.txt");
myfile << carscore << "\n";
myfile << tictacname << "\n";
myfile << tictacScore << "\n";
myfile << csinoname << "\n";
myfile << casinomoney << "\n";
myfile << wordplayername << "\n";
myfile << wordscore << "\n";
myfile << hangmanplayer << "\n";
myfile << hangmanscore << "\n";
myfile << h1 << "\n";
myfile << h2 << "\n";
myfile << h3 << "\n";
myfile << h4 << "\n";
myfile << h5 << "\n";
myfile.close();
}
string LoadRandomWord(string path, int p)
{
int lineCount = 0;
string word;
vector<string> v;
ifstream reader(path);
if (reader.is_open())
{
while (std::getline(reader, word))
v.push_back(word);
int randomLine = p;
word = v.at(randomLine);
reader.close();
}
return word;
}
void dataUpdation()
{
string wordToGuess;
wordToGuess = LoadRandomWord("scoredata.txt", 0);
int carscore = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 1);
string tictacname = wordToGuess;
wordToGuess = LoadRandomWord("scoredata.txt", 2);
int tictacScore = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 3);
string csinoname = wordToGuess;
wordToGuess = LoadRandomWord("scoredata.txt", 4);
int casinomoney = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 5);
string wordplayername = wordToGuess;
wordToGuess = LoadRandomWord("scoredata.txt", 6);
int wordscore = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 7);
string hangmanplayer = wordToGuess;
wordToGuess = LoadRandomWord("scoredata.txt", 8);
int hangmanscore = stoi(wordToGuess);
// played history
wordToGuess = LoadRandomWord("scoredata.txt", 9);
int recordRunCar = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 10);
int recordRunTicTac = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 11);
int recordRunCasino = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 12);
int recordRunWord = stoi(wordToGuess);
wordToGuess = LoadRandomWord("scoredata.txt", 13);
int recordRunHangman = stoi(wordToGuess);
// conditions for update every player name and score
if (maxCarScore > carscore || maxWordScore > wordscore || maxHnagmanScore > hangmanscore || maxCasinoWin > casinomoney || maxTictac > tictacScore)
{
carscore = maxCarScore;
wordscore = maxWordScore;
wordplayername = wordHunter;
hangmanscore = maxHnagmanScore;
hangmanplayer = hangmanHunter;
casinomoney = maxCasinoWin;
csinoname = casinoHunter;
tictacScore = maxTictac;
tictacname = tictacHunter;
}
else
{
maxCarScore = carscore;
maxWordScore = wordscore;
wordHunter = wordplayername;
maxHnagmanScore = hangmanscore;
hangmanHunter = hangmanplayer;
maxCasinoWin = casinomoney;
casinoHunter = csinoname;
maxTictac = tictacScore;
tictacHunter = tictacname;
}
if (runCar > recordRunCar || runTicTac > recordRunTicTac || runCasino > recordRunCasino || runWord > recordRunWord || runHangman > recordRunHangman)
{
recordRunCar = runCar;
recordRunTicTac = runTicTac;
recordRunCasino = runCasino;
recordRunWord = runWord;
recordRunHangman = runHangman;
}
else
{
runCar = recordRunCar;
runTicTac = recordRunTicTac;
runCasino = recordRunCasino;
runWord = recordRunWord;
runHangman = recordRunHangman;
}
uploadData(carscore, tictacname, tictacScore, csinoname, casinomoney, wordplayername, wordscore, hangmanplayer, hangmanscore, runCar, runTicTac, runCasino, runWord, runHangman);
}
/*<------------------------- End Game Score Update -------------------------------> */
/* <-------------------------- Tic Tac Toi -------------------------------> */
typedef struct
{
int *row;
} WinList;
class Player
{
private:
string name;
int score = 0;
public:
Player() : Player{""} {}
Player(string n) : score{0}, name{n} {}
void won()
{
//increment the score
score++;
}
int getScore() { return this->score; }
string getName() { return this->name; }
};
class Game
{
private:
char board[9];
int emptyIndex[9];
int gameOn, againstComputer;
int emptyCount;
WinList winlist[8];
void displayBoard()
{
cout << endl;
cout << "\t\t---------------------------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t|\t " << board[0] << " | " << board[1] << " | " << board[2] << " |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t|\t-----------"
<< " |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t|\t " << board[3] << " | " << board[4] << " | " << board[5] << " |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t|\t-----------"
<< " |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t|\t " << board[6] << " | " << board[7] << " | " << board[8] << " |" << endl;
cout << "\t\t|\t | | "
<< " |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t---------------------------" << endl;
cout << endl;
}
void computerInput()
{
int pos;
pos = rand() % 10;
if (emptyIndex[pos] == 1)
{
if (emptyCount < 0)
return;
computerInput();
}
else
{
system("cls");
cout << "\t\tComputer choose: " << pos + 1 << endl;
Sleep(400);
emptyIndex[pos] = 1;
emptyCount -= 1;
board[pos] = 'O';
}
}
void playerInput(Player &player, Player &player1)
{
int pos;
Sleep(500);
cout << endl;
// cout << "\t" << player.getName() << " Turn ";
cout << "\t" << player.getName() << "'s Turn ";
char inpt;
cout << "\t Enter the position : ";
inpt = getche();
pos = (int)(inpt)-48;
pos -= 1;
if (emptyIndex[pos] == 1)
{
cout << "\n\t-----Position Invalid-------\n"
<< endl;
playerInput(player, player1);
}
else
{
emptyIndex[pos] = 1;
emptyCount -= 1;
player.getName().compare(player1.getName()) == 0 ? board[pos] = 'X' : board[pos] = 'O';
}
system("cls");
}
void
checkWin(Player &p1, Player &p2)
{
int i, j, k;
bool flag = false;
char first_symbol;
for (i = 0; i < 8; i++)
{
first_symbol = board[winlist[i].row[0]];
if ((first_symbol != 'X') && (first_symbol != 'O'))
{
flag = false;
continue;
}
flag = true;
for (j = 0; j < 3; j++)
{
if (first_symbol != board[winlist[i].row[j]])
{
flag = false;
break;
}
}
if (flag)
{
gameOn = 0;
if (first_symbol == 'X')
{
cout << "\t\t--------------------------" << endl;
cout << "\t\t " << p2.getName() << " WON " << endl;
cout << "\t\t--------------------------" << endl;
p1.won();
}
else
{
p2.won();
if (againstComputer)
{
cout << "\t\t------------------------" << endl;
cout << "\t\t| Computer WON |" << endl;
cout << "\t\t------------------------" << endl;
}
else
{
cout << "\t\t---------------------------" << endl;
cout << "\t\t " << p1.getName() << " WON " << endl;
cout << "\t\t---------------------------" << endl;
}
}
displayScore(p1, p2);
break;
}
}
}
void playtic(Player &p1, Player &p2)
{
system("Color AD");
char rematch = '\0';
int hand = 0;
gameOn = 1;
displayBoard();
while ((emptyCount > 0) && (gameOn != 0))
{
if (againstComputer)
hand == 1 ? computerInput() : playerInput(p2, p2);
else
hand == 1 ? playerInput(p1, p2) : playerInput(p2, p2);
hand = !hand;
displayBoard();
checkWin(p1, p2);
}
if (emptyCount <= 0)
{
cout << "\t\t-----------------------" << endl;
cout << "\t\t| No WINNER |" << endl;
cout << "\t\t-----------------------" << endl;
}
cout << endl;
//score calculate high
if (p1.getScore() > maxTictac)
{
maxTictac = p1.getScore();
tictacHunter = p2.getName();
cout << "\n\t\tCongo! " << tictacHunter << ", You just created a highest record of " << maxTictac << endl;
}
if (p2.getScore() > maxTictac)
{
maxTictac = p2.getScore();
tictacHunter = p1.getName();
cout << "\n\t\tCongo! " << tictacHunter << ", You just created a highest record of " << maxTictac << endl;
}
cout << "\n\n\t<------------------------------------------>" << endl;
cout << "\t\t\tRematch Y/N: ";
rematch = getche();
if ((rematch == 'Y') || (rematch == 'y'))
{
init();
playtic(p1, p2);
}
}
void displayScore(Player &p1, Player &p2)
{
cout << endl;
cout << "\t--------------------------------------------------------------------------------" << endl;
cout << "\t| |" << endl;
cout << "\t\t" << p2.getName() << " SCORE : " << (p1.getScore() - p2.getScore());
if (againstComputer)
cout << "\t\t" << p2.getName() << " : " << p1.getScore() << " \t\tComputer: " << p2.getScore() << " " << endl;
else
cout << "\t " << p2.getName() << " : " << p1.getScore() << " \t " << p1.getName() << " : " << p2.getScore() << endl;
cout << "\t| |" << endl;
cout << "\t--------------------------------------------------------------------------------" << endl;
}
public:
Game() : emptyCount{0}, gameOn{1}, againstComputer{0}
{
init();
winlist[0].row = new int[3]{0, 1, 2};
winlist[1].row = new int[3]{3, 4, 5};
winlist[2].row = new int[3]{6, 7, 8};
winlist[3].row = new int[3]{0, 3, 6};
winlist[4].row = new int[3]{1, 4, 7};
winlist[5].row = new int[3]{2, 5, 8};
winlist[6].row = new int[3]{0, 4, 8};
winlist[7].row = new int[3]{2, 4, 6};
}
void init()
{
gameOn = 1;
emptyCount = 0;
srand(time(0));
for (size_t i = 0; i < 10; i++)
{
emptyIndex[i] = 0;
board[i] = (i + 1) + '0';
emptyCount++;
}
emptyCount--;
}
void onePlayerGame()
{
//Creating Player
string yname;
cout << "\n\n\n\t\t-----------------------Name Creation---------------------" << endl;
cout << "\t\t<>Enter your name : ";
cin >> yname;
Player p(yname);
system("cls");
Player c("Computer");
cout << "\n\t\t-----------------------------------" << endl;
cout << "\t\t " << yname << ": X \t Computer: O" << endl;
cout << "\t\t-------------------------------------" << endl;
cout << endl;
againstComputer = 1;
playtic(c, p);
}
void twoPlayerGame()
{
//Creating Player
string yname, oname;
cout << "\n\n\n\t\t-----------------------Name Creation---------------------" << endl;
cout << "\t\t<>Enter your name : ";
cin >> yname;
Sleep(500);
Player p(yname);
cout << "\t\t<>Enter another player name : ";
cin >> oname;
Player c(oname);
Sleep(700);
system("cls");
cout << "\n\t\t-----------------------------------" << endl;
cout << "\t\t " << yname << ": X \t " << oname << ": O" << endl;
cout << "\n\t\t-----------------------------------" << endl;
cout << endl;
againstComputer = 0;
playtic(c, p);
}
};
void tictoctoi()
{
int ch;
system("cls");
system("Color AD");
cout << "\n\n\n\t\t -------------MENU-----------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 1. 1 Player game |" << endl;
cout << "\t\t| 2. 2 Player game |" << endl;
cout << "\t\t| 3. To exit |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t ----------------------------" << endl;
cout << endl;
cout << "\n\t\t<> Select an option : ";
char op = getche();
ch = (int)(op)-48;
cout << "\n\n\t<> Highest win in Tic Toc by " << tictacHunter << " won " << maxTictac << " times" << endl;
Sleep(1500);
loadingDesign();
system("cls");
system("Color AD");
switch (ch)
{
case 1:
{
Game *game = new Game;
game->init();
game->onePlayerGame();
}
break;
case 2:
{
Game *game = new Game;
game->init();
game->twoPlayerGame();
}
break;
case 3:
break;
default:
cout << "\n\t\t<-----OOPs Invalid Option! TRY AGAIN------>\n"
<< endl;
tictoctoi();
}
}
void tictacInstructions()
{
system("cls");
system("Color AD");
cout << "\n\n\n"
<< endl;
cout << "\t\t + Tic Tac Toe + " << endl;
cout << "\t\t - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -" << endl;
cout << "\t\t . There are two options " << endl;
cout << "\t\t > one for play with computer" << endl;
cout << "\t\t > another for play with nearby player" << endl;
cout << "\t\t . in both the cases player have to enter name" << endl;
cout << "\t\t . Both can see there score and chances with name" << endl;
cout << "\t\t . Highest score is calculating in backend" << endl;
cout << "\t\t - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -" << endl;
Sleep(1000);
}
// int main()
// {
// tictoctoi();
// return 0;
// }
/* <-------------------------- End Tic Tac Toi -------------------------------> */
/* <-------------------------- HnagMan Game -------------------------------> */
void PrintMessage(string message, bool printTop = true, bool printBottom = true)
{
if (printTop)
{
cout << "\t\t+---------------------------------+" << endl;
cout << "\t\t|";
}
else
{
cout << "\t\t|";
}
bool front = true;
for (int i = message.length(); i < 33; i++)
{
if (front)
{
message = " " + message;
}
else
{
message = message + " ";
}
front = !front;
}
cout << message.c_str();
if (printBottom)
{
cout << "|" << endl;
cout << "\t\t+---------------------------------+" << endl;
}
else
{
cout << "|" << endl;
}
}
void DrawHangman(int guessCount = 0)
{
if (guessCount >= 1)
PrintMessage("|", false, false);
else
PrintMessage("", false, false);
if (guessCount >= 2)
PrintMessage("|", false, false);
else
PrintMessage("", false, false);
if (guessCount >= 3)
PrintMessage("O", false, false);
else
PrintMessage("", false, false);
if (guessCount == 4)
PrintMessage("/ ", false, false);
if (guessCount == 5)
PrintMessage("/| ", false, false);
if (guessCount >= 6)
PrintMessage("/|\\", false, false);
else
PrintMessage("", false, false);
if (guessCount >= 7)
PrintMessage("|", false, false);
else
PrintMessage("", false, false);
if (guessCount == 8)
PrintMessage("/", false, false);
if (guessCount >= 9)
PrintMessage("/ \\", false, false);
else
PrintMessage("", false, false);
}
void PrintLetters(string input, char from, char to)
{
string s;
for (char i = from; i <= to; i++)
{
if (input.find(i) == string::npos)
{
s += i;
s += " ";
}
else
s += " ";
}
PrintMessage(s, false, false);
}
void PrintAvailableLetters(string taken)
{
PrintMessage("Available letters");
PrintLetters(taken, 'A', 'M');
PrintLetters(taken, 'N', 'Z');
}
bool PrintWordAndCheckWin(string word, string guessed)
{
bool won = true;
string s;
for (int i = 0; i < word.length(); i++)
{
if (guessed.find(word[i]) == string::npos)
{
won = false;
s += "_ ";
}
else
{
s += word[i];
s += " ";
}
}
PrintMessage(s, false);
return won;
}
int hangmancountword;
string loadHangedWord(string path)
{
int lineCount = 0;
string word;
vector<string> v;
ifstream reader(path);
if (reader.is_open())
{
while (std::getline(reader, word))
v.push_back(word);
int randomLine = rand() % v.size();
// int randomLine = 0;
hangmancountword = randomLine;
word = v.at(randomLine);
reader.close();
}
return word;
}
int TriesLeft(string word, string guessed)
{
int error = 0;
for (int i = 0; i < guessed.length(); i++)
{
if (word.find(guessed[i]) == string::npos)
error++;
}
return error;
}
void HangManGame()
{
system("cls");
system("Color 1F");
string hangmanplayer = "";
cout << "\n\n\n"
<< endl;
cout << "\t\t <> ---------------------------------------------- <>" << endl;
cout << "\t\t | |" << endl;
cout << "\t\t | H A N G M A N |" << endl;
cout << "\t\t | W O R D |" << endl;
cout << "\t\t | K I L L E R |" << endl;
cout << "\t\t | |" << endl;
cout << "\t\t <> ---------------------------------------------- <>" << endl;
cout << "\n\n"
<< endl;
cout << "\t\t<> Enter your name : ";
cin >> hangmanplayer;
cout << "\n\n\t<> Highest score made by " << hangmanHunter << " is : " << maxHnagmanScore << endl;
Sleep(1500);
char choice;
int score = 0;
Timer tHnag;
do
{
srand(time(0));
string guesses;
string wordToGuess;
wordToGuess = loadHangedWord("hangWords.txt");
int tries = 0;
int scoreChecker = 0;
bool win = false;
tHnag.reset(); // Timer starts
do
{
system("cls");
cout << "\n\n\n";
cout << "\t -------------------------------------------------\n"
<< endl;
cout << "\t\t <> " << hangmanplayer << "! your game is running " << endl;
cout << "\t\t <> your score is : " << score << "" << endl;
cout << "\n\t -------------------------------------------------\n\n"
<< endl;
PrintMessage("HANGMAN");
DrawHangman(tries);
PrintAvailableLetters(guesses);
PrintMessage("Guess the word");
win = PrintWordAndCheckWin(wordToGuess, guesses);
PrintMessage("Hint Below");
if (win)
{
score += 10;
break;
}
if (hangmancountword < 12)
{
PrintMessage("Month Name");
}
else if (hangmancountword < 19)
{
PrintMessage("Days Name");
}
else
{
PrintMessage("Social Media");
}
char x;
cout << "\n\t\t>> ";
x = getche();
// cin >> x;
if (guesses.find(x) == string::npos)
{
guesses += x;
if (scoreChecker < 5)
{
score += 1;
}
scoreChecker++;
}
else
{
score -= 2;
}
tries = TriesLeft(wordToGuess, guesses);
} while (tries < 10);
if (win)
{
cout << "\n"
<< endl;
cout << "\n\t\t" << hangmanplayer << ", Your current score is : " << score << endl;
PrintMessage("YOU WON!");
cout << "\n\t\tHurry!! You found word in " << tHnag.getTime() << "s Only" << endl;
}
else
{
cout << "\n"
<< endl;
cout << "\n\t\tyour current score is : " << score << endl;
PrintMessage("GAME OVER");
score -= 5;
cout << "\n\t\tOops! You Hanged in " << tHnag.getTime() << "s !!" << endl;
}
//highest score calculation
if (maxHnagmanScore < score)
{
maxHnagmanScore = score;
hangmanHunter = hangmanplayer;
cout << "\n\n"
<< endl;
cout << "\t\tCongo ^.^ " << hangmanHunter << ", Your achieved Highest Hang score " << endl;
}
cout << "\n\t\tdo you want to replay y/n : ";
choice = getche();
if (choice == 'Y' || choice == 'y')
{
score += 5;
}
else
{
cout << "\n\n\t\t <> ";
cout << hangmanplayer << ", you choose to quit this game" << endl;
cout << "\t\t <> your total score is : " << score << endl;
}
} while (choice == 'Y' || choice == 'y');
}
void hangmaninstruction()
{
system("cls");
system("Color A0");
cout << "\n\n\n\n"
<< endl;
cout << "\t\t . . . . . . . . . . . . . . " << endl;
cout << "\t\t | HangMan Rules |" << endl;
cout << "\t\t<------------------------------------------------------------------>" << endl;
cout << "\t\t . There are 10 trias only for the player" << endl;
cout << "\t\t . for one new try player get 1 score only for 5 times " << endl;
cout << "\t\t . After 5 trials for new key input player loose 2 scores " << endl;
cout << "\t\t . after find total word player get 10 scores" << endl;
cout << "\t\t . to continue with new game player get bonus score 5" << endl;
cout << "\t\t . after fail to find word in the game player loose 5 score " << endl;
cout << "\t\t<------------------------------------------------------------------>" << endl;
Sleep(1000);
}
/*
+---------------------------------+
| HANG MAN |
+---------------------------------+
| | |
| | |
| O |
| /|\ |
| | |
| / \ |
| +----------+ |
| | | |
+---------------------------------+
| Available letters |
+---------------------------------+
| A B C D E F G H I J K L M |
| N O P Q R S T U V W X Y Z |
+---------------------------------+
| Guess the word |
+---------------------------------+
| _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
+---------------------------------+
>
*/
/* <-------------------------- End HangMan Game -------------------------------> */
/* <------------------------- Casino number gussing game -------------------> */
void kasinorules();
void kasinogame()
{
system("Color 5F");
system("cls");
string playerName = "";
int amount; // hold player's balance amount
int bettingAmount;
int guess;
int dice; // hold computer generated number
char choice;
int usedMoney; // for calculate won money using this
srand(time(0)); // "Seed" the random generator
cout << "\t:..................................:" << endl;
cout << "\t-----------------------------------" << endl;
cout << "\t| |" << endl;
cout << "\t| CASINO |" << endl;
cout << "\t| GAME |" << endl;
cout << "\t| |" << endl;
cout << "\t------------------------------------" << endl;
cout << "\t:..................................:" << endl;
Sleep(500);
cout << "\n\n\tEnter Your Name : ";
cin >> playerName;
do
{
cout << "\n\n\tEnter Deposit amount to play game : Rs.";
cin >> amount;
usedMoney = amount;
if (amount < 10)
{
cout << "\n\tYou have too low money! Enter again to play" << endl;
}
} while (amount < 10);
cout << "\n\n\t<> Exclusive winner " << casinoHunter << " won : " << maxCasinoWin << "Rs." << endl;
int moneyLeft = amount; //for calculate total lose or gain
Sleep(1500);
system("cls");
cout << "\n\n\n";
kasinorules();
/*time to watch */
Sleep(3000);
/*end time to watch */
int fwin = 0;
do
{
system("Color 4E");
system("cls");
cout << "\n\n\n\tYour current balance is Rs. " << amount << "\n";
Sleep(700);
// Get player's betting amount
do
{
cout << "\n\n\n\t" << playerName << ", enter money to bet : Rs.";
cin >> bettingAmount;
if (bettingAmount > amount)
cout << "\n\tYour betting amount is more than your current balance\n"
<< "\n\tRe-enter data\n ";
} while (bettingAmount > amount);
/* -----------start offer boxes---------- */
int newLuck1 = rand() % 9 + 1;
int newLuck2 = rand() % 9 + 1;
gotoxy(WIN_WIDTH + 5, 5);
cout << ".___________________________________.";
gotoxy(WIN_WIDTH + 5, 6);
cout << "| Extra offer pack"
<< " |";
gotoxy(WIN_WIDTH + 5, 7);
cout << "| 1. lucky draw " << newLuck1 << " |";
gotoxy(WIN_WIDTH + 5, 8);
cout << "| 2. lucky draw " << newLuck2 << " |";
gotoxy(WIN_WIDTH + 5, 9);