- All Implemented Interfaces:
ClientMessageManagerVisitor
public class MessageManagerParser extends java.lang.Object implements ClientMessageManagerVisitor
-
Constructor Summary
Constructors Constructor Description MessageManagerParser(Client client)Default constructor -
Method Summary
Modifier and Type Method Description voidaddWorker(int row, int col)Sends a AddWorkerRequest to the server to add a new WorkervoidchooseInitialGods(ChooseInitialGodsRequest message)Asks the lobby owner to choose the gods for the matchvoidchooseStartingPlayer(ChooseStartingPlayerRequest message)Asks the user to select the player which plays firstvoidchooseToReloadMatch(ChooseToReloadMatchRequest message)Asks the user if it wants to restore a previously saved gamevoidchooseWorker(Worker worker)Asks the user to choose a workervoidchooseYourGod(ChooseYourGodRequest message)Asks the user to choose its god
If there's only one god left to be chosen, it is automatically assigned to the playervoidchooseYourWorkerPosition(ChooseWorkerPositionRequest message)Asks the user to choose where to place its workervoidcreateLobby(LobbyCreatedEvent message)Notifies the user about the creation of a new lobbyvoidenterLobby(java.util.Map<java.lang.String,java.util.List<java.lang.String>> lobbiesAvailable)Lets the user decide to join or create a lobbyvoidjoinLobby(UserJoinedLobbyEvent message)Notifies the user about a new user joining the lobbyvoidmessageToSend(PossibleActions chosenAction, java.util.List<Cell> workersCell)Determines what message to send based on the action chosen by the uservoidonBuildableCellsReceived(BuildableCellsResponse message)Manages a BuildableCellsResponsevoidonBuildingCellSelected(PossibleBuildingBlockResponse message)Manages a PossibleBuildingBlockResponsevoidonGameBoardUpdate(GameBoardUpdate message)Refreshes the game boardvoidonGameStart(GameStartEvent message)Manages a GameStartEventvoidonGodChosen(ChosenGodsEvent message)Notifies the user about the gods chosen for the gamevoidonLogin(LoginResponse message)Manages the login responsevoidonMovedToWaitingRoom(MovedToWaitingRoomResponse message)Notifies the user that it's been moved to the waiting room upon an opponent's disconnectionvoidonPlayerBuild(PlayerBuildEvent message)Manages a PlayerBuildEventvoidonPlayerMove(PlayerMoveEvent message)Manages a PlayerMoveEventvoidonPlayerRemoved(PlayerRemovedEvent message)Manages a PlayerRemovedEvent, showing the winnervoidonTurnEnd(EndTurnEvent message)Manages an EndTurnEventvoidonWalkableCellsReceived(WalkableCellsResponse message)Manages a WalkableCellsResponsevoidonWinnerDeclared(WinnerDeclaredEvent message)Manages a WinnerDeclaredEvent, showing the winnervoidonWorkerAdd(WorkerAddedEvent message)Manages a WorkerAddedEventvoidonWorkerSelected(WorkerSelectedResponse message)Manages a WorkerSelectedResponsevoidprintOnBuild(java.util.List<Cell> buildableCells)Shows the buildable cells and asks the user where to build with its chosen workervoidprintOnMove(java.util.List<Cell> walkableCells)Shows the walkable cells and asks the user where to move its chosen workervoidsendBuild(Block selectedBlock)Sends a PlayerBuildRequest to the servervoidsendMove(Cell selectedCell)Sends a PlayerMoveRequest to the servervoidsetChosenSize(int chosenSize)chosenSize settervoidsetCreatingLobby(boolean creatingLobby)creatingLobby settervoidsetLookingForLobbies(boolean lookingForLobbies)lookingForLobbies settervoidsetSelectedCell(Cell selectedCell)selectedCell setter
-
Constructor Details
-
MessageManagerParser
Default constructor- Parameters:
client- the client to parse messages for
-
-
Method Details
-
setSelectedCell
selectedCell setter- Parameters:
selectedCell- the cell to be used for the next action
-
setChosenSize
public void setChosenSize(int chosenSize)chosenSize setterThis is crucial to correctly manage the
- Parameters:
chosenSize- the lobby size
-
setCreatingLobby
public void setCreatingLobby(boolean creatingLobby)creatingLobby setterUsed to determine if the user is creating a lobby
- Parameters:
creatingLobby- a boolean value
-
setLookingForLobbies
public void setLookingForLobbies(boolean lookingForLobbies)lookingForLobbies setterUsed to determine if the user is looking for a lobby
- Parameters:
lookingForLobbies- a boolean value
-
onLogin
Manages the login responseed on the LoginResponse outcome
- Type.OK: login successful, the user is in the waiting room and asked to create/join a lobby
- Type.SERVER_FULL: the server has exceeded its maximum capacity, won't accept new connections
- Type.INVALID_NAME: the username is already taken or forbidden
- Specified by:
onLoginin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
enterLobby
public void enterLobby(java.util.Map<java.lang.String,java.util.List<java.lang.String>> lobbiesAvailable)Lets the user decide to join or create a lobby- Parameters:
lobbiesAvailable- the list of available lobbies- See Also:
LoginManager
-
createLobby
Notifies the user about the creation of a new lobbyIf the user is looking for a lobby to join, the list of available lobbies is automatically refreshed and showed
- Specified by:
createLobbyin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
joinLobby
Notifies the user about a new user joining the lobby- Specified by:
joinLobbyin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
chooseToReloadMatch
Asks the user if it wants to restore a previously saved game- Specified by:
chooseToReloadMatchin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
chooseInitialGods
Asks the lobby owner to choose the gods for the match- Specified by:
chooseInitialGodsin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onGodChosen
Notifies the user about the gods chosen for the game- Specified by:
onGodChosenin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handled
-
chooseYourGod
Asks the user to choose its god
If there's only one god left to be chosen, it is automatically assigned to the player- Specified by:
chooseYourGodin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
chooseStartingPlayer
Asks the user to select the player which plays first- Specified by:
chooseStartingPlayerin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onMovedToWaitingRoom
Notifies the user that it's been moved to the waiting room upon an opponent's disconnection- Specified by:
onMovedToWaitingRoomin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
addWorker
public void addWorker(int row, int col)Sends a AddWorkerRequest to the server to add a new Worker- Parameters:
row- the worker cell row indexcol- the worker cell column index
-
onGameBoardUpdate
Refreshes the game board- Specified by:
onGameBoardUpdatein interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onPlayerMove
Manages a PlayerMoveEventd on the PlayerMoveEvent outcome:
- Type.OK: updates the saved game board
- Any other case: shows an error message
- Specified by:
onPlayerMovein interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onPlayerBuild
Manages a PlayerBuildEventd on the PlayerBuildEvent outcome:
- Type.OK: updates the saved game board
- Any other case: shows an error message
- Specified by:
onPlayerBuildin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onTurnEnd
Manages an EndTurnEventIf the outcome is Type.OK, the previous turn has been ended and a new one begun; if the user's username is the same contained in the message, its Client.setCurrentPlayer(boolean) token is set to
trueand its turn begins- Specified by:
onTurnEndin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
chooseYourWorkerPosition
Asks the user to choose where to place its worker- Specified by:
chooseYourWorkerPositionin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onWorkerAdd
Manages a WorkerAddedEventd on the WorkerAddedEvent outcome:
- Type.OK: updates the saved game board
- Any other case: shows an error message
- Specified by:
onWorkerAddin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onGameStart
Manages a GameStartEventSignals the users the game started; the player designated as first player (see ChooseStartingPlayerRequest) is asked to perform an action
- Specified by:
onGameStartin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
chooseWorker
Asks the user to choose a worker- Parameters:
worker- the selected worker
-
sendMove
Sends a PlayerMoveRequest to the server- Parameters:
selectedCell- the cell to move the selected worker to
-
sendBuild
Sends a PlayerBuildRequest to the server- Parameters:
selectedBlock- block to be built on the target cell
-
onWinnerDeclared
Manages a WinnerDeclaredEvent, showing the winner- Specified by:
onWinnerDeclaredin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onPlayerRemoved
Manages a PlayerRemovedEvent, showing the winner- Specified by:
onPlayerRemovedin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onWorkerSelected
Manages a WorkerSelectedResponseIf the response type is Type.OK, the user is asked to choose the action to perform; otherwise, a error message is shown
- Specified by:
onWorkerSelectedin interfaceClientMessageManagerVisitor- Parameters:
message- the message to handle
-
onWalkableCellsReceived
Manages a WalkableCellsResponseIf the response type is Type.OK, the user is shown a game board highlighting the cells on which its chosen worker can be moved; otherwise, an error message is shown
- Specified by:
onWalkableCellsReceivedin interfaceClientMessageManagerVisitor- Parameters:
message- the message to visit
-
onBuildableCellsReceived
Manages a BuildableCellsResponseIf the response type is Type.OK, the user is shown a game board highlighting the cells on which its chosen worker can build on; otherwise, an error message is shown
- Specified by:
onBuildableCellsReceivedin interfaceClientMessageManagerVisitor- Parameters:
message- the message to visit
-
onBuildingCellSelected
Manages a PossibleBuildingBlockResponseIf the response type is Type.OK, the user is asked to choose which block it wants to build on the selected cell; otherwise, an error message is shown
- Specified by:
onBuildingCellSelectedin interfaceClientMessageManagerVisitor- Parameters:
message- the message to visit
-
messageToSend
Determines what message to send based on the action chosen by the user- Parameters:
chosenAction- the chosen action
-
printOnMove
Shows the walkable cells and asks the user where to move its chosen worker- Parameters:
walkableCells- a list of walkable cells
-
printOnBuild
Shows the buildable cells and asks the user where to build with its chosen worker- Parameters:
buildableCells- a list of buildable cells
-