Class Terminal

java.lang.Object
it.polimi.ingsw.client.cli_graphics.Terminal

public class Terminal extends Object
  • Field Details

  • Constructor Details

    • Terminal

      public Terminal(int maxRowsNumber, int maxColumnsNumber, PrintStream target)
      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

      private void put(int row, int column, String character)
      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

      private String color(String s, String textColorANSI)
      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 returned
      textColorANSI - is the color with which the character will be written
      Returns:
      the given character with the given color applied to it
    • color

      private String color(String string, String textColorANSI, String backgroundColorANSI)
    • putStringAsComponent

      public void putStringAsComponent(List<String> hyperString, int row, int column)
      Prints the hyperString to the terminal
      Parameters:
      hyperString - list of characters, represented as a list of strings
      row - is the row coordinate from which the printing process will start
      column - 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

      public void log(String stringToBeLogged)
      This method logs the given string with the default color.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logSuccess

      public void logSuccess(String stringToBeLogged)
      This method logs the given string with the color indicating success.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logError

      public void logError(String stringToBeLogged)
      This method logs the given string with the color indicating an error.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logCyan

      public void logCyan(String stringToBeLogged)
      This method logs the given string with the cyan color.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logPurple

      public void logPurple(String stringToBeLogged)
      This method logs the given string with the purple color.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logWarning

      public void logWarning(String stringToBeLogged)
      This method logs the given string with the color indicating a warning.
      Parameters:
      stringToBeLogged - is the string to be logged.
    • logWithColor

      private void logWithColor(String stringToBeLogged, String ansiColorCode)
      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

      private void updateLogs(List<UnicodeString> logs)
      This method prints the logs to the terminal.
      Parameters:
      logs - represents the list of logs that will be printed to the terminal.
    • updateGameState

      public void updateGameState(LightGameState lightGameState)
      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

      private void renderClouds(List<List<Color>> clouds, int row, int col)
      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.