|
Eile Mit Weile
|
Contains ServerGameState and can modify it. More...
#include <GameInstance.hpp>
Public Member Functions | |
| GameInstance () | |
| ~GameInstance () | |
| std::string | GetId () |
| ServerGameState * | GetGameState () |
| bool | IsFull () |
| bool | IsStarted () |
| bool | IsFinished () |
| bool | TryAddPlayer (Player *new_player, std::string &err) |
| bool | TryRemovePlayer (Player *player, std::string &err) |
| bool | StartGame (Player *player, std::string &err) |
| bool | ThrowDice (Player *player, std::string &err) |
| bool | MoveFigure (Player *player, unsigned figure_id, unsigned space_id, std::string &err) |
| bool | SkipTurn (Player *player, std::string &err) |
Private Member Functions | |
| bool | IsPlayerAllowedToPlay (Player *player) |
Private Attributes | |
| ServerGameState * | game_state |
Static Private Attributes | |
| static std::mutex | modification_lock |
Contains ServerGameState and can modify it.
Note: All updates to the GameState are communicated to all players in the GameInstance as a FullStateResponse via the ServerNetworkManager. This class design is mostly taken from https://gitlab.ethz.ch/hraymond/cse-lama-example-project. It references the ServerNetworkManager class without having to instantiate it. We consider this bad practice but changing would require a lot of refactoring so we decided to keep it as is.
| GameInstance::GameInstance | ( | ) |
Creates a new ServerGameState (see GameState::GameState).
| GameInstance::~GameInstance | ( | ) |
Deletes the ServerGameState.
| ServerGameState * GameInstance::GetGameState | ( | ) |
Returns the ServerGameState.
| std::string GameInstance::GetId | ( | ) |
Returns the unique id of the ServerGameState (hex string). See GameState::GetId.
| bool GameInstance::IsFinished | ( | ) |
| bool GameInstance::IsFull | ( | ) |
Checks if the Player is allowed to play.
| bool GameInstance::IsStarted | ( | ) |
| bool GameInstance::MoveFigure | ( | Player * | player, |
| unsigned | figure_id, | ||
| unsigned | space_id, | ||
| std::string & | err | ||
| ) |
Moves a figure if the Player is allowed to do so, returns true if successful. Err is set to an error message if the figure could not be moved. See also ServerGameState::MoveFigure.
Starts the game if the Player is allowed to do so, returns true if successful. Err is set to an error message if the game could not be started. See also ServerGameState::StartGame.
Throws the dice if the Player is allowed to do so, returns true if successful. Err is set to an error message if the dice could not be thrown. See also ServerGameState::ThrowDice.
Adds a Player to the ServerGameState if there aren't already 4, returns true if successful. Err is set to an error message if the Player could not be added. See also ServerGameState::AddPlayer. Also gives Player the corresponding game id.
Removes a Player from the ServerGameState if it is in there, returns true if successful. Err is set to an error message if the Player could not be removed. See also ServerGameState::RemovePlayer. Also resets the game id of Player.
|
private |
The ServerGameState of this GameInstance.
|
inlinestaticprivate |
Mutex to lock the GameInstance for modification.