java.lang.Object
it.polimi.ingsw.am13.client.gamestate.GameState
All Implemented Interfaces:
Serializable

public class GameState extends Object implements Serializable
Representation of the state of the game in a certain instant. The representation is not player-specific: it stores information for all the players in the game. It is valid only for the game, hence the listed players cannot change (can only be set to disconnected). This implies that the pre-game phase, where players join the room before it gets full, is not represented.
See Also:
  • Field Details

    • gameId

      private final int gameId
      Game ID for this game
    • players

      private final Map<PlayerLobby,PlayerState> players
      The players in the game, mapped via their player lobby
    • pickables

      private List<CardPlayableIF> pickables
      The list of cards that are visible to the player (the two tops aof the decks and the four cards that are drawable). Following game's rules, this should be always of size 6
    • commonObjectives

      private final List<CardObjectiveIF> commonObjectives
      The list of objectives that are common to all players Following game's rules, this should be always of size 2
    • gameStatus

      private GameStatus gameStatus
      The current game status
    • currentPlayer

      private PlayerLobby currentPlayer
      The current player in a turn-based phase (the one who must play or pick a card). Null if the game phase is different from IN_GAME or FINAL_PHASE
    • firstPlayer

      private final PlayerLobby firstPlayer
      The first player (from which the rounds start)
    • winner

      private List<PlayerLobby> winner
      Winner of the game, initially null
    • turnsToEnd

      private int turnsToEnd
      Number of turns to reach the end of the turn-based phase. -1 if FINAL_PHASE has not been reached yet
  • Constructor Details

    • GameState

      public GameState(GameModelIF model)
      Creates a new representation of the game's state starting from the given interface of model
      Parameters:
      model - Game model from which to retrieve the game's state
  • Method Details

    • getGameId

      public int getGameId()
      Returns:
      Game ID for this game
    • getPlayers

      public List<PlayerLobby> getPlayers()
      Returns:
      List of players in the game. (should not change). The order is the order in a round, from the first player to the last one
    • getPlayerState

      public PlayerState getPlayerState(PlayerLobby playerLobby)
      Parameters:
      playerLobby - Player whose the state is to be retrieved
      Returns:
      The representation of the state for the given player
    • getPickables

      public List<CardPlayableIF> getPickables()
      Returns:
      The list of cards that are visible to the player (the two tops aof the decks and the four cards that are drawable). Following game's rules, this should be always of size 6
    • setPickables

      void setPickables(List<CardPlayableIF> pickables)
      Sets the (6) pickable cards. Note that the is not created another list
      Parameters:
      pickables - List of pickable cards to set
    • getCommonObjectives

      public List<CardObjectiveIF> getCommonObjectives()
      Returns:
      The list of objectives that are common to all players Following game's rules, this should be always of size 2
    • getGameStatus

      public GameStatus getGameStatus()
      Returns:
      The current game status
    • setGameStatus

      void setGameStatus(GameStatus gameStatus)
      Set the current game status
      Parameters:
      gameStatus - Game status to set
    • getCurrentPlayer

      public PlayerLobby getCurrentPlayer()
      Returns:
      The current player in a turn-based phase (the one who must play or pick a card) Null if the game phase is different from IN_GAME or FINAL
    • setCurrentPlayer

      void setCurrentPlayer(PlayerLobby currentPlayer)
      Set the current player
      Parameters:
      currentPlayer - Current player to set
    • getFirstPlayer

      public PlayerLobby getFirstPlayer()
      Returns:
      The first player (from which the rounds start)
    • getWinner

      public List<PlayerLobby> getWinner()
      Returns:
      Winner of the game, initially null
    • setWinner

      public void setWinner(List<PlayerLobby> winners)
      Sets the winner. This method should be used only once the game is ended
      Parameters:
      winners - Winner to set
    • getTurnsToEnd

      public int getTurnsToEnd()
      Returns:
      Number of turns to reach the end of the turn-based phase
    • setTurnsToEnd

      public void setTurnsToEnd(int turnsToEnd)
      Sets the number of turns till the end.
      Parameters:
      turnsToEnd - Number of turns to reach the end of the turn-based phase
    • countConnected

      public int countConnected()
      Returns:
      the number of players that are currently connected