-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
101 lines (89 loc) · 2.01 KB
/
Player.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
#include "stdafx.h"
#include "Player.h"
namespace BlackJack
{
/****************/
/* Constructors */
/****************/
Player::Player( uint playerNum ) : m_chips( 1000 ), m_playerNum( playerNum )
{
// Create the default hand
m_hands.push_back( Hand( m_hands.size() + 1 ) );
// Create the default bet placeholder
m_currentBets.push_back( 0 );
// Create the default handstatus placeholder
m_handStatuses.push_back( Hit );
}
/***********/
/* Methods */
/***********/
///////////////////
// AddCardToHand //
///////////////////
void
Player::AddCardToHand( const Card &card, uint handIndex )
{
m_hands[ handIndex ].AddCard( card );
}
//////////////
// DoubleBet//
//////////////
void
Player::DoubleBet( uint handIndex )
{
m_chips -= m_currentBets[ handIndex ];
m_currentBets[ handIndex ] *= 2;
}
///////////////
// SplitHand //
///////////////
void
Player::SplitHand( uint handIndex )
{
Card topCard = m_hands[ handIndex ].RemoveTopCard();
m_hands.push_back( Hand( topCard, m_hands.size() + 1 ) );
// Copy bet from hand being split to new partial hand
m_currentBets.push_back( m_currentBets[ handIndex ] );
m_chips -= m_currentBets[ handIndex ];
// Create the default handstatus placeholder for the new partial hand
m_handStatuses.push_back( Hit );
}
//////////////
// AddChips //
//////////////
void
Player::AddChips( uint chips )
{
m_chips += chips;
}
///////////////////
// SubtractChips //
///////////////////
void
Player::SubtractChips( uint chips )
{
m_chips = m_chips - chips >= 0 ? m_chips - chips : 0;
}
//////////////
// ClearBet //
//////////////
void
Player::ClearBet( uint handIndex )
{
m_currentBets[ handIndex ] = 0;
}
///////////
// Reset //
///////////
void
Player::Reset()
{
// Clear hands & bets & handstatuses
m_hands.clear();
m_hands.push_back( Hand( m_hands.size() + 1 ) );
m_currentBets.clear();
m_currentBets.push_back( 0 );
m_handStatuses.clear();
m_handStatuses.push_back( Hit );
}
}