Class CommandLineInterface
java.lang.Object
it.polimi.ingsw.eriantys.client.UserInterface
it.polimi.ingsw.eriantys.client.cli.CommandLineInterface
- All Implemented Interfaces:
ClientMessageHandler
,Runnable
This class represents the command line user interface (CLI).
It handles user inputs and messages received from the server.
-
Field Summary
Fields inherited from class it.polimi.ingsw.eriantys.client.UserInterface
characterCardInfo, client
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleMessage
(Accepted message) Handles aAccepted
message.void
handleMessage
(AcceptedJoinLobby message) Handles aAcceptedJoinLobby
message.void
handleMessage
(AcceptedLeaveLobby message) Handles aAcceptedLeaveLobby
message.void
handleMessage
(AcceptedUsername message) Handles aAcceptedUsername
message.void
handleMessage
(AssistantCardUpdate message) Handles aAssistantCardUpdate
message.void
handleMessage
(AvailableLobbies message) Handles aAvailableLobbies
message.void
handleMessage
(BoardUpdate message) Handles aBoardUpdate
message.void
handleMessage
(DisconnectionUpdate message) Handles aDisconnectionUpdate
message.void
handleMessage
(GameOverUpdate message) Handles aGameOverUpdate
message.void
handleMessage
(HelpResponse message) Handles aHelpResponse
message.void
handleMessage
(InitialBoardStatus message) Handles aInitialBoardStatus
message.void
handleMessage
(LobbyUpdate message) Handles aLobbyUpdate
message.void
handleMessage
(UserSelectionUpdate message) Handles aUserSelectionUpdate
message.void
quit()
Notifies the user that they have been disconnected from the game due to an error.void
run()
Starts the loop reading user inputs and handling commands.void
Shows an error message to the user.void
Shows an information message to the user.void
Prints the current status of the player's schoolboard.void
showSchoolBoard
(String player) Prints the current status of a player's schoolboard.Methods inherited from class it.polimi.ingsw.eriantys.client.UserInterface
handleMessage, handleMessage, handleMessage, handleMessage, handleMessage, handleMessage, handleMessage, init, setClient
-
Constructor Details
-
CommandLineInterface
Constructs aCommandLineInterface
object.- Throws:
IOException
- if theScanner
to read user inputs couldn't be created
-
-
Method Details
-
showInfo
Description copied from class:UserInterface
Shows an information message to the user.- Specified by:
showInfo
in classUserInterface
- Parameters:
details
- the message to show
-
showError
Description copied from class:UserInterface
Shows an error message to the user.- Specified by:
showError
in classUserInterface
- Parameters:
details
- the message to show
-
run
public void run()Starts the loop reading user inputs and handling commands. Notifies the client that the user interface is ready. -
showSchoolBoard
public void showSchoolBoard()Prints the current status of the player's schoolboard. -
showSchoolBoard
Prints the current status of a player's schoolboard.- Parameters:
player
- the player whose schoolboard should be printed
-
handleMessage
Handles aAccepted
message. Prints a message letting the player know that the action has been accepted.- Parameters:
message
- the received message
-
handleMessage
Handles aAcceptedUsername
message. Saves the selected username and checks if a reconnection is available. Prints a message letting the player know the username was accepted and how to reconnect.- Parameters:
message
- the received message
-
handleMessage
Handles aAcceptedJoinLobby
message. Saves the game id and the reconnection settings. Prints a message letting the player know the lobby was joined correctly.- Parameters:
message
- the received message
-
handleMessage
Handles aAcceptedLeaveLobby
message. Removes reconnection settings. Prints a message letting the player know the lobby was left correctly.- Parameters:
message
- the received message
-
handleMessage
Handles aHelpResponse
message. Prints the correct help message received from the server.- Parameters:
message
- the received message
-
handleMessage
Handles aAvailableLobbies
message. Prints the list of available lobbies.- Parameters:
message
- the received message
-
handleMessage
Handles aLobbyUpdate
message. Prints the list of players in the joined lobby- Parameters:
message
- the received message
-
handleMessage
Handles aAssistantCardUpdate
message. Prints the assistant cards played by the other players and then, if the player is the next one to play, prints the available assistant cards.- Specified by:
handleMessage
in interfaceClientMessageHandler
- Overrides:
handleMessage
in classUserInterface
- Parameters:
message
- the received message
-
handleMessage
Handles aBoardUpdate
message. Saves the board status. If the player is the next one to play, prints a message.- Specified by:
handleMessage
in interfaceClientMessageHandler
- Overrides:
handleMessage
in classUserInterface
- Parameters:
message
- the received message
-
handleMessage
Handles aUserSelectionUpdate
message. Prints the tower colors and wizards selected by other players and, if the player is the next to choose, prints the remaining tower colors and wizards.- Specified by:
handleMessage
in interfaceClientMessageHandler
- Overrides:
handleMessage
in classUserInterface
- Parameters:
message
- the received message
-
handleMessage
Handles aGameOverUpdate
message. Removes reconnection settings. Prints the winner. Stops the application.- Parameters:
message
- the received message
-
handleMessage
Handles aInitialBoardStatus
message. Saves the initial board status. Prints a message letting the player know that the game has started.- Parameters:
message
- the received message
-
handleMessage
Handles aDisconnectionUpdate
message. Prints a message with disconnection details.- Parameters:
message
- the received message
-
quit
public void quit()Description copied from class:UserInterface
Notifies the user that they have been disconnected from the game due to an error.- Specified by:
quit
in classUserInterface
-