Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
player Class Reference

Represents a player in the game. More...

#include <player.h>

Inheritance diagram for player:
unique_serializable serializable

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.
 
handget_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.
 
- Public Member Functions inherited from unique_serializable
std::string get_id () const
 
virtual void write_into_json (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override
 
- Public Member Functions inherited from serializable
virtual rapidjson::Document * to_json () const
 

Static Public Member Functions

static playerfrom_json (const rapidjson::Value &json)
 Deserializes a player object from a json object.
 

Additional Inherited Members

- Protected Member Functions inherited from unique_serializable
 unique_serializable (std::string id)
 
- Protected Attributes inherited from unique_serializable
std::string _id
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ player() [1/2]

player::player ( const std::string & name)
explicit

Constructs a new player object (used by client).

Parameters
nameThe player's name.

◆ player() [2/2]

player::player ( const std::string & id,
const std::string & name )

Constructs a new player object (used by the server)

Parameters
idThe player's id.
nameThe player's name.

Member Function Documentation

◆ add_card()

bool player::add_card ( card * card,
std::string & err ) const

Adds a card to the player's hand.

Parameters
cardThe card to be added to the player's hand.
errThe error message updated in case something does not work.
Returns
A boolean indicating whether adding the card worked or not.

◆ from_json()

player * player::from_json ( const rapidjson::Value & json)
static

Deserializes a player object from a json object.

Parameters
jsonThe json object containing the player information.
Returns
A pointer to a new player object created from the given json object.

◆ get_game_id()

std::string player::get_game_id ( )

Gets the game id of the game the player has joint.

Returns
The game id of the game the player has joint.

◆ get_hand()

hand * player::get_hand ( ) const
nodiscardnoexcept

Gets the player's hand.

Returns
The player's hand.

◆ get_nof_cards()

unsigned int player::get_nof_cards ( ) const
nodiscardnoexcept

Gets the number of cards in the player's hand.

Returns
The number of cards in the player's hand.

◆ get_nof_predicted()

int player::get_nof_predicted ( ) const
nodiscardnoexcept

Gets the number of tricks predicted to be won by the player in the current round.

Returns
The number of tricks predicted to be won by the player in the current round.

◆ get_nof_tricks()

int player::get_nof_tricks ( ) const
nodiscardnoexcept

Gets the number of tricks won by the player in the current round.

Returns
The number of tricks won by the player in the current round.

◆ get_player_name()

std::string player::get_player_name ( ) const
nodiscardnoexcept

Gets the player's name.

Returns
The player's name.

◆ get_scores()

std::vector< serializable_value< int > * > player::get_scores ( ) const
nodiscardnoexcept

Gets the scores of the player.

Returns
The scores of the player as a vector.

◆ set_game_id()

void player::set_game_id ( const std::string & game_id)

Sets the game id of the player.

Parameters
game_idThe game id of the game the player has joint.

◆ set_nof_predicted()

void player::set_nof_predicted ( int nof_predicted) const

Sets the player's number of predicted tricks to the given input.

Parameters
nof_predictedThe 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.

◆ set_nof_tricks()

void player::set_nof_tricks ( int nof_tricks) const

Sets the player's number of won tricks to the given input.

Parameters
nof_tricksThe 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.

◆ set_scores()

void player::set_scores ( int score)

Sets the player's scores to the given scores.

Parameters
scoreThe new scores of the player.

◆ setup_round()

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.

◆ wrap_up_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.

◆ write_into_json()

void player::write_into_json ( rapidjson::Value & json,
rapidjson::Document::AllocatorType & allocator ) const
overridevirtual

Serializes a player object into a json object.

Parameters
jsonThe json object for serializing the player.
allocatorThe json allocator for serializing the player.

Implements serializable.


The documentation for this class was generated from the following files: