-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
148 lines (121 loc) · 2.59 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
#include "header.h"
int main (int argc, char * const argv[]) {
// insert code here...this is the main function, it creates a shuffled deck and begin the story
srand(time(NULL));
Deck deck1=Deck();
deck1.shuffle();
char ch='y';
int money=100;
int moneyevolve[100]={money};
int moneycount=0;
cout << "Welcome to BlackJack!\n";
while ((ch=='y' || ch=='Y') && (money>0)) {
Hand gnomehand=Hand();
Hand omehand=Hand();
gnomehand.takeacard(deck1);
omehand.takeacard(deck1);
gnomehand.takeacard(deck1);
omehand.takeacard(deck1);
cout << "You have $"<< money;
cout << endl;
int bet=money+10;
while (bet>money) {
cout << "Please input your bet as a multiple of 10: \n";
cin >> bet;
}
money-=bet;
cout << "Now you have $"<<money<<endl;
omehand.display(1);
cout << "Your hand: ";
gnomehand.display(2);
int gnomesum,black=0;
gnomesum=gnomehand.sumup();
if (gnomesum==BLACKJACK) {
black=1;
}
else{
cout << "Double down?y/n?\n";
char d;
cin >> d;
if (d=='y' || d=='Y')
{
money-=bet;
bet*=2;
gnomehand.takeacard(deck1);
gnomehand.displaynew();
}
else {
cout << "hit me? y/n?\n";
char c;
cin >> c;
while (c=='y' || c=='Y') {
gnomehand.takeacard(deck1);
gnomehand.displaynew();
if (gnomehand.sumup()>=BLACKJACK) {
c='n';
}
else
{cin >>c;}
}
}
}
gnomesum=gnomehand.sumup();
cout << "Your sum is :"<< gnomesum<<endl;
if (black==1) {
cout << "Congratulations! You have blackjack!\n";
} else if (gnomesum>BLACKJACK) {
cout << "Busted! ChouChou!\n";
}
cout << "Dealers full hand: ";
omehand.display(2);
int omesum,omeblack=0;
omesum=omehand.sumup();
if (omesum==BLACKJACK) {
omeblack=1;
}
else
{while (omesum<=16) {
omehand.takeacard(deck1);
omehand.displaynew();
omesum=omehand.sumup();
}
}
cout << "Dealer's sum: "<< omesum<<endl;
if (omeblack==1) {
cout << "Dealer has blackjack!\n";
} else if (omesum>BLACKJACK) {
cout << "Dealer busted!\n";
}
if (black==1 && omeblack==1 ) {
money+=bet;
cout << "Both blackjack! Money back!\n";
}
else if (black==1)
{
money+=bet*5/2;
cout << "Awesome! Blackjack money!\n";
}
else if (gnomesum<=BLACKJACK && omesum>BLACKJACK)
{
money+=bet*2;
cout << "I win!\n";
}
else if (gnomesum<=BLACKJACK && gnomesum>omesum)
{
money+=bet*2;
cout << "I win!\n";
}
cout << "Now you have $"<< money<< endl;
moneycount++;
moneyevolve[moneycount]=money;
cout << "Continue?y/n\n";
cin >> ch;
deck1.needtoshuffle();
}
cout << "Thanks for playing! \n";
for (int i=0; i<=moneycount; i++) {
cout << moneyevolve[i]<<" ";
}
cout << endl;
return 0;
}