-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hand.cpp
118 lines (105 loc) · 1.98 KB
/
Hand.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
/*
* Hand.cpp
*
* Created on: Apr 20, 2021
* Author: nickm
*/
#include "Hand.h"
Hand::Hand()
{
}
Hand::Hand(string playerName) {
// TODO Auto-generated constructor stub
vector<Card> handVector;
SetPlayerName(playerName);
handValue = 0;
handValue2 = 0;
}
void Hand::AddCard(Card input)
{
string card;
char first;
handVector.push_back(input);
card = input.DisplayValue();
first = card[0];
if (first == 'A')
{
hasAce = true;
handValue += 1;
handValue += 11;
}
else
{
handValue += input.GetnValue();
}
}
string Hand::DisplayHand(){
Card temp;
string answer;
for (unsigned int i = 0; i < handVector.size(); i++)
{
temp = handVector.at(i);
answer += temp.DisplayValue() + " ";
}
return answer;
}
string Hand::DisplayHandValue(){
Card temp;
int numAnswer;
int numAnswer2=0;
if (hasAce == false)
{
for (unsigned int i = 0; i < handVector.size(); i++)
{
temp = handVector.at(i);
numAnswer += temp.GetnValue();
}
return to_string(numAnswer);
}
else
{
for (unsigned int i = 0; i < handVector.size(); i++)
{
temp = handVector.at(i);
numAnswer += temp.GetnValue();
if (temp.GetnValue2() == 0)
{
numAnswer2 += temp.GetnValue();
}
else
{
numAnswer2 += temp.GetnValue2();
}
}
if (numAnswer > 21 and numAnswer2 > 21)
{
aceBust = true;
}
if (numAnswer > 16 and numAnswer < 21)
{
largerValue = numAnswer;
smallerValue = numAnswer2;
}
if ((numAnswer2 > 16 and numAnswer2 < 21 ) and numAnswer2 > numAnswer)
{
largerValue = numAnswer2;
smallerValue = numAnswer;
}
return to_string(numAnswer) + " or " + to_string(numAnswer2);
}
}
bool Hand::GetAceBust(){
return aceBust;
}
bool Hand::GetHasAce(){
return hasAce;
}
int Hand::GetLargerValue(){
return largerValue;
}
int Hand::GetSmallerValue(){
return smallerValue;
}
Hand::~Hand() {
// TODO Auto-generated destructor stub
}