-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
58 lines (46 loc) · 1.18 KB
/
Player.cpp
File metadata and controls
58 lines (46 loc) · 1.18 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
#include "Player.h"
#include <iostream>
Player::Player(const string& playerName, int startingBalance) : name(playerName), balance(startingBalance), currentBet(0), isStanding(false) {
}
void Player::reset() {
playerHand.clear();
currentBet = 0;
isStanding = false;
}
void Player::placeBet(int amount) {
if (amount > balance) {
cerr << "Not enough balance to place this bet\n";
return;
}
currentBet = amount;
balance -= amount;
}
void Player::hit(Deck& deck) {
if (!isStanding) {
playerHand.addCard(deck.dealCard());
}
}
void Player::stand() {
isStanding = true;
}
bool Player::isBusted() const {
return playerHand.getTotalValue() > 21;
}
bool Player::hasBlackjack() const {
return playerHand.getTotalValue() == 21 && playerHand.toString().find(",") == string::npos;
}
void Player::addWinnings(int amount) {
balance += amount;
}
string Player::getName() const {
return name;
}
int Player::getBalance() const {
return balance;
}
int Player::getCurrentBet() const {
return currentBet;
}
string Player::toString() const {
return name + "'s Hand: " + playerHand.toString() + " | Balance: $" + to_string(balance);
}