- 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 void
addWorker(int row, int col)
Sends a AddWorkerRequest to the server to add a new Workervoid
chooseInitialGods(ChooseInitialGodsRequest message)
Asks the lobby owner to choose the gods for the matchvoid
chooseStartingPlayer(ChooseStartingPlayerRequest message)
Asks the user to select the player which plays firstvoid
chooseToReloadMatch(ChooseToReloadMatchRequest message)
Asks the user if it wants to restore a previously saved gamevoid
chooseWorker(Worker worker)
Asks the user to choose a workervoid
chooseYourGod(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 playervoid
chooseYourWorkerPosition(ChooseWorkerPositionRequest message)
Asks the user to choose where to place its workervoid
createLobby(LobbyCreatedEvent message)
Notifies the user about the creation of a new lobbyvoid
enterLobby(java.util.Map<java.lang.String,java.util.List<java.lang.String>> lobbiesAvailable)
Lets the user decide to join or create a lobbyvoid
joinLobby(UserJoinedLobbyEvent message)
Notifies the user about a new user joining the lobbyvoid
messageToSend(PossibleActions chosenAction, java.util.List<Cell> workersCell)
Determines what message to send based on the action chosen by the uservoid
onBuildableCellsReceived(BuildableCellsResponse message)
Manages a BuildableCellsResponsevoid
onBuildingCellSelected(PossibleBuildingBlockResponse message)
Manages a PossibleBuildingBlockResponsevoid
onGameBoardUpdate(GameBoardUpdate message)
Refreshes the game boardvoid
onGameStart(GameStartEvent message)
Manages a GameStartEventvoid
onGodChosen(ChosenGodsEvent message)
Notifies the user about the gods chosen for the gamevoid
onLogin(LoginResponse message)
Manages the login responsevoid
onMovedToWaitingRoom(MovedToWaitingRoomResponse message)
Notifies the user that it's been moved to the waiting room upon an opponent's disconnectionvoid
onPlayerBuild(PlayerBuildEvent message)
Manages a PlayerBuildEventvoid
onPlayerMove(PlayerMoveEvent message)
Manages a PlayerMoveEventvoid
onPlayerRemoved(PlayerRemovedEvent message)
Manages a PlayerRemovedEvent, showing the winnervoid
onTurnEnd(EndTurnEvent message)
Manages an EndTurnEventvoid
onWalkableCellsReceived(WalkableCellsResponse message)
Manages a WalkableCellsResponsevoid
onWinnerDeclared(WinnerDeclaredEvent message)
Manages a WinnerDeclaredEvent, showing the winnervoid
onWorkerAdd(WorkerAddedEvent message)
Manages a WorkerAddedEventvoid
onWorkerSelected(WorkerSelectedResponse message)
Manages a WorkerSelectedResponsevoid
printOnBuild(java.util.List<Cell> buildableCells)
Shows the buildable cells and asks the user where to build with its chosen workervoid
printOnMove(java.util.List<Cell> walkableCells)
Shows the walkable cells and asks the user where to move its chosen workervoid
sendBuild(Block selectedBlock)
Sends a PlayerBuildRequest to the servervoid
sendMove(Cell selectedCell)
Sends a PlayerMoveRequest to the servervoid
setChosenSize(int chosenSize)
chosenSize settervoid
setCreatingLobby(boolean creatingLobby)
creatingLobby settervoid
setLookingForLobbies(boolean lookingForLobbies)
lookingForLobbies settervoid
setSelectedCell(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:
onLogin
in 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:
createLobby
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
joinLobby
Notifies the user about a new user joining the lobby- Specified by:
joinLobby
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
chooseToReloadMatch
Asks the user if it wants to restore a previously saved game- Specified by:
chooseToReloadMatch
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
chooseInitialGods
Asks the lobby owner to choose the gods for the match- Specified by:
chooseInitialGods
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
onGodChosen
Notifies the user about the gods chosen for the game- Specified by:
onGodChosen
in 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:
chooseYourGod
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
chooseStartingPlayer
Asks the user to select the player which plays first- Specified by:
chooseStartingPlayer
in 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:
onMovedToWaitingRoom
in 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:
onGameBoardUpdate
in 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:
onPlayerMove
in 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:
onPlayerBuild
in 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
true
and its turn begins- Specified by:
onTurnEnd
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
chooseYourWorkerPosition
Asks the user to choose where to place its worker- Specified by:
chooseYourWorkerPosition
in 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:
onWorkerAdd
in 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:
onGameStart
in 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:
onWinnerDeclared
in interfaceClientMessageManagerVisitor
- Parameters:
message
- the message to handle
-
onPlayerRemoved
Manages a PlayerRemovedEvent, showing the winner- Specified by:
onPlayerRemoved
in 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:
onWorkerSelected
in 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:
onWalkableCellsReceived
in 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:
onBuildableCellsReceived
in 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:
onBuildingCellSelected
in 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
-