java.lang.Object
it.polimi.ingsw.am13.client.view.tui.ViewTUI
- All Implemented Interfaces:
View
Implementation of a view for TUI.
It stores and handles the flow of the game (the "show" updates it expects to receive)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Chat
Chat.private List
<PlayerLobby> List of receivers defining the current shown chat room.private MenuTUI
Current menu, which defines the possible actions to performprivate GameState
Game's state.private MenuInputReader
Thread which reads user input for menu selectionprivate LogTUI
Log object to store logs displayed in the Log Section of the Match visualizationprivate PlayerLobby
Player the view refers to.private ViewTUIMatch
Handler of the view for the turn-based phases. -
Constructor Summary
ConstructorsConstructorDescriptionViewTUI()
Builds a new TUI view, setting an empty menu and all state attributes to null (not yet set) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
changeAndPrintMenu
(String request, MenuItem... items) Creates a new menu with the specified items, sets this as the new current menu and prints itvoid
enterChatRoom
(List<String> receiverNicks) Enters the chatroom associated to the specified receivers' nicknamesvoid
Force closing the app.void
Leaves the chatroom currently active, and reprints the matchprivate void
printCurrentChat
(String messageUp) Prints all the messages for the currently active chat room (assuming a chatroom is active) It can print a message before the chat room.(package private) void
setCurrentMenu
(MenuTUI currentMenu) Sets the current menuvoid
setNetworkHandler
(NetworkHandler networkHandler) Starts the thread defined byMenuInputReader
(listening for input from stdin)void
showChatMessage
(PlayerLobby sender, List<PlayerLobby> receivers) Shows a chat messagevoid
It shows a successful objective card chosen.void
Show the end of the game (after which the server deletes the game)void
Prints a generic exception and prints again the current menuvoid
Shows the game entering the final phase (last turns before adding extra points)void
It shows the game entering the turn-based phase In particular sets theViewTUIMatch
and uses that to handle this phase.void
Show the game moving on to the next turnvoid
showPickedCard
(PlayerLobby player) Shows a player picking a cardvoid
showPlayedCard
(PlayerLobby player, Coordinates coord) Shows a player placing one of their hand cards on the fieldvoid
showPlayedStarter
(PlayerLobby player) It shows a successful starter card played.void
showPlayerDisconnected
(PlayerLobby player) Show a player disconnecting from the gamevoid
showPlayerJoinedRoom
(PlayerLobby player) Prints a player joining the room.void
showPlayerLeftRoom
(PlayerLobby player) Prints a player leaving the room If the player is the one associated to the view, it is assumed that this is the ACK message from the server and handles it.void
showPlayerReconnected
(PlayerLobby player) Show a player reconnecting to the gamevoid
Prints the list of all rooms (with game started or not started)void
showStartGame
(GameState gameState, Chat chat) Shows the game starting.void
showStartGameReconnected
(GameState state, PlayerLobby thisPlayer, Chat chat) Shows the already started game to the player who has reconnected mid-gamevoid
showStartupScreen
(boolean isSocket, String ip, int port) Shows a startup screenvoid
Shows the points updated after the turn-based phase is finishedvoid
Show the winner
-
Field Details
-
currentMenu
Current menu, which defines the possible actions to perform -
thisPlayer
Player the view refers to. Null if it is not defined yet -
gameState
Game's state. Null if it is not defined yet -
viewTUIMatch
Handler of the view for the turn-based phases. Null if it is not defined -
logs
Log object to store logs displayed in the Log Section of the Match visualization -
inputReader
Thread which reads user input for menu selection -
chat
Chat. As gameState, it is handled outside of this class, and shouldn't be updated here -
currentChatRoom
List of receivers defining the current shown chat room. Null is no chat room is currently shown
-
-
Constructor Details
-
ViewTUI
public ViewTUI()Builds a new TUI view, setting an empty menu and all state attributes to null (not yet set)
-
-
Method Details
-
setNetworkHandler
Starts the thread defined byMenuInputReader
(listening for input from stdin)- Specified by:
setNetworkHandler
in interfaceView
- Parameters:
networkHandler
- Handler of the network, with which the commands can be sent to the server
-
showStartupScreen
Shows a startup screen- Specified by:
showStartupScreen
in interfaceView
- Parameters:
isSocket
- If the chosen connection is socket (vs RMI)ip
- Ip of the clientport
- Port of the client
-
showException
Prints a generic exception and prints again the current menu- Specified by:
showException
in interfaceView
- Parameters:
e
- Exception to be shown
-
showRooms
Prints the list of all rooms (with game started or not started) -
showPlayerJoinedRoom
Prints a player joining the room. If the player for this was not set, it is assumed this is the ACK message from the server and handles it. Otherwise, it shows the update- Specified by:
showPlayerJoinedRoom
in interfaceView
- Parameters:
player
- Player who joined the room
-
showPlayerLeftRoom
Prints a player leaving the room If the player is the one associated to the view, it is assumed that this is the ACK message from the server and handles it. Otherwise, it shows the update- Specified by:
showPlayerLeftRoom
in interfaceView
- Parameters:
player
- Player who left the room
-
showStartGame
Shows the game starting. In particular prints the two sides of the starter card and sets the meny in order to play the starter- Specified by:
showStartGame
in interfaceView
- Parameters:
gameState
- Reference to the game's state which is kept up to date
-
showStartGameReconnected
Shows the already started game to the player who has reconnected mid-game- Specified by:
showStartGameReconnected
in interfaceView
- Parameters:
state
- GameState of the started matchthisPlayer
- Player linked to this client which is reconnecting to the match
-
showPlayedStarter
It shows a successful starter card played. If the player is not the one associated to the view, it shows the update. Otherwise, it shows the two possible objective card and sets the menu in order to choose between them.- Specified by:
showPlayedStarter
in interfaceView
- Parameters:
player
- Player who played their starter card
-
showChosenPersonalObjective
It shows a successful objective card chosen. If the player is the one associated to the view, is also updated the menu- Specified by:
showChosenPersonalObjective
in interfaceView
- Parameters:
player
- Player who chose their personal objective card
-
showInGame
public void showInGame()It shows the game entering the turn-based phase In particular sets theViewTUIMatch
and uses that to handle this phase.- Specified by:
showInGame
in interfaceView
-
showPlayedCard
Shows a player placing one of their hand cards on the field- Specified by:
showPlayedCard
in interfaceView
- Parameters:
player
- Player who placed the card on fieldcoord
- Coordinates of the field where the card has been placed
-
showPickedCard
Shows a player picking a card- Specified by:
showPickedCard
in interfaceView
- Parameters:
player
- Player who picked a card
-
showNextTurn
public void showNextTurn()Show the game moving on to the next turn- Specified by:
showNextTurn
in interfaceView
-
showFinalPhase
public void showFinalPhase()Shows the game entering the final phase (last turns before adding extra points)- Specified by:
showFinalPhase
in interfaceView
-
showUpdatePoints
public void showUpdatePoints()Shows the points updated after the turn-based phase is finished- Specified by:
showUpdatePoints
in interfaceView
-
showWinner
public void showWinner()Show the winner- Specified by:
showWinner
in interfaceView
-
showEndGame
public void showEndGame()Show the end of the game (after which the server deletes the game)- Specified by:
showEndGame
in interfaceView
-
showPlayerDisconnected
Show a player disconnecting from the game- Specified by:
showPlayerDisconnected
in interfaceView
- Parameters:
player
- Player who disconnected
-
showPlayerReconnected
Show a player reconnecting to the game- Specified by:
showPlayerReconnected
in interfaceView
- Parameters:
player
- Player who reconnected
-
showChatMessage
Shows a chat message- Specified by:
showChatMessage
in interfaceView
- Parameters:
sender
- of the messagereceivers
- of the message
-
forceCloseApp
public void forceCloseApp()Force closing the app. It should be used to end the app for anomalous reasons- Specified by:
forceCloseApp
in interfaceView
-
printCurrentChat
Prints all the messages for the currently active chat room (assuming a chatroom is active) It can print a message before the chat room. It prints always the menu, too- Parameters:
messageUp
- Message to show before the chat room (it appears at the top of the screen). Use "" or null string to show nothing
-
enterChatRoom
Enters the chatroom associated to the specified receivers' nicknames- Parameters:
receiverNicks
- Receivers' nickname of the players associated to the chatroom to enter- Throws:
InvalidParameterException
- If the nicknames don't correspond to any player, or are invalid for the chatroom
-
leaveChatRoom
public void leaveChatRoom()Leaves the chatroom currently active, and reprints the match -
getThisPlayer
- Returns:
- player the view refers to. Null if it is not defined yet
-
getGameState
- Returns:
- game's state. Null if it is not defined yet
-
getCurrentMenu
- Returns:
- current menu, which defines the possible actions to perform