-
Notifications
You must be signed in to change notification settings - Fork 0
/
players.cpp
125 lines (109 loc) · 2.64 KB
/
players.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
119
120
121
122
123
124
125
/**
* Blackjack in C++
* players.h
* Author: Danny Noe
* Description: players.h contains two classes.
* Dealer class: represents the dealer in blackjack
* Player class: represents a player in blackjack
*/
#include "players.h"
#include "deck.h"
#include <string>
#include <vector>
using std::string;
//------------------------------------------------------------------------------------------
/**
* Dealer Class
* Dealer class represents the dealer in blackjack
*/
/**
* Initalizes the Dealer class by creating a game_deck (Deck object)
*/
Dealer::Dealer()
{
game_deck = Deck();
return;
}
/**
* Override the string operator to represent the Dealer as a string.
* Only the dealer's top card is included in the str.
* @param[out] str, string describing the dealer's top card
*/
Dealer::operator string() const
{
return "Dealer's top card " + string(dealerHand.front());
}
/**
* Deals the top card from the Deck
* @param[out] Card, the card drawn from the deck
*/
Card Dealer::dealCard()
{
return game_deck.dealCard();
}
/**
* Adds a card to the dealer's hand
* @param[in] new_card, the card to be added to the hand
*/
void Dealer::updateHand(Card new_card)
{
dealerHand.push_back(new_card);
}
/**
* Shuffles the deck
*/
void Dealer::shuffle()
{
game_deck.shuffle();
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
/**
* Player Class
* the class represents a player in blackjack
*/
/**
* Initializes the player class by giving them 100 chips
*/
Player::Player()
{
chips = 100; // Player starts with $100 in chips
}
/**
* Overrides the string() method to display the Player class
* @param[out] str, string describing the player's hand
*/
Player::operator string() const
{
string out = "Your hand: ";
for (std::vector<Card>::const_iterator it = playerHand.begin(); it != playerHand.end(); ++it)
{
out += string(*it) + " ";
}
return out;
}
/**
* Returns the chips in the player has
* @param[out] int, num of chips in player's hand
*/
int Player::getChips()
{
return chips;
}
/**
* Updates the number of chips in the player has
* @param[in] difference, the difference in chips to be added
*/
void Player::updateChips(int difference)
{
chips = chips + difference;
}
/**
* Adds a card to the player's hand
* @param[in] new_card, the card to be added to the hand
*/
void Player::updateHand(Card new_card)
{
playerHand.push_back(new_card);
}
//------------------------------------------------------------------------------------------