-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
137 lines (121 loc) · 2.46 KB
/
player.h
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
126
127
128
129
130
131
132
133
134
135
136
137
/**
* @file player.h
* @author DSN
* @brief Defines the contract for a \c Player
* @version 0.2
* @date 2023-08-19
*
*/
#ifndef PLAYER_H
#define PLAYER_H
#include "deck.h"
#include "outcome.h"
#include <string_view>
/**
* @brief A player is defined by the score that he earns through his chances, in which he can either hit or stand.
*
*/
class Player
{
protected:
std::string_view m_name{};
const int m_limit{};
int m_score{};
bool m_stand{};
bool m_busted{};
Outcome m_outcome{};
public:
Player() = default;
Player(
std::string_view name,
const int playerLimit
) :
m_name{ name },
m_limit{ playerLimit },
m_score{ 0 },
m_stand{ false },
m_busted{ false },
m_outcome{ LOSE }
{
}
virtual ~Player() = default;
/**
* @brief Get the player's name
*
* @return std::string_view
*/
std::string_view getName() const
{
return m_name;
}
/**
* @brief Get the player's score
*
* @return int
*/
int getScore() const
{
return m_score;
}
/**
* @brief Return if a player is busted
*
* @return true : if the player's score has crossed the given limit
* @return false : the player isn't busted yet
*/
bool isBusted() const
{
return m_busted;
}
/**
* @brief Return if a player STANDS
*
* @return true : if the players STANDS
* @return false : the player HITS
*/
bool isStand() const
{
return m_stand;
}
/**
* @brief Set the player's outcome upon finishing the game
*
* @param outcome
*/
void setOutcome(Outcome outcome)
{
m_outcome = outcome;
}
/**
* @brief Get the outcome of the player's game
*
* @return Outcome
*/
Outcome getOutcome() const
{
return m_outcome;
}
/**
* @brief Reset the scores and status of the players (to play another game)
*
*/
void reset()
{
m_score = 0;
m_stand = false;
m_busted = false;
}
/**
* @brief Defines the chance of a player.
*
* @param deck
*/
virtual void chance(Deck& deck) = 0;
/**
* @brief Defines the actions performed when a player HITS (as opposed to STANDS).
*
* @param deck
*/
virtual void hit(Deck& deck) = 0;
};
#endif