java.lang.Object
polimi.ingsw.am21.codex.client.ClientGameEventHandler
- All Implemented Interfaces:
Remote,GameErrorListener,GameEventListener,RemoteGameEventListener
Class that handles the events thrown by the server, caught by the clients and forwards them to the local model and the view.
It implements the GameEventListener and GameErrorListener interfaces.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidcardPlaced(String gameId, String playerId, Integer playerHandCardNumber, Integer cardId, CardSideType side, Position position, int newPlayerScore, Map<ResourceType, Integer> updatedResources, Map<ObjectType, Integer> updatedObjects, Set<Position> availableSpots, Set<Position> forbiddenSpots) Interface method used to process the event of the current player placing a card on their playerboard.voidchangeTurn(String gameId, String playerNickname, Integer playerIndex, Boolean isLastRound, Set<Position> availableSpots, Set<Position> forbiddenSpots, Integer resourceDeckTopCardId, Integer goldDeckTopCardId) Interface method used to process the event of the player ending their turn choosing not to draw a card.voidchangeTurn(String gameId, String playerNickname, Integer playerIndex, Boolean isLastRound, DrawingCardSource source, DrawingDeckType deck, Integer cardId, Integer newPairCardId, Set<Position> availableSpots, Set<Position> forbiddenSpots, Integer resourceDeckTopCardId, Integer goldDeckTopCardId) Interface method used to process the event of the player ending their turn drawing a cardvoidchatMessage(String gameID, ChatMessage message) Interface method used to process the event of a player sending a chat message in the game they're in.voidvoidgameAlreadyExists(String gameId) voidvoidgameCreated(String gameId, int currentPlayers, int maxPlayers) Interface method used to process the game creation event.voidgameDeleted(String gameId) Interface method used to process the game deletion event.voidgameHalted(String gameID) voidgameNotFound(String gameId) voidvoidvoidgameOver()Interface method used to process the event of the game ending.voidgameResumed(String gameID) voidgameStarted(String gameId, GameInfo gameInfo) Interface method used to process the event of a game starting.voidgetObjectiveCards(javafx.util.Pair<Integer, Integer> objectiveCards) Interface method to process the event of a client requesting their secret objective cardvoidgetStarterCard(Integer cardId) Interface method to process the event of a client requesting their starter cardgetView()voidvoidvoidvoidinvalidCardPlacement(String reason) voidvoidvoidvoidvoidvoidlobbyInfo(LobbyUsersInfo usersInfo) 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.voidnicknameTaken(String nickname) voidvoidvoidplayerChoseObjectiveCard(String gameId, UUID connectionID, String nickname) Interface method used to process the event of a player choosing their objective card.voidplayerConnectionChanged(UUID connectionID, String nickname, GameController.UserGameContext.ConnectionStatus status) Interface method used to process the event of a player's connection status changing.voidplayerJoinedGame(String gameId, UUID connectionID, String nickname, TokenColor color, List<Integer> handIDs, Integer starterCardID, CardSideType starterSide) Interface method used to process the event of a player joining a game.voidplayerJoinedLobby(String gameId, UUID connectionID) Interface method used to process the event of a player joining a game lobby.voidplayerLeftLobby(String gameId, UUID connectionID) Interface method used to process the event of a player leaving a game lobby.voidvoidvoidplayerScoresUpdate(Map<String, Integer> newScores) 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.voidplayerSetNickname(String gameId, UUID connectionID, String nickname) Interface method used to process the event of a player choosing their nickname.voidplayerSetToken(String gameId, UUID connectionID, String nickname, TokenColor token) Interface method used to process the event of a player choosing their token color.voidrefreshLobbies(Set<String> lobbyIds, Map<String, Integer> currentPlayers, Map<String, Integer> maxPlayers) Interface method used to refresh the status of the lobbies after a game is created or a client joins a gamevoidremainingRounds(String gameID, int remainingRounds) 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.voidtokenTaken(TokenColor token) voidvoiduserContext(FullUserGameContext context) voidwinningPlayer(String nickname) Interface method used to process and display the winning player of the game.
-
Constructor Details
-
ClientGameEventHandler
-
-
Method Details
-
getView
-
getRemoteListener
-
getLocalModel
-
handleInvalidActionException
-
listGames
public void listGames() -
gameCreated
Description copied from interface:RemoteGameEventListenerInterface method used to process the game creation event.- Specified by:
gameCreatedin interfaceGameEventListener- Specified by:
gameCreatedin interfaceRemoteGameEventListener- 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:RemoteGameEventListenerInterface method used to refresh the status of the lobbies after a game is created or a client joins a game- Specified by:
refreshLobbiesin interfaceGameEventListener- Specified by:
refreshLobbiesin interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface method used to process the game deletion event.- Specified by:
gameDeletedin interfaceGameEventListener- Specified by:
gameDeletedin interfaceRemoteGameEventListener- Parameters:
gameId- The identifier of the game that has just been deleted.
-
playerJoinedLobby
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player joining a game lobby.- Specified by:
playerJoinedLobbyin interfaceGameEventListener- Specified by:
playerJoinedLobbyin interfaceRemoteGameEventListener- Parameters:
gameId- The identifier of the game lobby that the player has joined.connectionID- The unique identifier of the player that has joined the lobby.
-
playerLeftLobby
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player leaving a game lobby.- Specified by:
playerLeftLobbyin interfaceGameEventListener- Specified by:
playerLeftLobbyin interfaceRemoteGameEventListener- 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.
-
playerSetToken
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player choosing their token color.- Specified by:
playerSetTokenin interfaceGameEventListener- Specified by:
playerSetTokenin interfaceRemoteGameEventListener- 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 alreadytoken- The token color that the player has chosen
-
playerSetNickname
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player choosing their nickname.- Specified by:
playerSetNicknamein interfaceGameEventListener- Specified by:
playerSetNicknamein interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player choosing their objective card.- Specified by:
playerChoseObjectiveCardin interfaceGameEventListener- Specified by:
playerChoseObjectiveCardin interfaceRemoteGameEventListener- 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
-
playerJoinedGame
public void playerJoinedGame(String gameId, UUID connectionID, String nickname, TokenColor color, List<Integer> handIDs, Integer starterCardID, CardSideType starterSide) Description copied from interface:RemoteGameEventListenerInterface 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:
playerJoinedGamein interfaceGameEventListener- Specified by:
playerJoinedGamein interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a game starting.- Specified by:
gameStartedin interfaceGameEventListener- Specified by:
gameStartedin interfaceRemoteGameEventListener- Parameters:
gameId- The identifier of the game that has just started.gameInfo- The information about the game that has just started.
-
changeTurn
public void changeTurn(String gameId, String playerNickname, Integer playerIndex, Boolean isLastRound, DrawingCardSource source, DrawingDeckType deck, Integer cardId, Integer newPairCardId, Set<Position> availableSpots, Set<Position> forbiddenSpots, Integer resourceDeckTopCardId, Integer goldDeckTopCardId) Description copied from interface:RemoteGameEventListenerInterface method used to process the event of the player ending their turn drawing a card- Specified by:
changeTurnin interfaceGameEventListener- Specified by:
changeTurnin interfaceRemoteGameEventListener- 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.cardId- 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:RemoteGameEventListenerInterface 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:
changeTurnin interfaceGameEventListener- Specified by:
changeTurnin interfaceRemoteGameEventListener- Parameters:
gameId- The unique identifier of the game that has just ended.playerNickname- The player that has just finished their turnplayerIndex- 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.
-
cardPlaced
public void cardPlaced(String gameId, String playerId, Integer playerHandCardNumber, Integer cardId, CardSideType side, Position position, int newPlayerScore, Map<ResourceType, Integer> updatedResources, Map<ObjectType, Integer> updatedObjects, Set<Position> availableSpots, Set<Position> forbiddenSpots) Description copied from interface:RemoteGameEventListenerInterface method used to process the event of the current player placing a card on their playerboard.- Specified by:
cardPlacedin interfaceGameEventListener- Specified by:
cardPlacedin interfaceRemoteGameEventListener- Parameters:
gameId- The identifier of the game in which the card was placed.playerId- 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.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. This set is used to display the forbidden spots on the gameboard.
-
unknownResponse
public void unknownResponse()- Specified by:
unknownResponsein interfaceGameErrorListener
-
gameAlreadyExists
- Specified by:
gameAlreadyExistsin interfaceGameErrorListener
-
gameNotFound
- Specified by:
gameNotFoundin interfaceGameErrorListener
-
notInLobby
public void notInLobby()- Specified by:
notInLobbyin interfaceGameErrorListener
-
lobbyFull
- Specified by:
lobbyFullin interfaceGameErrorListener
-
tokenTaken
- Specified by:
tokenTakenin interfaceGameErrorListener
-
nicknameTaken
- Specified by:
nicknameTakenin interfaceGameErrorListener
-
gameNotStarted
public void gameNotStarted()- Specified by:
gameNotStartedin interfaceGameErrorListener
-
notInGame
public void notInGame()- Specified by:
notInGamein interfaceGameErrorListener
-
gameAlreadyStarted
public void gameAlreadyStarted()- Specified by:
gameAlreadyStartedin interfaceGameErrorListener
-
playerNotActive
public void playerNotActive()- Specified by:
playerNotActivein interfaceGameErrorListener
-
invalidCardPlacement
- Specified by:
invalidCardPlacementin interfaceGameErrorListener
-
invalidNextTurnCall
public void invalidNextTurnCall()- Specified by:
invalidNextTurnCallin interfaceGameErrorListener
-
invalidGetObjectiveCardsCall
public void invalidGetObjectiveCardsCall()- Specified by:
invalidGetObjectiveCardsCallin interfaceGameErrorListener
-
gameNotReady
public void gameNotReady()- Specified by:
gameNotReadyin interfaceGameErrorListener
-
gameOver
public void gameOver()Description copied from interface:RemoteGameEventListenerInterface method used to process the event of the game ending.- Specified by:
gameOverin interfaceGameErrorListener- Specified by:
gameOverin interfaceGameEventListener- Specified by:
gameOverin interfaceRemoteGameEventListener
-
emptyDeck
public void emptyDeck()- Specified by:
emptyDeckin interfaceGameErrorListener
-
playerNotFound
public void playerNotFound()- Specified by:
playerNotFoundin interfaceGameErrorListener
-
incompleteLobbyPlayer
- Specified by:
incompleteLobbyPlayerin interfaceGameErrorListener
-
illegalCardSideChoice
public void illegalCardSideChoice()- Specified by:
illegalCardSideChoicein interfaceGameErrorListener
-
invalidTokenColor
public void invalidTokenColor()- Specified by:
invalidTokenColorin interfaceGameErrorListener
-
alreadyPlacedCard
public void alreadyPlacedCard()- Specified by:
alreadyPlacedCardin interfaceGameErrorListener
-
cardNotPlaced
public void cardNotPlaced()- Specified by:
cardNotPlacedin interfaceGameErrorListener
-
playerScoresUpdate
Description copied from interface:RemoteGameEventListenerInterface 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:
playerScoresUpdatein interfaceGameEventListener- Specified by:
playerScoresUpdatein interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface 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:
remainingRoundsin interfaceGameEventListener- Specified by:
remainingRoundsin interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface method used to process and display the winning player of the game.- Specified by:
winningPlayerin interfaceGameEventListener- Specified by:
winningPlayerin interfaceRemoteGameEventListener- Parameters:
nickname- The nickname of the player that has won the game.
-
playerConnectionChanged
public void playerConnectionChanged(UUID connectionID, String nickname, GameController.UserGameContext.ConnectionStatus status) Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player's connection status changing.- Specified by:
playerConnectionChangedin interfaceGameEventListener- Specified by:
playerConnectionChangedin interfaceRemoteGameEventListener- 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.
-
lobbyInfo
Description copied from interface:RemoteGameEventListenerInterface 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:
lobbyInfoin interfaceGameEventListener- Specified by:
lobbyInfoin interfaceRemoteGameEventListener- 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
Description copied from interface:RemoteGameEventListenerInterface method used to process the event of a player sending a chat message in the game they're in.- Specified by:
chatMessagein interfaceGameEventListener- Specified by:
chatMessagein interfaceRemoteGameEventListener- Parameters:
gameID- The identifier of the game in which the chat message was sent.message- The chat message that was sent by the player.
-
getObjectiveCards
Description copied from interface:RemoteGameEventListenerInterface method to process the event of a client requesting their secret objective card- Specified by:
getObjectiveCardsin interfaceGameEventListener- Specified by:
getObjectiveCardsin interfaceRemoteGameEventListener- Parameters:
objectiveCards- 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
Description copied from interface:RemoteGameEventListenerInterface method to process the event of a client requesting their starter card- Specified by:
getStarterCardin interfaceGameEventListener- Specified by:
getStarterCardin interfaceRemoteGameEventListener- Parameters:
cardId- The unique identifier of the starter card that the player has chosen.
-
gameHalted
- Specified by:
gameHaltedin interfaceGameEventListener- Specified by:
gameHaltedin interfaceRemoteGameEventListener
-
gameResumed
- Specified by:
gameResumedin interfaceGameEventListener- Specified by:
gameResumedin interfaceRemoteGameEventListener
-
userContext
- Specified by:
userContextin interfaceGameEventListener- Specified by:
userContextin interfaceRemoteGameEventListener
-