Class LocalModelContainer

java.lang.Object
polimi.ingsw.am21.codex.client.localModel.LocalModelContainer
All Implemented Interfaces:
Remote, GameEventListener, RemoteGameEventListener

public class LocalModelContainer extends Object implements GameEventListener
The LocalModelContainer class is the container of the model of the game that is stored locally on the client side to enable client interaction with the server.

Since the server model has some controller functionality included, we opted to create a mere container local model for the view to draw things properly and keep track of game events client side.

The status of the game is updated by the server: the client is notified and the local gameboard updated through the client game event handler, which updates the local model and the view.

It contains the local menu, lobby and game board.
See Also:
  • Constructor Details

    • LocalModelContainer

      public LocalModelContainer()
  • Method Details

    • getClientContextContainer

      public LocalModelContainer.ClientContextContainer getClientContextContainer()
    • getGameId

      public Optional<String> getGameId()
    • setConnectionID

      public void setConnectionID(UUID connectionID)
    • getConnectionID

      public UUID getConnectionID()
    • getLocalMenu

      public LocalMenu getLocalMenu()
    • getLocalLobby

      public Optional<LocalLobby> getLocalLobby()
    • getLocalGameBoard

      public Optional<LocalGameBoard> getLocalGameBoard()
    • gameCreated

      public void gameCreated(String gameId, int currentPlayers, int maxPlayers)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the game creation event.
      Specified by:
      gameCreated in interface GameEventListener
      Specified by:
      gameCreated in interface RemoteGameEventListener
      Parameters:
      gameId - The unique identifier of the game that has just been created.
      currentPlayers - The number of players currently in the game.
      maxPlayers - The maximum number of players that can join the game.
    • refreshLobbies

      public void refreshLobbies(Set<String> lobbyIds, Map<String,Integer> currentPlayers, Map<String,Integer> maxPlayers)
      Description copied from interface: RemoteGameEventListener
      Interface method used to refresh the status of the lobbies after a game is created or a client joins a game
      Specified by:
      refreshLobbies in interface GameEventListener
      Specified by:
      refreshLobbies in interface RemoteGameEventListener
      Parameters:
      lobbyIds - A set containing the unique identifiers of all the game lobbies with available spots.
      currentPlayers - A map containing the number of players currently in each lobby. The key is the unique identifier of the lobby and the value is the number of players. The number of players is the number of players currently in the lobby.
      maxPlayers - A map containing the maximum number of players that can join each lobby. The key is the unique identifier of the lobby and the value is the maximum number of players. The maximum number of players is the maximum number of players that can join the lobby.
    • gameDeleted

      public void gameDeleted(String gameId)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the game deletion event.
      Specified by:
      gameDeleted in interface GameEventListener
      Specified by:
      gameDeleted in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game that has just been deleted.
    • lobbyFull

      public void lobbyFull(String gameId)
      Interface method used to process
      Parameters:
      gameId - The identifier of the lobby that has been filled.
    • playerJoinedLobby

      public void playerJoinedLobby(String gameId, UUID connectionID)
      Removes a player slot from the game entry in the menu. Adds the player to your lobby if you have one. Creates a lobby if you join a lobby.
      Specified by:
      playerJoinedLobby in interface GameEventListener
      Specified by:
      playerJoinedLobby in interface RemoteGameEventListener
      Parameters:
      gameId - the id of the game lobby
      connectionID - the id of the player that joined the lobby
    • playerConnectionChanged

      public void playerConnectionChanged(UUID connectionID, String nickname, GameController.UserGameContext.ConnectionStatus status)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player's connection status changing.
      Specified by:
      playerConnectionChanged in interface GameEventListener
      Specified by:
      playerConnectionChanged in interface RemoteGameEventListener
      Parameters:
      connectionID - The unique identifier of the player whose connection status has changed. This is the identifier that the player uses to connect to the server.
      nickname - The nickname of the player whose connection status has changed.
      status - The new connection status of the player.
    • playerLeftLobby

      public void playerLeftLobby(String gameId, UUID connectionID)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player leaving a game lobby.
      Specified by:
      playerLeftLobby in interface GameEventListener
      Specified by:
      playerLeftLobby in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game lobby that the player has left.
      connectionID - The unique identifier of the player that has left the lobby.
    • tokenTaken

      public void tokenTaken(TokenColor token)
    • playerSetToken

      public void playerSetToken(String gameId, UUID connectionID, String nickname, TokenColor token)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player choosing their token color.
      Specified by:
      playerSetToken in interface GameEventListener
      Specified by:
      playerSetToken in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game lobby in which the player has set their token color.
      connectionID - The unique identifier of the player that has set their token color.
      nickname - The nickname of the player that has set their token color, if they have chosen it already
      token - The token color that the player has chosen
    • playerSetNickname

      public void playerSetNickname(String gameId, UUID connectionID, String nickname)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player choosing their nickname.
      Specified by:
      playerSetNickname in interface GameEventListener
      Specified by:
      playerSetNickname in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game lobby in which the player has set their nickname.
      connectionID - The unique identifier of the player that has set their nickname.
      nickname - The nickname of the player that has set their nickname
    • playerChoseObjectiveCard

      public void playerChoseObjectiveCard(String gameId, UUID connectionID, String nickname)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player choosing their objective card.
      Specified by:
      playerChoseObjectiveCard in interface GameEventListener
      Specified by:
      playerChoseObjectiveCard in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game lobby in which the player has set their objective card.
      connectionID - The unique identifier of the player that has set their objective card.
      nickname - The nickname of the player that has set their objective card, if they have chosen it already
    • getAvailableObjectives

      public CardPair<Card> getAvailableObjectives()
      Gets the objectives the local player can choose from in the lobby
    • playerChoseObjectiveCard

      public void playerChoseObjectiveCard(Boolean isFirst)
    • getObjectiveCards

      public void getObjectiveCards(javafx.util.Pair<Integer,Integer> cardIdPair)
      Description copied from interface: RemoteGameEventListener
      Interface method to process the event of a client requesting their secret objective card
      Specified by:
      getObjectiveCards in interface GameEventListener
      Specified by:
      getObjectiveCards in interface RemoteGameEventListener
      Parameters:
      cardIdPair - A pair of integers representing the unique identifiers of the secret objective cards. The first integer is the unique identifier of the secret objective card that the player has chosen. The second integer is the unique identifier of the secret objective card that the player has not chosen.
    • getStarterCard

      public void getStarterCard(Integer cardId)
      Description copied from interface: RemoteGameEventListener
      Interface method to process the event of a client requesting their starter card
      Specified by:
      getStarterCard in interface GameEventListener
      Specified by:
      getStarterCard in interface RemoteGameEventListener
      Parameters:
      cardId - The unique identifier of the starter card that the player has chosen.
    • gameHalted

      public void gameHalted(String gameID)
      Specified by:
      gameHalted in interface GameEventListener
      Specified by:
      gameHalted in interface RemoteGameEventListener
    • gameResumed

      public void gameResumed(String gameID)
      Specified by:
      gameResumed in interface GameEventListener
      Specified by:
      gameResumed in interface RemoteGameEventListener
    • userContext

      public void userContext(FullUserGameContext context)
      Specified by:
      userContext in interface GameEventListener
      Specified by:
      userContext in interface RemoteGameEventListener
    • playerJoinedGame

      public void playerJoinedGame(String gameId, UUID connectionID, String nickname, TokenColor color, List<Integer> handIDs, Integer starterCardID, CardSideType starterSide)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player joining a game. This happens when a player chooses which side of their starter card they prefer to place
      Specified by:
      playerJoinedGame in interface GameEventListener
      Specified by:
      playerJoinedGame in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game that the player has joined.
      connectionID - The unique identifier of the player that has joined the game.
      nickname - The nickname of the player that has joined the game.
      color - The token color of the player that has joined the game.
      handIDs - The unique identifiers of the cards in the player's hand.
      starterCardID - The id of the starter card the player was given as their starter card.
      starterSide - The side of the card that the player has chosen to place.
    • gameStarted

      public void gameStarted(String gameId, GameInfo gameInfo)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a game starting.
      Specified by:
      gameStarted in interface GameEventListener
      Specified by:
      gameStarted in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game that has just started.
      gameInfo - The information about the game that has just started.
    • cardPlaced

      public void cardPlaced(String gameId, String playerNickname, Integer playerHandCardNumber, Integer cardId, CardSideType side, Position position, int newPlayerScore, Map<ResourceType,Integer> updatedResources, Map<ObjectType,Integer> updatedObjects, Set<Position> availablePositions, Set<Position> forbiddenPositions)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the current player placing a card on their playerboard.
      Specified by:
      cardPlaced in interface GameEventListener
      Specified by:
      cardPlaced in interface RemoteGameEventListener
      Parameters:
      gameId - The identifier of the game in which the card was placed.
      playerNickname - The identifier of the player that placed the card.
      playerHandCardNumber - The number of the card in the player's hand that was placed.
      cardId - The unique identifier of the card that was placed.
      side - The side of the card that was placed.
      position - The position on the player board where the card was placed.
      newPlayerScore - The updated score of the player that placed the card.
      updatedResources - The updated resources of the player that placed the card. The key is the type of resource and the value is the new amount of that resource.
      updatedObjects - The updated objects of the player that placed the card. The key is the type of object and the value is the new amount of that object.
      availablePositions - A set of positions that are available for the next player to place a card.
      forbiddenPositions - A set of positions that are forbidden for the next player to place a card. This set is used to display the forbidden spots on the gameboard.
    • changeTurn

      public void changeTurn(String gameId, String playerNickname, Integer playerIndex, Boolean isLastRound, DrawingCardSource source, DrawingDeckType deck, Integer drawnCardId, Integer newPairCardId, Set<Position> availableSpots, Set<Position> forbiddenSpots, Integer resourceDeckTopCardId, Integer goldDeckTopCardId)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the player ending their turn drawing a card
      Specified by:
      changeTurn in interface GameEventListener
      Specified by:
      changeTurn in interface RemoteGameEventListener
      Parameters:
      gameId - The unique identifier of the game that has just ended.
      playerNickname - The nickname of the player that has just finished their turn. This can be null if the game ended because of a disconnection.
      playerIndex - The index of the player that has just finished their turn in the list of players.
      isLastRound - A boolean indicating if this is the last round of the game.
      source - The source from which the card was drawn.
      deck - The type of deck from which the card was drawn.
      drawnCardId - The unique identifier of the card that was drawn. (null if the receiving client is not the one who drew the card)
      newPairCardId - The unique identifier of the new pair card that was drawn.
      availableSpots - A set of positions that are available for the next player to place a card.
      forbiddenSpots - A set of positions that are forbidden for the next player to place a card.
    • changeTurn

      public void changeTurn(String gameId, String playerNickname, Integer playerIndex, Boolean isLastRound, Set<Position> availableSpots, Set<Position> forbiddenSpots, Integer resourceDeckTopCardId, Integer goldDeckTopCardId)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the player ending their turn choosing not to draw a card. This possibility is given by the fact that the decks might be empty, A player can choose not to draw in their last turn if they prefer not to draw from the pairs available on the gameboard
      Specified by:
      changeTurn in interface GameEventListener
      Specified by:
      changeTurn in interface RemoteGameEventListener
      Parameters:
      gameId - The unique identifier of the game that has just ended.
      playerNickname - The player that has just finished their turn
      playerIndex - The index of the player that has just finished their turn in the list of players.
      isLastRound - A boolean indicating if this is the last round of the game.
      availableSpots - A set of positions that are available for the next player to place a card.
      forbiddenSpots - A set of positions that are forbidden for the next player to place a card.
      resourceDeckTopCardId - The unique identifier of the top card in the resource deck.
      goldDeckTopCardId - The unique identifier of the top card in the gold deck.
    • gameOver

      public void gameOver()
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the game ending.
      Specified by:
      gameOver in interface GameEventListener
      Specified by:
      gameOver in interface RemoteGameEventListener
    • playerScoresUpdate

      public void playerScoresUpdate(Map<String,Integer> newScores)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the player's score being updated after the game ends and secret and common objectives are evaluated.
      Specified by:
      playerScoresUpdate in interface GameEventListener
      Specified by:
      playerScoresUpdate in interface RemoteGameEventListener
      Parameters:
      newScores - A map containing the updated scores of the players. The key is the nickname of the player and the value is the new score of the player.
    • remainingRounds

      public void remainingRounds(String gameID, int remainingRounds)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of the number of remaining rounds being updated or set when winning score is reached by any of the players.
      Specified by:
      remainingRounds in interface GameEventListener
      Specified by:
      remainingRounds in interface RemoteGameEventListener
      Parameters:
      gameID - The identifier of the game in which the number of remaining rounds was updated.
      remainingRounds - The number of rounds remaining in the game.
    • winningPlayer

      public void winningPlayer(String nickname)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process and display the winning player of the game.
      Specified by:
      winningPlayer in interface GameEventListener
      Specified by:
      winningPlayer in interface RemoteGameEventListener
      Parameters:
      nickname - The nickname of the player that has won the game.
    • lobbyInfo

      public void lobbyInfo(LobbyUsersInfo usersInfo)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player joining a game lobby when there are other players already inside it that may or may not have already completed the process of joining the game.
      Specified by:
      lobbyInfo in interface GameEventListener
      Specified by:
      lobbyInfo in interface RemoteGameEventListener
      Parameters:
      usersInfo - The information about the users in the lobby. It includes the nickname, token color, objective card choice, starter card side chosen, and in-game status of each user.
    • chatMessage

      public void chatMessage(String gameID, ChatMessage message)
      Description copied from interface: RemoteGameEventListener
      Interface method used to process the event of a player sending a chat message in the game they're in.
      Specified by:
      chatMessage in interface GameEventListener
      Specified by:
      chatMessage in interface RemoteGameEventListener
      Parameters:
      gameID - The identifier of the game in which the chat message was sent.
      message - The chat message that was sent by the player.
    • currentPlayerHasPlacedCard

      public boolean currentPlayerHasPlacedCard()
      Gets whether the current player has already placed a card for their turn, and they now have to draw.