-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
198 lines (148 loc) · 5.43 KB
/
game.cpp
File metadata and controls
198 lines (148 loc) · 5.43 KB
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
#include <string>
#include <ctime>
#include <cstdlib>
#include <string>
#include <iostream>
#include "cardgame.h"
#include "player.h"
#include "human.h"
#include "computer.h"
#include "blackjack.h"
#include "eCash.h"
using namespace std;
int main(){
human Player(player::card_max);
computer Computer(player::card_max);
blackjack game;
cout << endl;
game.welcome();
//seed rand
srand(time(NULL));
int* Phandcard = Player.cards;
int* Chandcard = Computer.cards;
int* Pactualcards = Player.actual_cards;
int* Cactualcards = Computer.actual_cards;
//1 for player 0 for dealer, so display_cards function can display the proper promotion
bool display_index;
static const int firstround_num_cards = 2;
eCash eCash;
eCash.login();
eCash.query();
int num_of_rounds;
cout << endl;
cout << endl;
cout << endl;
cout << "How many rounds you would like to play?" << endl;
while(!(cin >> num_of_rounds)){
cout << "error: ";
cin.clear();
cin.ignore(123, '\n');
}
cout << endl;
game.blackjack_welcome();
cout << endl;
for (int round_num = 1; round_num <= num_of_rounds; round_num++) {
eCash.change_bet();
int count = 0; //number of cards have been drawn so far
cout << endl;
cout << endl;
cout <<"################### Round : "<< round_num << " ######################"<< endl;
for(int b = 0; b < firstround_num_cards; b++){
//player cards
Player.get_card(count);
//computer cards
Computer.get_card(count);
count++;
}
//display each card drawn by the player
display_index = 1;
game.display_cards(display_index, Pactualcards, count);
//computer try to gain advantages by switching Ace value
Computer.choose_ace(count);
//showing information to player
Player.information_before_deciding_winner(Cactualcards, count);
//computer may call the game at this point
if (Computer.if_diff_10(Phandcard, count) == true){
cout << "Dealer have chose to stay." << endl;
cout << '\n';
cout << "Showing all cards..." << endl;
system("pause");
//writing in the value of the decider
cout << "Your sum is: " << game.get_sum(Phandcard,count) << endl;
display_index = 0;
game.display_cards(display_index, Cactualcards, count);
Computer.show_computer_cards(count);
int decider = game.decide_winner(game.get_sum(Phandcard,count),game.get_sum(Chandcard,count));
eCash.consume(decider);
//writing in the score
game.write_score(decider);
}
if (Computer.if_diff_10(Phandcard, count) == false ) {
//cout << '\n';
cout << "Dealer have chose to hit." << endl;
//check if sum == 21, hint is given if true
Player.checkif_21_hint(count);
//Change or switch another card or not, then rerun this process
string more_card; //more_card as the trigger word
more_card = Player.morecard_prompt(more_card);
cout << '\n';
//give more cards
while (more_card == "hit"){
//player cards
Player.get_card(count);
//computer cards
Computer.get_card(count);
count++;
//check if sum == 21, hint is given if true
Player.checkif_21_hint(count);
display_index = 1;
game.display_cards(display_index, Pactualcards, count);
more_card = "stay";
if (game.checkif_blow(Phandcard,count) == 0){
more_card = Player.morecard_prompt(more_card);
cout << '\n';
} else if (game.checkif_blow(Phandcard,count) == 1){
more_card = "stay";
} else if(Computer.computer_checkif_over_18(count) == "no")
more_card = "stay";
}
//computer try to gain advantages by switching Ace value
Computer.choose_ace(count);
Player.information_before_deciding_winner(Cactualcards ,count);
cout << "Showing all cards..." << endl;
system("pause");
display_index = 0;
game.display_cards(display_index, Cactualcards, count);
Computer.show_computer_cards(count);
int decider = game.decide_winner(game.get_sum(Phandcard,count),game.get_sum(Chandcard,count));
eCash.consume(decider);
if (eCash.get_money() < 0){
cout << "Game will terminate." << endl;
system("pause");
return 0;
}
game.write_score(decider);
}
game.refresh_card(Phandcard);
game.refresh_card(Chandcard);
if (round_num == num_of_rounds){
cout << "That was the last round, thank you for playing!" << endl;
system("pause");
}
if (round_num != num_of_rounds){
//cout << "################### ROUND BREAK ###################" << endl;
string prompt_4 = "Please enter 'next' to enter next round: ";
string word_4 = "next";
game.trigger(prompt_4, word_4);
cout << '\n';
cout << endl;
cout << endl;
}
}
game.print_score();
Player.~human();
Computer.~computer();
game.~blackjack();
game.refresh_carddeck();
return 0;
}