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

Contains ServerGameState and can modify it. More...

#include <GameInstance.hpp>

Public Member Functions

 GameInstance ()
 
 ~GameInstance ()
 
std::string GetId ()
 
ServerGameStateGetGameState ()
 
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

ServerGameStategame_state
 

Static Private Attributes

static std::mutex modification_lock
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GameInstance()

GameInstance::GameInstance ( )

Creates a new ServerGameState (see GameState::GameState).

◆ ~GameInstance()

GameInstance::~GameInstance ( )

Deletes the ServerGameState.

Member Function Documentation

◆ GetGameState()

ServerGameState * GameInstance::GetGameState ( )

Returns the ServerGameState.

◆ GetId()

std::string GameInstance::GetId ( )

Returns the unique id of the ServerGameState (hex string). See GameState::GetId.

◆ IsFinished()

bool GameInstance::IsFinished ( )

◆ IsFull()

bool GameInstance::IsFull ( )

◆ IsPlayerAllowedToPlay()

bool GameInstance::IsPlayerAllowedToPlay ( Player player)
private

Checks if the Player is allowed to play.

◆ IsStarted()

bool GameInstance::IsStarted ( )

◆ MoveFigure()

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.

◆ SkipTurn()

bool GameInstance::SkipTurn ( Player player,
std::string &  err 
)

Skips the turn of the Player if the Player is allowed to do so, returns true if successful. Err is set to an error message if the turn could not be skipped. See also GameState::SkipTurn.

◆ StartGame()

bool GameInstance::StartGame ( Player player,
std::string &  err 
)

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.

◆ ThrowDice()

bool GameInstance::ThrowDice ( Player player,
std::string &  err 
)

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.

◆ TryAddPlayer()

bool GameInstance::TryAddPlayer ( Player new_player,
std::string &  err 
)

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.

◆ TryRemovePlayer()

bool GameInstance::TryRemovePlayer ( Player player,
std::string &  err 
)

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.

Member Data Documentation

◆ game_state

ServerGameState* GameInstance::game_state
private

◆ modification_lock

std::mutex GameInstance::modification_lock
inlinestaticprivate

Mutex to lock the GameInstance for modification.


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