java.lang.Object
it.polimi.ingsw.am13.client.view.tui.ViewTUI
All Implemented Interfaces:
View

public class ViewTUI extends Object implements View
Implementation of a view for TUI. It stores and handles the flow of the game (the "show" updates it expects to receive)
  • Field Details

    • currentMenu

      private MenuTUI currentMenu
      Current menu, which defines the possible actions to perform
    • thisPlayer

      private PlayerLobby thisPlayer
      Player the view refers to. Null if it is not defined yet
    • gameState

      private GameState gameState
      Game's state. Null if it is not defined yet
    • viewTUIMatch

      private ViewTUIMatch viewTUIMatch
      Handler of the view for the turn-based phases. Null if it is not defined
    • logs

      private LogTUI logs
      Log object to store logs displayed in the Log Section of the Match visualization
    • inputReader

      private MenuInputReader inputReader
      Thread which reads user input for menu selection
    • chat

      private Chat chat
      Chat. As gameState, it is handled outside of this class, and shouldn't be updated here
    • currentChatRoom

      private List<PlayerLobby> 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

    • changeAndPrintMenu

      private void changeAndPrintMenu(String request, MenuItem... items)
      Creates a new menu with the specified items, sets this as the new current menu and prints it
      Parameters:
      items - Items to be included in the new current menu
    • setNetworkHandler

      public void setNetworkHandler(NetworkHandler networkHandler)
      Starts the thread defined by MenuInputReader (listening for input from stdin)
      Specified by:
      setNetworkHandler in interface View
      Parameters:
      networkHandler - Handler of the network, with which the commands can be sent to the server
    • showStartupScreen

      public void showStartupScreen(boolean isSocket, String ip, int port)
      Shows a startup screen
      Specified by:
      showStartupScreen in interface View
      Parameters:
      isSocket - If the chosen connection is socket (vs RMI)
      ip - Ip of the client
      port - Port of the client
    • showException

      public void showException(Exception e)
      Prints a generic exception and prints again the current menu
      Specified by:
      showException in interface View
      Parameters:
      e - Exception to be shown
    • showRooms

      public void showRooms(List<RoomIF> rooms)
      Prints the list of all rooms (with game started or not started)
      Specified by:
      showRooms in interface View
      Parameters:
      rooms - List of rooms
    • showPlayerJoinedRoom

      public void showPlayerJoinedRoom(PlayerLobby player)
      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 interface View
      Parameters:
      player - Player who joined the room
    • showPlayerLeftRoom

      public 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. Otherwise, it shows the update
      Specified by:
      showPlayerLeftRoom in interface View
      Parameters:
      player - Player who left the room
    • showStartGame

      public void showStartGame(GameState gameState, Chat chat)
      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 interface View
      Parameters:
      gameState - Reference to the game's state which is kept up to date
    • showStartGameReconnected

      public void showStartGameReconnected(GameState state, PlayerLobby thisPlayer, Chat chat)
      Shows the already started game to the player who has reconnected mid-game
      Specified by:
      showStartGameReconnected in interface View
      Parameters:
      state - GameState of the started match
      thisPlayer - Player linked to this client which is reconnecting to the match
    • showPlayedStarter

      public void showPlayedStarter(PlayerLobby player)
      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 interface View
      Parameters:
      player - Player who played their starter card
    • showChosenPersonalObjective

      public void showChosenPersonalObjective(PlayerLobby player)
      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 interface View
      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 the ViewTUIMatch and uses that to handle this phase.
      Specified by:
      showInGame in interface View
    • showPlayedCard

      public void showPlayedCard(PlayerLobby player, Coordinates coord)
      Shows a player placing one of their hand cards on the field
      Specified by:
      showPlayedCard in interface View
      Parameters:
      player - Player who placed the card on field
      coord - Coordinates of the field where the card has been placed
    • showPickedCard

      public void showPickedCard(PlayerLobby player)
      Shows a player picking a card
      Specified by:
      showPickedCard in interface View
      Parameters:
      player - Player who picked a card
    • showNextTurn

      public void showNextTurn()
      Show the game moving on to the next turn
      Specified by:
      showNextTurn in interface View
    • showFinalPhase

      public void showFinalPhase()
      Shows the game entering the final phase (last turns before adding extra points)
      Specified by:
      showFinalPhase in interface View
    • showUpdatePoints

      public void showUpdatePoints()
      Shows the points updated after the turn-based phase is finished
      Specified by:
      showUpdatePoints in interface View
    • showWinner

      public void showWinner()
      Show the winner
      Specified by:
      showWinner in interface View
    • showEndGame

      public void showEndGame()
      Show the end of the game (after which the server deletes the game)
      Specified by:
      showEndGame in interface View
    • showPlayerDisconnected

      public void showPlayerDisconnected(PlayerLobby player)
      Show a player disconnecting from the game
      Specified by:
      showPlayerDisconnected in interface View
      Parameters:
      player - Player who disconnected
    • showPlayerReconnected

      public void showPlayerReconnected(PlayerLobby player)
      Show a player reconnecting to the game
      Specified by:
      showPlayerReconnected in interface View
      Parameters:
      player - Player who reconnected
    • showChatMessage

      public void showChatMessage(PlayerLobby sender, List<PlayerLobby> receivers)
      Shows a chat message
      Specified by:
      showChatMessage in interface View
      Parameters:
      sender - of the message
      receivers - 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 interface View
    • printCurrentChat

      private 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. 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

      public void enterChatRoom(List<String> receiverNicks) throws InvalidParameterException
      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

      public PlayerLobby getThisPlayer()
      Returns:
      player the view refers to. Null if it is not defined yet
    • getGameState

      public GameState getGameState()
      Returns:
      game's state. Null if it is not defined yet
    • getCurrentMenu

      public MenuTUI getCurrentMenu()
      Returns:
      current menu, which defines the possible actions to perform
    • setCurrentMenu

      void setCurrentMenu(MenuTUI currentMenu)
      Sets the current menu
      Parameters:
      currentMenu - current menu, which defines the possible actions to perform