java.lang.Object
polimi.ingsw.am21.codex.model.Game

public class Game extends Object
  • Constructor Details

    • Game

      public Game(int players)
    • Game

      public Game(int players, org.json.JSONArray cards)
  • Method Details

    • getLobby

      public Lobby getLobby()
      Gets the lobby associated with the game.
      Returns:
      The lobby associated with the game.
    • start

      Starts the game.
      Throws:
      GameNotReadyException
      GameAlreadyStartedException
    • drawObjectiveCardPair

      public CardPair<ObjectiveCard> drawObjectiveCardPair() throws EmptyDeckException
      Draws a pair of objective cards from the deck.
      Returns:
      A pair of objective cards drawn from the deck.
      Throws:
      EmptyDeckException - When the deck being drawn from is empty.
    • getState

      public GameState getState()
      Gets the state of the game.
      Returns:
      The state of the game.
    • getPlayerState

      public PlayerState getPlayerState(String nickname) throws PlayerNotFoundGameException
      Gets the state of a player.
      Parameters:
      nickname - The nickname of the player.
      Returns:
      The state of the player.
      Throws:
      PlayerNotFoundGameException - If the player is not found.
    • getScoreBoard

      public Map<String,Integer> getScoreBoard()
      Gets the scoreboard of the game.
      Returns:
      The scoreboard of the game.
    • getCurrentPlayer

      public Player getCurrentPlayer()
      Gets the current player.
      Returns:
      The current player.
    • getPlayer

      public Player getPlayer(String nickname) throws PlayerNotFoundGameException
      Gets a player from the nickname
      Parameters:
      nickname - The nickname of the player you're looking for
      Throws:
      PlayerNotFoundGameException
    • getPlayers

      public List<Player> getPlayers()
      Gets the players in the game.
    • getCurrentPlayerIndex

      public Integer getCurrentPlayerIndex()
      Gets the index of current player.
      Returns:
      The index of current player.
    • addPlayer

      public void addPlayer(Player player)
      Adds a player to the game.
      Parameters:
      player - The player to add.
    • isGameOver

      public Boolean isGameOver()
      Checks if the game is over.
      Returns:
      True if the game is over, otherwise false.
    • setGameOver

      public void setGameOver()
      Sets the game to be over.
    • getRemainingRounds

      public Optional<Integer> getRemainingRounds()
      Gets the remaining rounds in the game.
      Returns:
      The remaining rounds in the game, if any.
    • isGameHalted

      public Boolean isGameHalted()
    • nextTurn

      public void nextTurn(DrawingCardSource drawingSource, DrawingDeckType deckType, BiConsumer<Integer,Integer> nextTurnEventAfterDraw, Runnable nextTurnWithoutDraw, Consumer<Integer> remainingRoundsChange) throws InvalidActionException
      Draws the player card and runs nextTurnExecute();
      Parameters:
      drawingSource - Where we are drawing the card rom
      deckType - The type of deck to draw from.
      nextTurnEventAfterDraw - Callback to be called after the cards are drawn: the first parameter is the id of the card drawn by the player, the second is from the one drawn for the card pair (if any, null otherwise).
      nextTurnWithoutDraw - Callback to be called if the player cannot draw a card (e.g. because the deck is empty).
      remainingRoundsChange - Callback triggered if the number of remaining rounds changes (so when the next (or current) round will be the last one
      Throws:
      GameOverException - If the game is over.
      InvalidActionException
    • nextTurn

      public void nextTurn(Runnable nextTurnWithoutDraw, Consumer<Integer> remainingRoundsChange) throws InvalidActionException
      runs nextTurnExecute()
      Parameters:
      remainingRoundsChange - Callback triggered if the number of remaining rounds changes (so when the next (or current) round will be the last one
      Throws:
      GameOverException - If the game is over.
      InvalidActionException
    • playerDisconnected

      public void playerDisconnected(String player) throws PlayerNotFoundGameException
      Throws:
      PlayerNotFoundGameException
    • playerReconnected

      public void playerReconnected(String player) throws PlayerNotFoundGameException
      Throws:
      PlayerNotFoundGameException
    • drawStarterCard

      public PlayableCard drawStarterCard() throws EmptyDeckException
      Draws a starter card from the deck.
      Returns:
      The starter card drawn from the deck.
      Throws:
      EmptyDeckException - If the deck being drawn from is empty.
    • insertObjectiveCard

      public void insertObjectiveCard(ObjectiveCard objectiveCard)
    • insertStarterCard

      public void insertStarterCard(PlayableCard starterCard)
    • isLastRound

      public Boolean isLastRound()
    • drawHand

      public List<PlayableCard> drawHand() throws EmptyDeckException
      Throws:
      EmptyDeckException
    • getPlayersCount

      public Integer getPlayersCount()
      Returns:
      the number of connected players
    • getMaxPlayers

      public Integer getMaxPlayers()
      Returns:
      the number of maximum players
    • getPlayersSpotsLeft

      public Integer getPlayersSpotsLeft()
    • getObjectiveCards

      public CardPair<ObjectiveCard> getObjectiveCards()
    • getResourceCards

      public CardPair<PlayableCard> getResourceCards()
    • getGoldCards

      public CardPair<PlayableCard> getGoldCards()
    • getChat

      public Chat getChat()
    • getGameBoard

      public GameBoard getGameBoard()