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.Locklock -
Constructor Summary
Constructors Constructor Description CLI(boolean enableRawMode)Default constructor -
Method Summary
Modifier and Type Method Description voidaskIP()Asks the user the server address to connect tovoidaskLobbyName()Asks the user the name for the lobby to be createdvoidaskLobbySize()Asks the user the number of players for its lobbyvoidaskToReloadLastSettings(java.util.List<java.lang.String> savedUsers)Asks the user if it wants to reload a previously saved address/username combovoidaskUsername()Asks the user the username it wants to usevoidbuildAction(java.util.List<Cell> gameBoard, java.util.List<Cell> buildableCells)Asks the user to select a cell to build onvoidchooseAction(java.util.List<PossibleActions> possibleActions)Asks the user which action to performvoidchooseBlockToBuild(java.util.List<Block> buildableBlocks)Asks the user which block to build on a cellvoidchooseGameGods(java.util.List<GodData> allGods, int size)Asks the user to choose the gods for the gamevoidchooseLobbyToJoin(java.util.Map<java.lang.String,java.util.List<java.lang.String>> lobbiesAvailable)Asks the user which lobby it wants to joinvoidchooseMatchReload()Asks the user if it wants to reload an existing saved matchvoidchooseStartingPlayer(java.util.List<java.lang.String> players)Asks the user which player will play firstvoidchooseUserGod(java.util.List<GodData> possibleGods)Asks the user to choose its personal god for the gamevoidchooseWorker(java.util.List<Cell> cells)Asks the user to choose a workerbooleanenableRawMode()Determines if the terminal running the application allows non-canonical modevoidevaluateInput(java.lang.String input)Passes a string to the inputManagervoidgameBoardUpdate(java.util.List<Cell> gameBoard, java.util.List<PlayerData> players)Refreshes the game screenvoidgameStartScreen(java.util.List<Cell> gameBoard, java.util.List<PlayerData> playerData)Updates information about the players and the gamevoidlobbyOptions(java.util.List<java.lang.String> options)Asks the user if it wants to join or create a lobbyvoidmoveAction(java.util.List<Cell> gameBoard, java.util.List<Cell> walkableCells)Asks the user to select a cell to move its current worker onvoidplaceWorker()Asks the user to place its worker on the boardvoidprintLogo()Prints the start screenvoidprintUserServerCombos(java.util.List<java.lang.String> options)Shows the user the address/username combosvoidsetInputManager(InputManager inputManager)Sets the InputManager to parse the inputsvoidshowErrorMessage(java.lang.String error)Shows an error messagevoidshowGameBoard(java.util.List<Cell> gameBoard)Prints the game board on the screenvoidshowSuccessMessage(java.lang.String message)Shows a success message
-
Field Details
-
lock
protected static java.util.concurrent.locks.Lock lock
-
-
Constructor Details
-
CLI
public CLI(boolean enableRawMode) throws java.io.IOExceptionDefault 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
Sets the InputManager to parse the inputs- Specified by:
setInputManagerin interfaceViewInterface- 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:
showErrorMessagein interfaceViewInterface- Parameters:
error- the error message
-
showSuccessMessage
public void showSuccessMessage(java.lang.String message)Shows a success message- Specified by:
showSuccessMessagein interfaceViewInterface- Parameters:
message- the message
-
printLogo
public void printLogo()Prints the start screen- Specified by:
printLogoin interfaceViewInterface
-
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:
askToReloadLastSettingsin interfaceViewInterface- 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:
printUserServerCombosin interfaceViewInterface- Parameters:
options- the address/username combos
-
askIP
public void askIP()Asks the user the server address to connect to- Specified by:
askIPin interfaceViewInterface
-
askUsername
public void askUsername()Asks the user the username it wants to use- Specified by:
askUsernamein interfaceViewInterface
-
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:
lobbyOptionsin interfaceViewInterface- Parameters:
options- the possible options
-
askLobbyName
public void askLobbyName()Asks the user the name for the lobby to be created- Specified by:
askLobbyNamein interfaceViewInterface
-
askLobbySize
public void askLobbySize()Asks the user the number of players for its lobby- Specified by:
askLobbySizein interfaceViewInterface
-
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:
chooseLobbyToJoinin interfaceViewInterface- 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:
chooseMatchReloadin interfaceViewInterface
-
chooseGameGods
Asks the user to choose the gods for the game- Specified by:
chooseGameGodsin interfaceViewInterface- Parameters:
allGods- the list of available godssize- the number of players
-
chooseUserGod
Asks the user to choose its personal god for the game- Specified by:
chooseUserGodin interfaceViewInterface- 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:
chooseStartingPlayerin interfaceViewInterface- Parameters:
players- the list of players
-
gameStartScreen
Updates information about the players and the game- Specified by:
gameStartScreenin interfaceViewInterface- Parameters:
gameBoard- the starting game boardplayerData- the players data
-
showGameBoard
Prints the game board on the screen- Specified by:
showGameBoardin interfaceViewInterface- Parameters:
gameBoard- the board to print
-
gameBoardUpdate
Refreshes the game screen- Specified by:
gameBoardUpdatein interfaceViewInterface- Parameters:
gameBoard- the board to start withplayers- information about the players
-
placeWorker
public void placeWorker()Asks the user to place its worker on the board- Specified by:
placeWorkerin interfaceViewInterface
-
chooseWorker
Asks the user to choose a worker- Specified by:
chooseWorkerin interfaceViewInterface- Parameters:
cells- the cells containing the user's workers
-
chooseAction
Asks the user which action to perform- Specified by:
chooseActionin interfaceViewInterface- Parameters:
possibleActions- a list of possible actions
-
moveAction
Asks the user to select a cell to move its current worker on- Specified by:
moveActionin interfaceViewInterface- Parameters:
gameBoard- the current game boardwalkableCells- the cells on which the worker can be moved to
-
buildAction
Asks the user to select a cell to build on- Specified by:
buildActionin interfaceViewInterface- Parameters:
gameBoard- the current game boardbuildableCells- the cells on which the worker can build
-
chooseBlockToBuild
Asks the user which block to build on a cell- Specified by:
chooseBlockToBuildin interfaceViewInterface- Parameters:
buildableBlocks- the possible blocks (always more than one)
-