Class Terminal
java.lang.Object
it.polimi.ingsw.client.cli_graphics.Terminal
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringstatic final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringstatic final Stringprivate static final Stringprivate intprivate static final Stringprivate static final Stringprivate final intprivate final intprivate List<UnicodeString>private static final Stringprivate intprivate static final Stringprivate PrintStreamprivate String[][]private static final Map<TowerColor,String> private static final String -
Constructor Summary
ConstructorsConstructorDescriptionTerminal(int maxRowsNumber, int maxColumnsNumber, PrintStream target) Minimum width 10 -
Method Summary
Modifier and TypeMethodDescriptionprivate voidclean()This method cleans everything in the terminal except the logs window in the terminal.private voidThis method cleans the entire terminal.private voidThis method cleans the logs window in the terminal.private StringThis method gets a character in input (in the form of a String) and applies the given color to it.private Stringvoidflush()This method flushes the content of the terminal to the target.getUsernameFromSchoolBoardID(Map<String, Integer> usernameToSchoolBoardId, int schoolBoardId) This method returns the username corresponding to the given schoolBoardId wrapped in an Optional, if it exists.voidThis method logs the given string with the default color.voidThis method logs the given string with the cyan color.voidThis method logs the given string with the color indicating an error.voidThis method logs the given string with the purple color.voidlogSuccess(String stringToBeLogged) This method logs the given string with the color indicating success.voidlogWarning(String stringToBeLogged) This method logs the given string with the color indicating a warning.private voidlogWithColor(String stringToBeLogged, String ansiColorCode) This method logs the given string with the given color (represented with a string).private voidThis method puts the given character in the given position in the terminal.voidputStringAsComponent(List<String> hyperString, int row, int column) Prints the hyperString to the terminalprivate voidrenderArchipelagos(List<LightArchipelago> archipelagos, int motherNaturePosition, int row, int col) This method renders all the archipelagos in the terminal.private voidrenderAvailableCharacters(List<LightPlayableCharacter> availableCharacters, int row, int col) private voidrenderClouds(List<List<Color>> clouds, int row, int col) This method renders all the clouds in the terminal.private voidrenderSchoolBoards(List<LightSchoolBoard> schoolBoards, Map<String, Integer> usernameToSchoolBoardId, int currentPlayerSchoolBoardId, int row, int col) This method renders all the schoolBoards in the terminal.voidupdateGameState(LightGameState lightGameState) This method updates the terminal with the new lightGameState.private voidupdateLogs(List<UnicodeString> logs) This method prints the logs to the terminal.
-
Field Details
-
rows
private int rows -
cols
private int cols -
terminal
-
target
-
loggerWidth
private final int loggerWidth -
loggerHeight
private final int loggerHeight -
logs
-
ANSI_RESET
- See Also:
-
ANSI_BLACK
- See Also:
-
ANSI_RED
- See Also:
-
ANSI_GREEN
- See Also:
-
ANSI_YELLOW
- See Also:
-
ANSI_BLUE
- See Also:
-
ANSI_GREY
- See Also:
-
ANSI_PURPLE
- See Also:
-
ANSI_CYAN
- See Also:
-
ANSI_WHITE
- See Also:
-
ANSI_BLACK_BACKGROUND
- See Also:
-
ANSI_WHITE_BACKGROUND
- See Also:
-
studentColorToANSI
-
towerColorToANSI
-
studentSymbol
- See Also:
-
professorSymbol
- See Also:
-
towerSymbol
- See Also:
-
filledCircleSymbol
- See Also:
-
lockSymbol
- See Also:
-
-
Constructor Details
-
Terminal
Minimum width 10- Parameters:
maxRowsNumber- is the maximum number of rows that can be used in the terminal.maxColumnsNumber- is the maximum number of columns that can be used in the terminal.target- represents where the terminal will be printed.
-
-
Method Details
-
put
This method puts the given character in the given position in the terminal.- Parameters:
row- is the parameter that indicates the row coordinate in which the given character will be written.column- is the parameter that indicates the column coordinate in which the given character will be written.character- is the character that will be written.
-
color
This method gets a character in input (in the form of a String) and applies the given color to it.- Parameters:
s- is the character that will be returnedtextColorANSI- is the color with which the character will be written- Returns:
- the given character with the given color applied to it
-
color
-
putStringAsComponent
Prints the hyperString to the terminal- Parameters:
hyperString- list of characters, represented as a list of stringsrow- is the row coordinate from which the printing process will startcolumn- is the column coordinate from which the printing process will start
-
flush
public void flush()This method flushes the content of the terminal to the target. -
clean
private void clean()This method cleans everything in the terminal except the logs window in the terminal. -
cleanLogs
private void cleanLogs()This method cleans the logs window in the terminal. -
cleanEverything
private void cleanEverything()This method cleans the entire terminal. -
log
This method logs the given string with the default color.- Parameters:
stringToBeLogged- is the string to be logged.
-
logSuccess
This method logs the given string with the color indicating success.- Parameters:
stringToBeLogged- is the string to be logged.
-
logError
This method logs the given string with the color indicating an error.- Parameters:
stringToBeLogged- is the string to be logged.
-
logCyan
This method logs the given string with the cyan color.- Parameters:
stringToBeLogged- is the string to be logged.
-
logPurple
This method logs the given string with the purple color.- Parameters:
stringToBeLogged- is the string to be logged.
-
logWarning
This method logs the given string with the color indicating a warning.- Parameters:
stringToBeLogged- is the string to be logged.
-
logWithColor
This method logs the given string with the given color (represented with a string).- Parameters:
stringToBeLogged- is the string to be logged.ansiColorCode- is the color in which the given string will be logged.
-
updateLogs
This method prints the logs to the terminal.- Parameters:
logs- represents the list of logs that will be printed to the terminal.
-
updateGameState
This method updates the terminal with the new lightGameState.- Parameters:
lightGameState- is the new lightGameState that will be rendered on the terminal.
-
renderAvailableCharacters
private void renderAvailableCharacters(List<LightPlayableCharacter> availableCharacters, int row, int col) -
getUsernameFromSchoolBoardID
private Optional<String> getUsernameFromSchoolBoardID(Map<String, Integer> usernameToSchoolBoardId, int schoolBoardId) This method returns the username corresponding to the given schoolBoardId wrapped in an Optional, if it exists. Optional.empty() if the provided schoolBoardId doesn't exist.- Parameters:
usernameToSchoolBoardId- is the map that maps usernames to schoolBoardIds.schoolBoardId- represents the schoolBoardId for which you want to get the username.- Returns:
- the username corresponding to the given schoolBoardId
-
renderSchoolBoards
private void renderSchoolBoards(List<LightSchoolBoard> schoolBoards, Map<String, Integer> usernameToSchoolBoardId, int currentPlayerSchoolBoardId, int row, int col) This method renders all the schoolBoards in the terminal.- Parameters:
schoolBoards- is a list containing the schoolBoard of every player.usernameToSchoolBoardId- is a map that maps the username to the schoolBoardId of each player.currentPlayerSchoolBoardId- indicates the schoolBoardId of the current player.row- indicates the row from which the schoolBoards will be printed.col- indicates the column from which the schoolBoards will be printed.
-
renderArchipelagos
private void renderArchipelagos(List<LightArchipelago> archipelagos, int motherNaturePosition, int row, int col) This method renders all the archipelagos in the terminal.- Parameters:
archipelagos- is a list containing all the archipelagos.motherNaturePosition- is an integer that indicates the index of archipelagos in which motherNature finds itself.row- indicates the row from which the archipelagos will be printed.col- indicates the column from which the archipelagos will be printed.
-
renderClouds
This method renders all the clouds in the terminal.- Parameters:
clouds- is a list containing all the clouds.row- indicates the row from which the clouds will be printed.col- indicates the column from which the clouds will be printed.
-