-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
940 lines (775 loc) · 30 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
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
#include <iostream>
#include <vector>
#include <random>
#include <array>
#include <algorithm>
#include <thread>
#include <iomanip>
//-----[[ COLOUR CONTROL ]]-----//
#define RESET "\x1b[0m"
#define RED "\x1b[31m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define GREEN "\x1b[32m"
#define CLEAR "\033[2J\033[1;1H"
//-----[[ SYMBOLS ]]-----//
#define SPADE "\u2660"
#define HEART "\u2665"
#define DIAMOND "\u2666"
#define CLUB "\u2663"
#define CHERRY "\U0001F352"
#define LEMON "\U0001F34B"
#define ORANGE "\U0001F34A"
#define BELL "\U0001F514"
#define STAR "\u2B50"
#define SEVEN "7"
#define BAR "▃"
struct Stats {
int wins = 0;
int losses = 0;
int draws = 0;
double win_rate() const {
return (wins + losses + draws) ? (double) wins / (wins + losses + draws) * 100 : 0.0;
}
double loss_rate() const {
return (wins + losses + draws) ? (double) losses / (wins + losses + draws) * 100 : 0.0;
}
double draw_rate() const {
return (wins + losses + draws) ? (double) draws / (wins + losses + draws) * 100 : 0.0;
}
};
enum class Outcome {
WIN,
LOSE,
DRAW
};
namespace games {
struct Card {
int value;
std::string suit;
std::string rank;
};
const char *card_template = R"(
┌────────┐
│%s │
│ │
│ %s │
│ │
│ %s│
└───%s───┘
)";
const char *hidden_card_template = R"(
┌────────┐
│░░░░░░░░│
│░░░░░░░░│
│░░░░░░░░│
│░░░░░░░░│
│░░░░░░░░│
└────────┘
)";
namespace baccarat {
const std::vector<Card> valid_cards = {
{2, SPADE, "2"}, {3, SPADE, "3"}, {4, SPADE, "4"}, {5, SPADE, "5"}, {6, SPADE, "6"},
{7, SPADE, "7"}, {8, SPADE, "8"}, {9, SPADE, "9"}, {10, SPADE, "10"}, {0, SPADE, "J"},
{0, SPADE, "Q"}, {0, SPADE, "K"}, {1, SPADE, "A"},
{2, HEART, "2"}, {3, HEART, "3"}, {4, HEART, "4"}, {5, HEART, "5"}, {6, HEART, "6"},
{7, HEART, "7"}, {8, HEART, "8"}, {9, HEART, "9"}, {10, HEART, "10"}, {0, HEART, "J"},
{0, HEART, "Q"}, {0, HEART, "K"}, {1, HEART, "A"},
{2, DIAMOND, "2"}, {3, DIAMOND, "3"}, {4, DIAMOND, "4"}, {5, DIAMOND, "5"}, {6, DIAMOND, "6"},
{7, DIAMOND, "7"}, {8, DIAMOND, "8"}, {9, DIAMOND, "9"}, {10, DIAMOND, "10"}, {0, DIAMOND, "J"},
{0, DIAMOND, "Q"}, {0, DIAMOND, "K"}, {1, DIAMOND, "A"},
{2, CLUB, "2"}, {3, CLUB, "3"}, {4, CLUB, "4"}, {5, CLUB, "5"}, {6, CLUB, "6"},
{7, CLUB, "7"}, {8, CLUB, "8"}, {9, CLUB, "9"}, {10, CLUB, "10"}, {0, CLUB, "J"},
{0, CLUB, "Q"}, {0, CLUB, "K"}, {1, CLUB, "A"}
};
std::vector<Card> deck;
std::string format_value(int value) {
if (value < 10) {
return std::to_string(value) + "─";
}
return std::to_string(value);
}
std::vector<std::string> create_card(const Card& card) {
std::array<char, 256> card_buffer;
std::string val = format_value(card.value);
std::string top_rank = card.rank;
std::string bottom_rank = card.rank;
if (card.rank.length() == 1) {
top_rank += " ";
bottom_rank = " " + bottom_rank;
}
std::snprintf(
card_buffer.data(), card_buffer.size(),
card_template,
top_rank.c_str(), card.suit.c_str(), bottom_rank.c_str(), val.c_str());
std::vector<std::string> card_lines;
std::string card_str(card_buffer.data());
size_t pos = 0;
std::string line;
while ((pos = card_str.find('\n')) != std::string::npos) {
line = card_str.substr(0, pos);
if (!line.empty()) {
card_lines.push_back(line);
}
card_str.erase(0, pos + 1);
}
if (!card_str.empty()) {
card_lines.push_back(card_str);
}
return card_lines;
}
Card draw_card() {
Card card = deck.back();
deck.pop_back();
return card;
}
void shuffle_deck() {
std::random_device rd;
std::mt19937 g(rd());
deck = valid_cards;
std::shuffle(deck.begin(), deck.end(), g);
}
void render_cards(const std::vector<Card>& cards) {
if (cards.empty()) return;
std::vector<std::vector<std::string>> all_card_lines;
for (size_t i = 0; i < cards.size(); ++i) {
all_card_lines.push_back(create_card(cards[i]));
}
for (size_t line = 0; line < all_card_lines[0].size(); ++line) {
for (const auto& card_lines : all_card_lines) {
std::cout << card_lines[line] << " ";
}
std::cout << std::endl;
}
}
int calculate_score(const std::vector<Card>& hand) {
int score = 0;
for (const auto& card : hand) {
score += card.value;
}
return score % 10;
}
Outcome game_main() {
std::cout << CLEAR;
std::cout
<< YELLOW << "[?] Shuffling the deck...\n" << RESET;
shuffle_deck();
std::cout
<< GREEN << "[i] The deck has been shuffled!\n" << RESET
<< std::endl;
std::vector<Card> banker_hand = {draw_card(), draw_card()};
std::vector<Card> player_hand = {draw_card(), draw_card()};
bool player_turn = true;
while (player_turn) {
int choice;
std::cout
<< "What would you like to do?\n"
<< YELLOW << "[1] " << RESET << "Bet on Player\n"
<< YELLOW << "[2] " << RESET << "Bet on Banker\n"
<< YELLOW << "[3] " << RESET << "Bet on Tie\n"
<< BLUE << "> " << RESET;
std::cin >> choice;
std::cout << CLEAR;
switch(choice) {
case 1: {
std::cout
<< RED << "Banker's Hand: \n";
render_cards(banker_hand);
std::cout
<< GREEN << "Player's Hand: \n";
render_cards(player_hand);
int player_score = calculate_score(player_hand);
int banker_score = calculate_score(banker_hand);
if (player_score > banker_score) {
std::cout
<< GREEN << "You win! Your score is " << BLUE << player_score
<< GREEN << " and the banker's score is " << BLUE << banker_score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
} else {
std::cout
<< RED << "You lost. Your score is " << BLUE << player_score
<< RED << " and the banker's score is " << BLUE << banker_score
<< RED << ".\n" << RESET;
return Outcome::LOSE;
}
break;
}
case 2: {
std::cout
<< RED << "Banker's Hand: \n";
render_cards(banker_hand);
std::cout
<< GREEN << "Player's Hand: \n";
render_cards(player_hand);
int player_score = calculate_score(player_hand);
int banker_score = calculate_score(banker_hand);
if (banker_score > player_score) {
std::cout
<< GREEN << "You win! Your score is " << BLUE << player_score
<< GREEN << " and the banker's score is " << BLUE << banker_score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
} else {
std::cout
<< RED << "You lost. Your score is " << BLUE << player_score
<< RED << " and the banker's score is " << BLUE << banker_score
<< RED << ".\n" << RESET;
return Outcome::LOSE;
}
break;
}
case 3: {
std::cout
<< RED << "Banker's Hand: \n";
render_cards(banker_hand);
std::cout
<< GREEN << "Player's Hand: \n";
render_cards(player_hand);
int player_score = calculate_score(player_hand);
int banker_score = calculate_score(banker_hand);
if (player_score == banker_score) {
std::cout
<< GREEN << "You win! Your score is " << BLUE << player_score
<< GREEN << " and the banker's score is " << BLUE << banker_score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
} else {
std::cout
<< RED << "You lost. Your score is " << BLUE << player_score
<< RED << " and the banker's score is " << BLUE << banker_score
<< RED << ".\n" << RESET;
return Outcome::LOSE;
}
break;
}
default: {
std::cout
<< RED << "Invalid choice. Please try again.\n" << RESET;
break;
}
}
}
return Outcome::LOSE;
}
}
namespace slots {
const char *slot_template = R"(
┌─────┬─────┬─────┐
│ %s │ %s │ %s │
└─────┴─────┴─────┘
)";
void print_reels(const std::string &reel1, const std::string &reel2, const std::string &reel3) {
char buffer[256];
snprintf(buffer, sizeof(buffer), slot_template, reel1.c_str(), reel2.c_str(), reel3.c_str());
std::cout << buffer;
}
std::vector<std::vector<std::string>> make_reels() {
std::random_device rd;
std::mt19937 g(rd());
std::vector<std::vector<std::string>> reels = {
{CHERRY, LEMON, BELL, ORANGE, STAR, SEVEN, BAR},
{CHERRY, LEMON, BELL, ORANGE, STAR, SEVEN, BAR},
{CHERRY, LEMON, BELL, ORANGE, STAR, SEVEN, BAR}
};
for (auto &reel : reels) {
std::shuffle(reel.begin(), reel.end(), g);
}
return reels;
}
Outcome game_main() {
std::vector<std::vector<std::string>> reels = make_reels();
for (size_t i = 0; i < reels[0].size(); ++i) {
print_reels(reels[0][i], reels[1][i], reels[2][i]);
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
return Outcome::LOSE;
}
}
namespace blackjack {
const std::vector<Card> valid_cards = {
{2, SPADE, "2"},
{3, SPADE, "3"},
{4, SPADE, "4"},
{5, SPADE, "5"},
{6, SPADE, "6"},
{7, SPADE, "7"},
{8, SPADE, "8"},
{9, SPADE, "9"},
{10, SPADE, "10"},
{10, SPADE, "J"},
{10, SPADE, "Q"},
{10, SPADE, "K"},
{2, HEART, "2"},
{3, HEART, "3"},
{4, HEART, "4"},
{5, HEART, "5"},
{6, HEART, "6"},
{7, HEART, "7"},
{8, HEART, "8"},
{9, HEART, "9"},
{10, HEART, "10"},
{10, HEART, "J"},
{10, HEART, "Q"},
{10, HEART, "K"},
{2, DIAMOND, "2"},
{3, DIAMOND, "3"},
{4, DIAMOND, "4"},
{5, DIAMOND, "5"},
{6, DIAMOND, "6"},
{7, DIAMOND, "7"},
{8, DIAMOND, "8"},
{9, DIAMOND, "9"},
{10, DIAMOND, "10"},
{10, DIAMOND, "J"},
{10, DIAMOND, "Q"},
{10, DIAMOND, "K"},
{2, CLUB, "2"},
{3, CLUB, "3"},
{4, CLUB, "4"},
{5, CLUB, "5"},
{6, CLUB, "6"},
{7, CLUB, "7"},
{8, CLUB, "8"},
{9, CLUB, "9"},
{10, CLUB, "10"},
{10, CLUB, "J"},
{10, CLUB, "Q"},
{10, CLUB, "K"},
{11, SPADE, "A"},
{11, HEART, "A"},
{11, DIAMOND, "A"},
{11, CLUB, "A"}
};
std::vector<Card> deck;
void shuffle_deck() {
std::random_device rd;
std::mt19937 g(rd());
deck = valid_cards;
std::shuffle(deck.begin(), deck.end(), g);
}
Card draw_card() {
Card card = deck.back();
deck.pop_back();
return card;
}
int calculate_score(std::vector<Card> &hand) {
int score = 0;
int ace_count = 0;
for (auto &card : hand) {
score += card.value;
if (card.rank == "A") ace_count++;
}
while (score > 21 && ace_count > 0) {
score -= 10;
ace_count--;
}
return score;
}
std::string format_value(int value) {
if (value < 10) {
return std::to_string(value) + "─";
}
return std::to_string(value);
}
std::vector<std::string> create_card(const Card& card) {
std::array<char, 256> card_buffer;
std::string val = format_value(card.value);
std::string top_rank = card.rank;
std::string bottom_rank = card.rank;
if (card.rank.length() == 1) {
top_rank += " ";
bottom_rank = " " + bottom_rank;
}
std::snprintf(
card_buffer.data(), card_buffer.size(),
card_template,
top_rank.c_str(), card.suit.c_str(), bottom_rank.c_str(), val.c_str());
std::vector<std::string> card_lines;
std::string card_str(card_buffer.data());
size_t pos = 0;
std::string line;
while ((pos = card_str.find('\n')) != std::string::npos) {
line = card_str.substr(0, pos);
if (!line.empty()) {
card_lines.push_back(line);
}
card_str.erase(0, pos + 1);
}
if (!card_str.empty()) {
card_lines.push_back(card_str);
}
return card_lines;
}
std::vector<std::string> create_hidden_card() {
std::vector<std::string> hidden_card_lines;
std::string hidden_card_str(hidden_card_template);
size_t pos = 0;
std::string line;
while ((pos = hidden_card_str.find('\n')) != std::string::npos) {
line = hidden_card_str.substr(0, pos);
if (!line.empty()) {
hidden_card_lines.push_back(line);
}
hidden_card_str.erase(0, pos + 1);
}
if (!hidden_card_str.empty()) {
hidden_card_lines.push_back(hidden_card_str);
}
return hidden_card_lines;
}
void render_cards(const std::vector<Card>& cards, bool first_round = false) {
if (cards.empty()) return;
std::vector<std::vector<std::string>> all_card_lines;
for (size_t i = 0; i < cards.size(); ++i) {
if (first_round && i == 1) {
all_card_lines.push_back(create_hidden_card());
} else {
all_card_lines.push_back(create_card(cards[i]));
}
}
for (size_t line = 0; line < all_card_lines[0].size(); ++line) {
for (const auto& card_lines : all_card_lines) {
std::cout << card_lines[line] << " ";
}
std::cout << std::endl;
}
}
Outcome game_main() {
std::cout << CLEAR;
int dealer_score;
int player_score;
const std::string notice = "Dealer must stand on 17 and must draw to 16.";
std::cout
<< YELLOW << "[?] Shuffling the deck...\n" << RESET;
shuffle_deck();
std::cout
<< GREEN << "[i] The deck has been shuffled!\n" << RESET
<< std::endl;
std::vector<Card> dealer_hand = {draw_card(), draw_card()};
std::vector<Card> player_hand = {draw_card(), draw_card()};
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand, true);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
std::cout
<< BLUE << "\n" << notice << "\n" << RESET
<< std::endl;
bool player_turn = (calculate_score(player_hand) != 21);
while (player_turn) {
int choice;
std::cout
<< "What would you like to do?\n"
<< YELLOW << "[1] " << RESET << "Hit\n"
<< YELLOW << "[2] " << RESET << "Stand\n"
<< BLUE << "> " << RESET;
std::cin >> choice;
switch (choice) {
case 1: {
std::cout << CLEAR;
player_hand.push_back(draw_card());
int score = calculate_score(player_hand);
if (score == 21) {
player_turn = false;
break;
}
if (score > 21) {
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
std::cout
<< RED << "\n\nYou busted! Your score is "
<< BLUE << score
<< RED << ".\n" << RESET;
return Outcome::LOSE;
}
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand, true);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
break;
}
case 2: {
player_turn = false;
break;
}
default: {
std::cout
<< RED << "Invalid choice. Please try again.\n" << RESET;
break;
}
}
}
player_score = calculate_score(player_hand);
dealer_score = calculate_score(dealer_hand);
if (player_score == 21 && dealer_score != 21) {
std::cout << CLEAR;
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
std::cout
<< GREEN << "\n\nYou win! Your score is "
<< BLUE << player_score
<< GREEN << " and the dealer's score is "
<< BLUE << dealer_score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
}
bool dealer_turn = true;
while (dealer_turn) {
std::cout << CLEAR;
int score = calculate_score(dealer_hand);
if (score >= 17) {
dealer_turn = false;
continue;
} else {
dealer_hand.emplace_back(draw_card());
score = calculate_score(dealer_hand);
if (score > 21) {
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
std::cout
<< GREEN << "\n\nYou win! Dealer busted! Their score is "
<< BLUE << score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
}
}
}
std::cout
<< RED << "Dealer's Hand:\n";
render_cards(dealer_hand);
std::cout
<< GREEN << "\nYour Hand:\n";
render_cards(player_hand);
player_score = calculate_score(player_hand);
dealer_score = calculate_score(dealer_hand);
if (player_score > dealer_score) {
std::cout
<< GREEN << "\n\nYou win! Your score is "
<< BLUE << player_score
<< GREEN << " and the dealer's score is "
<< BLUE << dealer_score
<< GREEN << ".\n" << RESET;
return Outcome::WIN;
} else if (dealer_score > player_score) {
std::cout
<< RED << "\n\nYou lost. Your score is "
<< BLUE << player_score
<< RED << " and the dealer's score is "
<< BLUE << dealer_score
<< RED << ".\n" << RESET;
return Outcome::LOSE;
} else if (dealer_score == player_score) {
std::cout
<< GREEN << "\n\nIt's a tie! Your score is "
<< BLUE << player_score
<< GREEN << " and the dealer's score is "
<< BLUE << dealer_score
<< GREEN << ".\n" << RESET;
return Outcome::DRAW;
}
return Outcome::LOSE;
}
}
namespace guess_the_number {
Outcome game_main() {
std::cout << CLEAR;
short winning_number;
short guess;
std::cout
<< RED << "====================================\n" << RESET
<< RED << "|| Welcome to Guess the Number! ||\n" << RESET
<< RED << "====================================\n" << RESET
<< std::endl;
std::cout
<< YELLOW << "[?] Getting the game ready for you...\n" << RESET;
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<short> dist(0, 100);
winning_number = dist(rng);
std::cout
<< GREEN << "[i] The game is ready!\n" << RESET
<< std::endl;
std::cout
<< "What is your guess? (Max: 100)\n"
<< BLUE << "> " << RESET;
std::cin >> guess;
std::cout
<< BLUE << "You guessed: " << RESET
<< guess << std::endl;
if (guess == winning_number) {
std::cout
<< GREEN << "\n\nCongratulations! You guessed the number!\n" << RESET;
return Outcome::WIN;
} else {
std::cout
<< RED << "\n\nYou lost. "
<< GREEN << "The winning number was "
<< BLUE << winning_number
<< GREEN << ".\n" << RESET;
return Outcome::LOSE;
}
}
}
}
const std::vector<std::string> menu = {
"Guess the Number",
"Roulette",
"Slots",
"Blackjack",
"Baccarat",
"View Winrate",
"Exit"
};
int get_menu_choice(const std::vector<std::string> &choices) {
std::cout
<< RED << "==============================\n" << RESET
<< RED << "|| Welcome to gambling! ||\n" << RESET
<< RED << "==============================\n" << RESET;
int choice;
int idx = 0;
for (const std::string &option : choices) {
idx++;
std::cout
<< YELLOW << "[" << idx << "] " << RESET
<< option << std::endl;
}
std::cout
<< "What would you like to play? \n"
<< BLUE << "> " << RESET;
std::cin >> choice;
if (choice < 1 || choice > choices.size()) {
std::cout << CLEAR;
return get_menu_choice(choices);
}
return choice;
}
void await_resume() {
std::cout
<< BLUE << "Press <ENTER> to continue playing...\n" << RESET;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
}
int main() {
Stats stats;
while (true) {
std::cout << CLEAR;
int choice = get_menu_choice(menu);
switch (choice) {
case 1: {
switch (games::guess_the_number::game_main()) {
case Outcome::WIN: {
stats.wins++;
break;
}
case Outcome::LOSE: {
stats.losses++;
break;
}
case Outcome::DRAW: {
stats.draws++;
break;
}
}
await_resume();
break;
}
case 2: {
break;
}
case 3: {
switch (games::slots::game_main()) {
case Outcome::WIN: {
stats.wins++;
break;
}
case Outcome::LOSE: {
stats.losses++;
break;
}
case Outcome::DRAW: {
stats.draws++;
break;
}
}
await_resume();
break;
}
case 4: {
switch (games::blackjack::game_main()) {
case Outcome::WIN: {
stats.wins++;
break;
}
case Outcome::LOSE: {
stats.losses++;
break;
}
case Outcome::DRAW: {
stats.draws++;
break;
}
}
await_resume();
break;
}
case 5: {
switch (games::baccarat::game_main()) {
case Outcome::WIN: {
stats.wins++;
break;
}
case Outcome::LOSE: {
stats.losses++;
break;
}
case Outcome::DRAW: {
stats.draws++;
break;
}
}
await_resume();
break;
}
case 6: {
std::cout << CLEAR;
std::cout
<< RED << "==============================\n" << RESET
<< RED << "|| Session Statistics ||\n" << RESET
<< RED << "==============================\n" << RESET;
std::cout
<< GREEN << "Wins: " << stats.wins << " (" << std::fixed << std::setprecision(2) << stats.win_rate() << "%)\n" << RESET
<< RED << "Losses: " << stats.losses << " (" << std::fixed << std::setprecision(2) << stats.loss_rate() << "%)\n" << RESET
<< YELLOW << "Draws: " << stats.draws << " (" << std::fixed << std::setprecision(2) << stats.draw_rate() << "%)\n" << RESET;
await_resume();
break;
}
case 7: {
std::cout
<< CLEAR
<< GREEN << "\nThanks for playing! Goodbye!\n" << RESET;
return EXIT_SUCCESS;
}
default: {
std::cout
<< RED << "Invalid choice. Please try again.\n" << RESET;
break;
}
}
}
}