Wizard
Software Engineering Project - Wizard
|
Represents a player in the game. More...
#include <player.h>
Public Member Functions | |
player (const std::string &name) | |
Constructs a new player object (used by client). | |
~player () override | |
Destructs a player object. | |
player (const std::string &id, const std::string &name) | |
Constructs a new player object (used by the server) | |
std::string | get_game_id () |
Gets the game id of the game the player has joint. | |
void | set_game_id (const std::string &game_id) |
Sets the game id of the player. | |
std::vector< serializable_value< int > * > | get_scores () const noexcept |
Gets the scores of the player. | |
void | set_scores (int score) |
Sets the player's scores to the given scores. | |
int | get_nof_tricks () const noexcept |
Gets the number of tricks won by the player in the current round. | |
void | set_nof_tricks (int nof_tricks) const |
Sets the player's number of won tricks to the given input. | |
int | get_nof_predicted () const noexcept |
Gets the number of tricks predicted to be won by the player in the current round. | |
void | set_nof_predicted (int nof_predicted) const |
Sets the player's number of predicted tricks to the given input. | |
unsigned int | get_nof_cards () const noexcept |
Gets the number of cards in the player's hand. | |
hand * | get_hand () const noexcept |
Gets the player's hand. | |
std::string | get_player_name () const noexcept |
Gets the player's name. | |
bool | add_card (card *card, std::string &err) const |
Adds a card to the player's hand. | |
void | setup_round () const |
Sets up the player for the next round. | |
void | wrap_up_round () |
Calculates the new score of the player. | |
void | write_into_json (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override |
Serializes a player object into a json object. | |
![]() | |
std::string | get_id () const |
virtual void | write_into_json (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override |
![]() | |
virtual rapidjson::Document * | to_json () const |
Static Public Member Functions | |
static player * | from_json (const rapidjson::Value &json) |
Deserializes a player object from a json object. | |
Additional Inherited Members | |
![]() | |
unique_serializable (std::string id) | |
![]() | |
std::string | _id |
Represents a player in the game.
This class encapsulates all information about a player, including the player's name, scores, hand, and the number of tricks they predicted and won.
|
explicit |
Constructs a new player object (used by client).
name | The player's name. |
player::player | ( | const std::string & | id, |
const std::string & | name ) |
Constructs a new player object (used by the server)
id | The player's id. |
name | The player's name. |
bool player::add_card | ( | card * | card, |
std::string & | err ) const |
Adds a card to the player's hand.
card | The card to be added to the player's hand. |
err | The error message updated in case something does not work. |
|
static |
Deserializes a player object from a json object.
json | The json object containing the player information. |
std::string player::get_game_id | ( | ) |
Gets the game id of the game the player has joint.
|
nodiscardnoexcept |
Gets the player's hand.
|
nodiscardnoexcept |
Gets the number of cards in the player's hand.
|
nodiscardnoexcept |
Gets the number of tricks predicted to be won by the player in the current round.
|
nodiscardnoexcept |
Gets the number of tricks won by the player in the current round.
|
nodiscardnoexcept |
Gets the player's name.
|
nodiscardnoexcept |
Gets the scores of the player.
void player::set_game_id | ( | const std::string & | game_id | ) |
Sets the game id of the player.
game_id | The game id of the game the player has joint. |
void player::set_nof_predicted | ( | int | nof_predicted | ) | const |
Sets the player's number of predicted tricks to the given input.
nof_predicted | The new number of tricks predicted by the player in the current round. |
This function is used to update the player's predicted number of tricks during the estimation phase of the game.
void player::set_nof_tricks | ( | int | nof_tricks | ) | const |
Sets the player's number of won tricks to the given input.
nof_tricks | The new number of tricks won by the player in the current round. |
This function is used to update the player's won number of tricks in case a player wins a trick.
void player::set_scores | ( | int | score | ) |
Sets the player's scores to the given scores.
score | The new scores of the player. |
void player::setup_round | ( | ) | const |
Sets up the player for the next round.
Sets the number of predicted tricks to -1 to show that no predictions have been made yet by the player and sets the number of won tricks to zero. This sets up the player for the next round.
void player::wrap_up_round | ( | ) |
Calculates the new score of the player.
Wraps up the player by calculating their score for the round that is wrapped up, based on the predicted and won tricks.
|
overridevirtual |
Serializes a player object into a json object.
json | The json object for serializing the player. |
allocator | The json allocator for serializing the player. |
Implements serializable.