|
Eile Mit Weile
|
Holds the state of one game. More...
#include <GameState.hpp>
Static Public Member Functions | |
| static GameState * | FromJson (const rapidjson::Value &json) |
Protected Attributes | |
| Board * | _board |
| std::vector< Player * > | _players |
| SerializableValue< bool > * | _is_started |
| SerializableValue< bool > * | _is_finished |
| SerializableValue< int > * | _current_player_idx |
| SerializableValue< int > * | _play_direction |
Protected Attributes inherited from UniqueSerializable | |
| std::string | id |
Static Protected Attributes | |
| static const int | _max_nof_players = 4 |
| static const int | _min_nof_players = 2 |
Additional Inherited Members | |
Protected Member Functions inherited from UniqueSerializable | |
| UniqueSerializable () | |
| UniqueSerializable (std::string id) | |
Holds the state of one game.
A derived class ServerGameState is used on the server side to execute game state modifications, while the client uses this class only to display the game state.
| GameState::GameState | ( | ) |
Empty Constructor. Runs UniqueSerializable empty constructor, creates Board and defines all other protected vars corresponding to an unstarted game with no players.
|
explicit |
Runs UniqueSerializable constructor with id, creates Board and defines all other protected vars corresponding to an unstarted game with no players.
| GameState::GameState | ( | std::string | id, |
| Board * | board, | ||
| std::vector< Player * > & | players, | ||
| SerializableValue< bool > * | is_started, | ||
| SerializableValue< bool > * | is_finished, | ||
| SerializableValue< int > * | current_player_idx, | ||
| SerializableValue< int > * | play_direction | ||
| ) |
Runs UniqueSerializable constructor with id, This constructor is used by the client to obtain a GameState (deserialization from json).
| GameState::~GameState | ( | ) |
Destructor. Deletes all dynamically allocated members and sets them to nullptr.
|
static |
Creates a GameState from a json object using the deserialization constructor.
| Player * GameState::GetCurrentPlayer | ( | ) |
Returns a pointer to the Player that is currently allowed to play.
Returns true if the Player is allowed to play now.
| bool GameState::IsFinished | ( | ) |
Returns true if the game has finished.
| bool GameState::IsFull | ( | ) |
Returns true if the game has reached the maximum number of players.
Returns true if the Player is currently in the game.
| bool GameState::IsStarted | ( | ) |
Returns true if the game has started.
Throws the dice for the player and returns the result.
|
overridevirtual |
Writes the GameState into a json object.
Implements Serializable.
|
protected |
Index of the player that is currently allowed to play. Wrapped in SerializableValue to allow tcp communication via json format
|
protected |
Indicates whether the game has finished. Wrapped in SerializableValue to allow tcp communication via json format
|
protected |
Indicates whether the game has started. Wrapped in SerializableValue to allow tcp communication via json format
At most 4 players can play in a single game
At least 2 players are needed to start a game
|
protected |
1 or -1 depending on which direction is played in. The current implementation always sets this to 1. Wrapped in SerializableValue to allow tcp communication via json format
|
protected |
Holds pointers to players that are currently in the game (see Player)