-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand.cpp
More file actions
74 lines (69 loc) · 1.3 KB
/
hand.cpp
File metadata and controls
74 lines (69 loc) · 1.3 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
# include "hand.h"
Hand::Hand(int& playerUniqueID, int& _handIdx)
: idxBelongsToPlayer(playerUniqueID), handIdx(_handIdx)
{
;
}
int Hand::getScore() const {
return score;
}
int Hand::getIdxBelongsToPlayer() const {
return idxBelongsToPlayer;
}
bool Hand::getisHandWinner() const {
return isHandWinner;
}
bool Hand::getisHandBust() const {
return isHandBust;
}
int Hand::gethandIdx() const {
return handIdx;
}
void Hand::sethasAce(const bool& status) {
hasAce = status;
}
void Hand::setisHandBust(const bool& status) {
isHandBust = status;
}
void Hand::setisHandWinner(const bool& status) {
isHandWinner = status;
}
void Hand::addCard(Card* card){
cards.push_back(*card);
score += card->val;
adjustForAce(card);
}
void Hand::recalculateScore() {
score = 0;
for (Card& card : cards) {
score += card.val;
}
}
void Hand::clearHand() {
cards.clear();
score = 0;
sethasAce(false);
setisHandBust(false);
setisHandWinner(false);
}
void Hand::displayHand(const bool& isStateDealing) const
{
if (!isHandBust)
{
for (size_t i = 0; i < cards.size(); i++)
{
cards[i].print();
}
cout << "Total score: " << score << endl << endl;
}
}
void Hand::adjustForAce(Card* card)
{
if (card->rank.compare("Ace") == 0 || hasAce) {
hasAce = true;
if (score > 21) {
score -= 10;
hasAce = false;
}
}
}