-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hand.cpp
executable file
·46 lines (38 loc) · 1 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
#include "Hand.h"
Hand::Hand(Deck *deck) : _Deck(deck), Y(400) { }
Hand::~Hand() { }
void Hand::Render() {
float offset = Card::CardWidth + 3, x = (900 / 2) - ((_Cards.size() * offset) / 2) + (Card::CardWidth / 2);
for (unsigned long i = 0; i < _Cards.size(); i++) {
Card *c = _Cards.at(i);
c->Coords[0] = x;
c->Coords[1] = Y;
c->Render();
x += offset;
}
}
void Hand::Draw() {
_Cards.push_back(_Deck->Draw());
}
int Hand::Count() {
int count = 0, aces = 0;
for (Card *card : _Cards) {
if (card->GetValue() == Card::ACE)
aces++;
else if (card->GetValue() == Card::JACK || card->GetValue() == Card::QUEEN || card->GetValue() == Card::KING)
count += 10;
else
count += (card->GetValue() + 1);
}
while (aces > 0) {
if (11 + count <= 21)
count += 11;
else
count++;
aces--;
}
return count;
}
void Hand::Reset() {
_Cards.clear();
}