-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.cpp
More file actions
179 lines (154 loc) · 3.83 KB
/
Box.cpp
File metadata and controls
179 lines (154 loc) · 3.83 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
/*
* Copyright 2013 James O'Hea
*
* This file is part of Blackjack.
*
* Blackjack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Blackjack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Blackjack. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Box.hpp"
/* Constructor for the Box object */
Box::Box(Player *NewOwner, const bool Split)
{
Owner = NewOwner;
Bet = 0;
HandValue = 0;
Insurance = 0;
AcesHeld = 0;
UsingInsurance = false;
Surrended = false;
SplitBox = Split;
}
/* Return the name of the owner of the box */
string Box::GetOwner() const
{
return Owner->GetName();
}
/* Return a pointer to the owner of the box */
Player* Box::GetOwnerObj() const
{
return Owner;
}
/* Return whether the box is used for split card play */
bool Box::CheckSplit() const
{
return SplitBox;
}
/* Return the size of box owner's stack */
float Box::CountStack() const
{
return Owner->CountStack();
}
/* Return the bet placed on the current box */
const float Box::CountBet() const
{
return Bet;
}
/* Place a bet on the current box */
void Box::PlaceBet(const float NewBet)
{
Owner->PlaceBet(NewBet);
Bet += NewBet;
}
/* Surrender the current hand */
void Box::Surrender()
{
Surrended = true;
Owner->AddToStack(Bet/2);
}
/* Check to see if the current box surrended */
const bool Box::CheckSurrended() const
{
return Surrended;
}
/* Check if the current box has taken insurance */
const bool Box::CheckInsurance() const
{
return UsingInsurance;
}
/* Place insurance on the current box */
void Box::PlaceInsurance()
{
Owner->PlaceBet(Bet / 2);
Insurance = (Bet / 2);
UsingInsurance = true;
}
/* Receive an insurance bet pay out */
void Box::ReceiveInsurance()
{
Owner->AddToStack(Bet + Insurance);
cout << " Wins insurance bet and collects " << Insurance << " from the dealer" << endl;
Insurance = 0;
}
/* Retrieve original bet after a push */
void Box::RetrieveBet()
{
Owner->AddToStack(Bet);
cout << " Bet of " << Bet << " returned" << endl;
}
/* Receive winnings of a bet - covers blackjack and 'normal' wins*/
void Box::ReceiveWinnings()
{
/* A blackjack win */
if(CheckHand() == 21 and Hand.size() == 2 and SplitBox == false)
{
Owner->AddToStack(Bet + Bet + (Bet/2));
cout << " Wins bet and collects " << (Bet + (Bet/2)) << " from the dealer" << endl;
}
/* A non-blackjack win */
else
{
Owner->AddToStack(Bet + Bet);
cout << " Wins bet and collects " << Bet << " from the dealer" << endl;
}
}
/* Return the split card to be moved and reduced the current hand value */
const Card Box::MoveSplitCard()
{
Card TempCard;
TempCard = Hand.at(1);
HandValue -= Hand.at(1).GetValue();
Hand.pop_back();
/* AcesHeld must be reassessed after a split */
string CompareString = Hand.front().GetName();
if (CompareString.compare("Ace") == 0)
{
AcesHeld = 1;
HandValue = 11;
}
return TempCard;
}
/* Reset all flags of the current box */
void Box::ReturnCards()
{
Hand.clear();
HandValue = 0;
AcesHeld = 0;
Bet = 0;
Insurance = 0;
UsingInsurance = false;
Surrended = false;
}
/* Declare the status of the current hand */
void Box::Status() const
{
cout << Owner->GetName();
/* If the current box is the result of a split hand, display a different message */
if(CheckSplit() == true)
{
cout << " (Split Hand)";
}
cout << ": (" << Owner->CountStack() << " in your stack, " << Bet << " on the table) You are holding: " << endl << endl;
ListHand();
StatusResult();
}