Module AM37

Class CLI

java.lang.Object
it.polimi.ingsw.view.cli.CLI
All Implemented Interfaces:
ViewInterface

public class CLI
extends java.lang.Object
implements ViewInterface
Command Line Interface manager
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static java.util.concurrent.locks.Lock lock  
  • Constructor Summary

    Constructors 
    Constructor Description
    CLI​(boolean enableRawMode)
    Default constructor
  • Method Summary

    Modifier and Type Method Description
    void askIP()
    Asks the user the server address to connect to
    void askLobbyName()
    Asks the user the name for the lobby to be created
    void askLobbySize()
    Asks the user the number of players for its lobby
    void askToReloadLastSettings​(java.util.List<java.lang.String> savedUsers)
    Asks the user if it wants to reload a previously saved address/username combo
    void askUsername()
    Asks the user the username it wants to use
    void buildAction​(java.util.List<Cell> gameBoard, java.util.List<Cell> buildableCells)
    Asks the user to select a cell to build on
    void chooseAction​(java.util.List<PossibleActions> possibleActions)
    Asks the user which action to perform
    void chooseBlockToBuild​(java.util.List<Block> buildableBlocks)
    Asks the user which block to build on a cell
    void chooseGameGods​(java.util.List<GodData> allGods, int size)
    Asks the user to choose the gods for the game
    void chooseLobbyToJoin​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> lobbiesAvailable)
    Asks the user which lobby it wants to join
    void chooseMatchReload()
    Asks the user if it wants to reload an existing saved match
    void chooseStartingPlayer​(java.util.List<java.lang.String> players)
    Asks the user which player will play first
    void chooseUserGod​(java.util.List<GodData> possibleGods)
    Asks the user to choose its personal god for the game
    void chooseWorker​(java.util.List<Cell> cells)
    Asks the user to choose a worker
    boolean enableRawMode()
    Determines if the terminal running the application allows non-canonical mode
    void evaluateInput​(java.lang.String input)
    Passes a string to the inputManager
    void gameBoardUpdate​(java.util.List<Cell> gameBoard, java.util.List<PlayerData> players)
    Refreshes the game screen
    void gameStartScreen​(java.util.List<Cell> gameBoard, java.util.List<PlayerData> playerData)
    Updates information about the players and the game
    void lobbyOptions​(java.util.List<java.lang.String> options)
    Asks the user if it wants to join or create a lobby
    void moveAction​(java.util.List<Cell> gameBoard, java.util.List<Cell> walkableCells)
    Asks the user to select a cell to move its current worker on
    void placeWorker()
    Asks the user to place its worker on the board
    void printLogo()
    Prints the start screen
    void printUserServerCombos​(java.util.List<java.lang.String> options)
    Shows the user the address/username combos
    void setInputManager​(InputManager inputManager)
    Sets the InputManager to parse the inputs
    void showErrorMessage​(java.lang.String error)
    Shows an error message
    void showGameBoard​(java.util.List<Cell> gameBoard)
    Prints the game board on the screen
    void showSuccessMessage​(java.lang.String message)
    Shows a success message

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lock

      protected static java.util.concurrent.locks.Lock lock
  • Constructor Details

    • CLI

      public CLI​(boolean enableRawMode) throws java.io.IOException
      Default constructor
      Parameters:
      enableRawMode - determines if the terminal in which the program is running allows non-canonical mode
      Throws:
      java.io.IOException
  • Method Details

    • enableRawMode

      public boolean enableRawMode()
      Determines if the terminal running the application allows non-canonical mode
      Returns:
      true if the terminal allows non-canonical mode, false otherwise
    • setInputManager

      public void setInputManager​(InputManager inputManager)
      Sets the InputManager to parse the inputs
      Specified by:
      setInputManager in interface ViewInterface
      Parameters:
      inputManager - te inputManager to use
    • evaluateInput

      public void evaluateInput​(java.lang.String input)
      Passes a string to the inputManager
      Parameters:
      input - the inputString
    • showErrorMessage

      public void showErrorMessage​(java.lang.String error)
      Shows an error message
      Specified by:
      showErrorMessage in interface ViewInterface
      Parameters:
      error - the error message
    • showSuccessMessage

      public void showSuccessMessage​(java.lang.String message)
      Shows a success message
      Specified by:
      showSuccessMessage in interface ViewInterface
      Parameters:
      message - the message
    • printLogo

      public void printLogo()
      Prints the start screen
      Specified by:
      printLogo in interface ViewInterface
    • askToReloadLastSettings

      public void askToReloadLastSettings​(java.util.List<java.lang.String> savedUsers)
      Asks the user if it wants to reload a previously saved address/username combo
      Specified by:
      askToReloadLastSettings in interface ViewInterface
      Parameters:
      savedUsers - the address/username combos
    • printUserServerCombos

      public void printUserServerCombos​(java.util.List<java.lang.String> options)
      Shows the user the address/username combos
      Specified by:
      printUserServerCombos in interface ViewInterface
      Parameters:
      options - the address/username combos
    • askIP

      public void askIP()
      Asks the user the server address to connect to
      Specified by:
      askIP in interface ViewInterface
    • askUsername

      public void askUsername()
      Asks the user the username it wants to use
      Specified by:
      askUsername in interface ViewInterface
    • lobbyOptions

      public void lobbyOptions​(java.util.List<java.lang.String> options)
      Asks the user if it wants to join or create a lobby
      Specified by:
      lobbyOptions in interface ViewInterface
      Parameters:
      options - the possible options
    • askLobbyName

      public void askLobbyName()
      Asks the user the name for the lobby to be created
      Specified by:
      askLobbyName in interface ViewInterface
    • askLobbySize

      public void askLobbySize()
      Asks the user the number of players for its lobby
      Specified by:
      askLobbySize in interface ViewInterface
    • chooseLobbyToJoin

      public void chooseLobbyToJoin​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> lobbiesAvailable)
      Asks the user which lobby it wants to join
      Specified by:
      chooseLobbyToJoin in interface ViewInterface
      Parameters:
      lobbiesAvailable - a map containing lobbies and their info
      See Also:
      Lobby.lobbyInfo()
    • chooseMatchReload

      public void chooseMatchReload()
      Asks the user if it wants to reload an existing saved match
      Specified by:
      chooseMatchReload in interface ViewInterface
    • chooseGameGods

      public void chooseGameGods​(java.util.List<GodData> allGods, int size)
      Asks the user to choose the gods for the game
      Specified by:
      chooseGameGods in interface ViewInterface
      Parameters:
      allGods - the list of available gods
      size - the number of players
    • chooseUserGod

      public void chooseUserGod​(java.util.List<GodData> possibleGods)
      Asks the user to choose its personal god for the game
      Specified by:
      chooseUserGod in interface ViewInterface
      Parameters:
      possibleGods - a list containing the available gods
    • chooseStartingPlayer

      public void chooseStartingPlayer​(java.util.List<java.lang.String> players)
      Asks the user which player will play first
      Specified by:
      chooseStartingPlayer in interface ViewInterface
      Parameters:
      players - the list of players
    • gameStartScreen

      public void gameStartScreen​(java.util.List<Cell> gameBoard, java.util.List<PlayerData> playerData)
      Updates information about the players and the game
      Specified by:
      gameStartScreen in interface ViewInterface
      Parameters:
      gameBoard - the starting game board
      playerData - the players data
    • showGameBoard

      public void showGameBoard​(java.util.List<Cell> gameBoard)
      Prints the game board on the screen
      Specified by:
      showGameBoard in interface ViewInterface
      Parameters:
      gameBoard - the board to print
    • gameBoardUpdate

      public void gameBoardUpdate​(java.util.List<Cell> gameBoard, java.util.List<PlayerData> players)
      Refreshes the game screen
      Specified by:
      gameBoardUpdate in interface ViewInterface
      Parameters:
      gameBoard - the board to start with
      players - information about the players
    • placeWorker

      public void placeWorker()
      Asks the user to place its worker on the board
      Specified by:
      placeWorker in interface ViewInterface
    • chooseWorker

      public void chooseWorker​(java.util.List<Cell> cells)
      Asks the user to choose a worker
      Specified by:
      chooseWorker in interface ViewInterface
      Parameters:
      cells - the cells containing the user's workers
    • chooseAction

      public void chooseAction​(java.util.List<PossibleActions> possibleActions)
      Asks the user which action to perform
      Specified by:
      chooseAction in interface ViewInterface
      Parameters:
      possibleActions - a list of possible actions
    • moveAction

      public void moveAction​(java.util.List<Cell> gameBoard, java.util.List<Cell> walkableCells)
      Asks the user to select a cell to move its current worker on
      Specified by:
      moveAction in interface ViewInterface
      Parameters:
      gameBoard - the current game board
      walkableCells - the cells on which the worker can be moved to
    • buildAction

      public void buildAction​(java.util.List<Cell> gameBoard, java.util.List<Cell> buildableCells)
      Asks the user to select a cell to build on
      Specified by:
      buildAction in interface ViewInterface
      Parameters:
      gameBoard - the current game board
      buildableCells - the cells on which the worker can build
    • chooseBlockToBuild

      public void chooseBlockToBuild​(java.util.List<Block> buildableBlocks)
      Asks the user which block to build on a cell
      Specified by:
      chooseBlockToBuild in interface ViewInterface
      Parameters:
      buildableBlocks - the possible blocks (always more than one)