java.lang.Object
it.polimi.ingsw.view.cli.console.graphics.components.Rectangle
it.polimi.ingsw.view.cli.console.graphics.components.WindowItem
it.polimi.ingsw.view.cli.console.graphics.components.Window
it.polimi.ingsw.view.cli.console.printers.BoardUtils
- All Implemented Interfaces:
KeyEventListener
- Direct Known Subclasses:
BasicPrinterBoardUtils
,FancyPrinterBoardUtils
public abstract class BoardUtils extends Window
-
Field Summary
Fields Modifier and Type Field Description protected int
boardHeight
protected int
boardWidth
protected java.util.List<PrintableObject>
buildingBlocks
protected java.lang.String[][]
cachedBoard
protected java.util.List<PrintableObject>
cellFrames
protected int
cellHeight
protected int
cellWidth
protected java.lang.String[][]
emptyBoard
protected int
horizontalWallWidth
protected java.util.List<Cell>
lastGameBoardPrinted
protected java.util.List<PlayerData>
playerData
protected int
verticalWallWidth
protected java.util.List<PrintableObject>
workers
Fields inherited from class it.polimi.ingsw.view.cli.console.graphics.components.Window
background, cli, enableInputOnReturn, returnTo
Fields inherited from class it.polimi.ingsw.view.cli.console.graphics.components.WindowItem
activeItems, id, parent, passiveItems
-
Constructor Summary
Constructors Constructor Description BoardUtils(Window parent, java.lang.String id)
Default constructor
Creates a new BoardUtils window, loading its settings from file -
Method Summary
Modifier and Type Method Description protected java.lang.String[][]
cloneMatrix(java.lang.String[][] input)
Clones a String matrixprotected void
highlight(Cell cell, java.lang.String[][] board)
Draws a frame around some given cellsabstract void
highlightWorkers(java.util.List<Cell> cells)
Highlights the user's workersprotected void
overrideCachedBoard(java.util.List<Cell> board)
Overrides, without checking for diffs, the cached gameBoardprotected void
setCachedBoard(java.util.List<Cell> gameBoard)
Sets the first version of a board, useful in case of a restoration from a saved gameabstract void
showGameBoard()
abstract void
showGameBoard(java.util.List<Cell> toHighlight)
Shows the current gameBoard on the screen, highlighting some cellsprotected java.lang.String[][]
subMatrix(java.lang.String[][] input, int startRow, int startCol, int finalRow, int finalCol)
Retrieves a subMatrix from a bigger matrixprotected java.util.List<Cell>
updateCachedBoard(java.util.List<Cell> board)
Updates the cached boardvoid
updateGameData(java.util.List<Cell> board, java.util.List<PlayerData> players)
Updates information about the game and the playersMethods inherited from class it.polimi.ingsw.view.cli.console.graphics.components.Window
addToBackground, getCli, getReturnTo, show
Methods inherited from class it.polimi.ingsw.view.cli.console.graphics.components.WindowItem
addActiveItem, addPassiveItem, currentActiveItem, drawShadows, getID, getParent, hideShadows, maxStringLength, nextActiveItem, previousActiveItem, remove
Methods inherited from class it.polimi.ingsw.view.cli.console.graphics.components.Rectangle
drawBackground, drawBorders, findCenter, getBackgroundColor, getColor, getHeight, getInitCoord, getTextColor, getWidth, hideBorders, loadPropertiesFile
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface it.polimi.ingsw.view.cli.console.KeyEventListener
onArrowDown, onArrowLeft, onArrowRight, onArrowUp, onBackspace, onCarriageReturn, onPrintableKey, onTab
-
Field Details
-
playerData
-
boardWidth
protected final int boardWidth -
boardHeight
protected final int boardHeight -
verticalWallWidth
protected final int verticalWallWidth -
horizontalWallWidth
protected final int horizontalWallWidth -
cellWidth
protected final int cellWidth -
cellHeight
protected final int cellHeight -
buildingBlocks
-
workers
-
cellFrames
-
emptyBoard
protected final java.lang.String[][] emptyBoard -
cachedBoard
protected final java.lang.String[][] cachedBoard -
lastGameBoardPrinted
-
-
Constructor Details
-
BoardUtils
Default constructor
Creates a new BoardUtils window, loading its settings from file- Parameters:
parent
- the parentid
- the Window id- Throws:
java.io.IOException
-
-
Method Details
-
showGameBoard
public abstract void showGameBoard() -
showGameBoard
Shows the current gameBoard on the screen, highlighting some cells- Parameters:
toHighlight
- the cells to highlight
-
highlightWorkers
Highlights the user's workers- Parameters:
cells
- the cells containing the user's workers
-
updateGameData
Updates information about the game and the players- Parameters:
board
- the game boardplayers
- information about the players
-
setCachedBoard
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
Overrides, without checking for diffs, the cached gameBoard- Parameters:
board
- the new board
-
updateCachedBoard
Updates the cached boardAssuming 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 matrixstartRow
- the input row coordinate to start extracting the subMatrixstartCol
- the input column coordinate to start extracting the subMatrixfinalRow
- the subMatrix number of rowsfinalCol
- the subMatrix number of columns- Returns:
- the required subMatrix
-
highlight
Draws a frame around some given cellsSince 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 highlightboard
- the board to print the frame on
-