Module AM37

Class BoardUtils

All Implemented Interfaces:
KeyEventListener
Direct Known Subclasses:
BasicPrinterBoardUtils, FancyPrinterBoardUtils

public abstract class BoardUtils
extends Window
  • Field Details

  • Constructor Details

    • BoardUtils

      public BoardUtils​(Window parent, java.lang.String id) throws java.io.IOException
      Default constructor
      Creates a new BoardUtils window, loading its settings from file
      Parameters:
      parent - the parent
      id - the Window id
      Throws:
      java.io.IOException
  • Method Details

    • showGameBoard

      public abstract void showGameBoard()
    • showGameBoard

      public abstract void showGameBoard​(java.util.List<Cell> toHighlight)
      Shows the current gameBoard on the screen, highlighting some cells
      Parameters:
      toHighlight - the cells to highlight
    • highlightWorkers

      public abstract void highlightWorkers​(java.util.List<Cell> cells)
      Highlights the user's workers
      Parameters:
      cells - the cells containing the user's workers
    • updateGameData

      public void updateGameData​(java.util.List<Cell> board, java.util.List<PlayerData> players)
      Updates information about the game and the players
      Parameters:
      board - the game board
      players - information about the players
    • setCachedBoard

      protected void setCachedBoard​(java.util.List<Cell> gameBoard)
      Sets the first version of a board, useful in case of a restoration from a saved game
      Parameters:
      gameBoard - the new gameBoard to set
    • overrideCachedBoard

      protected void overrideCachedBoard​(java.util.List<Cell> board)
      Overrides, without checking for diffs, the cached gameBoard
      Parameters:
      board - the new board
    • updateCachedBoard

      protected java.util.List<Cell> updateCachedBoard​(java.util.List<Cell> board)
      Updates the cached board

      Assuming that both the cached and new board are ordered in the same way (see GameBoard.getAllCells()), this method updates the cached board to a new provided version, ready to be printed.

      Parameters:
      board - the updated board
      Returns:
      a list containing the updated cells
    • cloneMatrix

      protected java.lang.String[][] cloneMatrix​(java.lang.String[][] input)
      Clones a String matrix
      Parameters:
      input - the matrix to clone
      Returns:
      a copy of the input
    • subMatrix

      protected java.lang.String[][] subMatrix​(java.lang.String[][] input, int startRow, int startCol, int finalRow, int finalCol)
      Retrieves a subMatrix from a bigger matrix
      Parameters:
      input - the input matrix
      startRow - the input row coordinate to start extracting the subMatrix
      startCol - the input column coordinate to start extracting the subMatrix
      finalRow - the subMatrix number of rows
      finalCol - the subMatrix number of columns
      Returns:
      the required subMatrix
    • highlight

      protected void highlight​(Cell cell, java.lang.String[][] board)
      Draws a frame around some given cells

      Since the frame should not be saved on the original board, the decorateCell(it.polimi.ingsw.view.cli.console.graphics.components.PrintableObject, java.lang.String[][], int, int) method requires a String[][] parameter on which the frame will be printed.

      Parameters:
      cell - the cell to highlight
      board - the board to print the frame on