Blackjack
Loading...
Searching...
No Matches
player.h
Go to the documentation of this file.
1
10#ifndef PLAYER_H
11#define PLAYER_H
12
13#include "deck.h"
14#include "outcome.h"
15#include <string_view>
16
21class Player
22{
23protected:
24 std::string_view m_name{};
25 const int m_limit{};
26 int m_score{};
27 bool m_stand{};
28 bool m_busted{};
30
31public:
33 {}
34
35 Player(std::string_view name, const int playerLimit)
36 : m_name{ name }, m_limit{ playerLimit }, m_score{ 0 }, m_stand{ false }, m_busted{ false }, m_outcome{ LOSE }
37 {}
38
39 virtual ~Player() = default;
40
46 std::string_view getName() const
47 {
48 return m_name;
49 }
50
56 int getScore() const
57 {
58 return m_score;
59 }
60
67 bool isBusted() const
68 {
69 return m_busted;
70 }
71
78 bool isStand() const
79 {
80 return m_stand;
81 }
82
88 void setOutcome(Outcome outcome)
89 {
90 m_outcome = outcome;
91 }
92
99 {
100 return m_outcome;
101 }
102
107 void reset()
108 {
109 m_score = 0;
110 m_stand = false;
111 m_busted = false;
112 }
113
119 virtual void chance(Deck& deck) = 0;
120
126 virtual void hit(Deck& deck) = 0;
127};
128
129#endif
Definition deck.h:24
A player is defined by the score that he earns through his chances, in which he can either hit or sta...
Definition player.h:22
virtual void chance(Deck &deck)=0
Defines the chance of a player.
virtual ~Player()=default
bool m_busted
Definition player.h:28
void reset()
Reset the scores and status of the players (to play another game)
Definition player.h:107
void setOutcome(Outcome outcome)
Set the player's outcome upon finishing the game.
Definition player.h:88
Outcome getOutcome() const
Get the outcome of the player's game.
Definition player.h:98
bool isStand() const
Return if a player STANDS.
Definition player.h:78
const int m_limit
Definition player.h:25
virtual void hit(Deck &deck)=0
Defines the actions performed when a player HITS (as opposed to STANDS).
bool isBusted() const
Return if a player is busted.
Definition player.h:67
Outcome m_outcome
Definition player.h:29
int m_score
Definition player.h:26
int getScore() const
Get the player's score.
Definition player.h:56
std::string_view getName() const
Get the player's name.
Definition player.h:46
std::string_view m_name
Definition player.h:24
bool m_stand
Definition player.h:27
Player(std::string_view name, const int playerLimit)
Definition player.h:35
Player()
Definition player.h:32
Defines a Deck of cards.
Defines the possible Outcomes of the game.
Outcome
There are two possible outcomes: lose or win (no tie)
Definition outcome.h:18
@ LOSE
Definition outcome.h:19