-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
134 lines (94 loc) · 3.05 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
#include "Dealer.h"
#include "Player.h"
#include <iostream>
bool Is_the_game_ovah (Game_Participant* x, int player);
bool Did_anyone_win (Player* arrayOfPlayers[], int arrayLength);
int main() {
Dealer dealer;
int numberOfPlayers;
int varTemp;
bool gameOvah;
char playerOption;
std::cout << "Hello and welcome to my table, where we will be playing standard BlackJack" << std::endl;
std::cout << "How many players are at the table? " << std::endl;
std::cin >> numberOfPlayers;
Player* player (arrayOfPlayers[]);
// Loop creates the new players and takes their wagers
for (int i = 0; i < numberOfPlayers; i++) {
std::cout << "Please place your game wagers now " << i + 1 << std::endl;
arrayOfPlayers[i] = new Player();
std::cin >> varTemp;
arrayOfPlayers[i] -> setMyWager(varTemp);
}
// Now the players will get their first 2 cards
for (int i = 0; i < numberOfPlayers; i++) {
dealer.cardsDealt (arrayOfPlayers[i], 2, i + 1);
std::cout << std::endl;
// Dealer gets his initial 2 cards here
dealer.cardsDealt (&dealer, 2, 0);
std::cout << std::endl;
}
while (!gameOvah) {
// Here we check to see if any player has won
for (int i = 0; i < numberOfPlayers; i++) {
if (Is_the_game_ovah (arrayOfPlayers[i], i + 1)) {
gameOvah = true;
continue;
}
}
// Here we check to see if the dealer has won the hand
if (Is_the_game_ovah (&dealer, 0)) {
gameOvah = true;
continue;
}
for (int i = 0; i < numberOfPlayers; i++) {
if (arrayOfPlayers[i] -> getiBust()) {
i++;
continue;
}
std::cout << "Your turn player " << i + 1 << "Choose 'H' to take a hit, or 'S' to stand!" << std::endl;
std::cin >> playerOption;
if (playerOption == 'H') {
dealer.cardsDealt (arrayOfPlayers[i], 1, i + 1);
}
}
if (Did_anyone_win (arrayOfPlayers, numberOfPlayers)) {
gameOvah = true;
continue;
}
// Here the dealer gets his turn to play his hand. He has to hit on 16 and stand on 17
if (dealer.getTotalPoints() < 17) {
dealer.cardsDealt (&dealer, 1, 0);
std::cout << std::endl;
}
return 0;
}
bool Is_the_game_ovah (Game_Participant* x, int player) {
// He we check if the person that is playing the game has won the hand
if (x -> getGameStatus()) {
std::cout << "Player" << player << "has won the hand. Congratulations" << x->getPointTotal() << std::endl;
return true;
}
if (player == 0 && x-> getiBust()) {
std::cout << "The dealer has bust" << "win" << x -> getPointTotal() << std::endl;
}
return false;
}
bool Did_anyone_win (player* arrayOfPlayers[], int arrayLength) {
for (int i = 0; i < arrayLength; i++) {
// Here we check to see if anyone is still in the game
if (arrayOfPlayers[i] -> getTotalPoints(), 21) {
return false;
}
return true;
}
}
}
bool Is_the_game_over(Game_Participant * x, int player)
{
return false;
}
bool Did_anyone_win(Player * arrayOfPlayers[], int arrayLength)
{
return false;
}