Eile Mit Weile
Loading...
Searching...
No Matches
Player Class Reference

Holds all relevant information of a player. More...

#include <Player.hpp>

Inheritance diagram for Player:
UniqueSerializable Serializable

Public Member Functions

 Player (std::string name, SerializableValue< int > *color_idx)
 
 Player (std::string name)
 
 Player (std::string id, std::string name)
 
 ~Player ()
 
std::string GetGameId ()
 
void SetGameId (std::string game_id)
 
unsigned int GetColorIdx () const
 
void SetColorIdx (int color_idx)
 
std::string GetPlayerName () const noexcept
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
- Public Member Functions inherited from UniqueSerializable
std::string GetId () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override
 
- Public Member Functions inherited from Serializable
virtual rapidjson::DocumentToJson () const
 

Static Public Member Functions

static PlayerFromJson (const rapidjson::Value &json)
 

Private Member Functions

 Player (std::string id, SerializableValue< std::string > *name, SerializableValue< int > *color_idx)
 

Private Attributes

SerializableValue< std::string > * _player_name
 
Color _color
 
SerializableValue< int > * _color_idx
 
std::string _game_id
 

Additional Inherited Members

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

Detailed Description

Holds all relevant information of a player.

Constructor & Destructor Documentation

◆ Player() [1/4]

Player::Player ( std::string  name,
SerializableValue< int > *  color_idx 
)
explicit

Constructor for the player used by client.

◆ Player() [2/4]

Player::Player ( std::string  name)
explicit

Constructor for the player used by client. Color id is set to 0 (red).

◆ Player() [3/4]

Player::Player ( std::string  id,
std::string  name 
)

Constructor for the player used by server. Color id is set to 0 (red). Unique id of UniqueSerializable is predefined argument.

◆ ~Player()

Player::~Player ( )

Destructor for the player. Deletes _player_name

◆ Player() [4/4]

Player::Player ( std::string  id,
SerializableValue< std::string > *  name,
SerializableValue< int > *  color_idx 
)
private

Deserialization constructor used by client to construct a Player from values sent by server (see FromJson)

Member Function Documentation

◆ FromJson()

Player * Player::FromJson ( const rapidjson::Value json)
static

Reads a player from a json object.

◆ GetColorIdx()

unsigned Player::GetColorIdx ( ) const

Getter for _color_idx.

◆ GetGameId()

std::string Player::GetGameId ( )

Getter for _game_id.

◆ GetPlayerName()

std::string Player::GetPlayerName ( ) const
noexcept

Getter for _player_name.

◆ SetColorIdx()

void Player::SetColorIdx ( int  color_idx)

Setter for _color_idx.

◆ SetGameId()

void Player::SetGameId ( std::string  game_id)

Setter for _game_id.

◆ WriteIntoJson()

void Player::WriteIntoJson ( rapidjson::Value json,
rapidjson::Document::AllocatorType &  allocator 
) const
overridevirtual

Writes the player into a json object.

Implements Serializable.

Member Data Documentation

◆ _color

Color Player::_color
private

Color of the player.

◆ _color_idx

SerializableValue<int>* Player::_color_idx
private

Color id of the player. Corresponds to the enum integer value of enum Color.

◆ _game_id

std::string Player::_game_id
private

Unique id of the game the player is in.

◆ _player_name

SerializableValue<std::string>* Player::_player_name
private

Name of the player.


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