Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
player.h
1#ifndef WIZARD_PLAYER_H
2#define WIZARD_PLAYER_H
3
4#include <string>
5#include "hand.h"
6#include "../../serialization/uuid_generator.h"
7#include "../../../../rapidjson/include/rapidjson/document.h"
8#include "../../serialization/unique_serializable.h"
9#include "../../serialization/serializable_value.h"
10
19private:
20
22 serializable_value<int>* _nof_tricks;
23 serializable_value<int>* _nof_predicted;
24 std::vector<serializable_value<int>*> _scores;
25 hand* _hand;
26
27#ifdef WIZARD_SERVER
28 std::string _game_id;
29#endif
30
40 player(const std::string& id,
42 serializable_value<int>* nof_tricks,
43 serializable_value<int>* nof_predicted,
44 const std::vector<serializable_value<int>*>& scores,
45 hand* hand);
46
47public:
48
49// constructors
54 explicit player(const std::string& name);
55
59 ~player() override;
60
61#ifdef WIZARD_SERVER
67 player(const std::string& id, const std::string& name);
68
73 std::string get_game_id();
74
79 void set_game_id(const std::string& game_id);
80#endif
81
82// accessors
87 [[nodiscard]] std::vector<serializable_value<int>*> get_scores() const noexcept;
88
93 void set_scores(int score);
94
99 [[nodiscard]] int get_nof_tricks() const noexcept;
100
107 void set_nof_tricks(int nof_tricks) const;
108
113 [[nodiscard]] int get_nof_predicted() const noexcept;
114
122 void set_nof_predicted(int nof_predicted) const;
123
128 [[nodiscard]] unsigned int get_nof_cards() const noexcept;
129
134 [[nodiscard]] hand* get_hand() const noexcept;
135
140 [[nodiscard]] std::string get_player_name() const noexcept;
141
142#ifdef WIZARD_SERVER
143// state update functions
150 bool add_card(card* card, std::string& err) const;
151
158 void setup_round() const;
159
166 void wrap_up_round();
167#endif
168
169// serialization interface
175 void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
176
182 static player* from_json(const rapidjson::Value& json);
183};
184
185#endif //WIZARD_PLAYER_H
Represents a card in the game.
Definition card.h:15
Represents a player's hand in the game.
Definition hand.h:15
Represents a player in the game.
Definition player.h:18
~player() override
Destructs a player object.
Definition player.cpp:29
void write_into_json(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Serializes a player object into a json object.
Definition player.cpp:152
void wrap_up_round()
Calculates the new score of the player.
Definition player.cpp:132
void set_nof_predicted(int nof_predicted) const
Sets the player's number of predicted tricks to the given input.
Definition player.cpp:97
int get_nof_predicted() const noexcept
Gets the number of tricks predicted to be won by the player in the current round.
Definition player.cpp:92
std::string get_player_name() const noexcept
Gets the player's name.
Definition player.cpp:104
unsigned int get_nof_cards() const noexcept
Gets the number of cards in the player's hand.
Definition player.cpp:114
static player * from_json(const rapidjson::Value &json)
Deserializes a player object from a json object.
Definition player.cpp:177
int get_nof_tricks() const noexcept
Gets the number of tricks won by the player in the current round.
Definition player.cpp:80
void set_nof_tricks(int nof_tricks) const
Sets the player's number of won tricks to the given input.
Definition player.cpp:85
void setup_round() const
Sets up the player for the next round.
Definition player.cpp:126
void set_game_id(const std::string &game_id)
Sets the game id of the player.
Definition player.cpp:61
bool add_card(card *card, std::string &err) const
Adds a card to the player's hand.
Definition player.cpp:121
std::vector< serializable_value< int > * > get_scores() const noexcept
Gets the scores of the player.
Definition player.cpp:68
void set_scores(int score)
Sets the player's scores to the given scores.
Definition player.cpp:73
hand * get_hand() const noexcept
Gets the player's hand.
Definition player.cpp:109
std::string get_game_id()
Gets the game id of the game the player has joint.
Definition player.cpp:56
Definition serializable_value.h:27
Definition unique_serializable.h:12