Package it.polimi.ingsw.server.model
Class WorkerMap
java.lang.Object
it.polimi.ingsw.server.model.WorkerMap
- Direct Known Subclasses:
WorkerBuildMap,WorkerMoveMap
public class WorkerMap
extends java.lang.Object
A 3x3 matrix that represents the cells adjacent to the worker.
The worker is in the central cell of the matrix.
-
Field Summary
Fields Modifier and Type Field Description static intN -
Constructor Summary
-
Method Summary
Modifier and Type Method Description booleananyCellOneLevelHigher()Says if there is any near Cell 1 level higher than the worker's one.protected booleananyTrueCell()Checks if there is any true cell in the matrix.protected voiddomeCellFalse()Sets false any cell containing a dome.protected voidfriendlyWorkerCellFalse()Sets false the cell containing the other worker of the same player.protected CellgetAbsolutePosition(int i, int j)Returns the cell of the Board given its coordinates relative to the WorkerMap.protected booleangetBooleanCellBoard(int i, int j)Returns a cell of the WorkerMap given its absolute coordinates i.e the coordinates of the Board.protected booleangetBooleanCellWorkerMap(int i, int j)Returns a cell of the WorkerMap given its relative coordinates.protected WorkergetWorker()voidlevelDifferenceLessEqualThanX(int x)Sets false cells that are above the worker more than x levels.java.util.ArrayList<Worker>neighboringEnemyWorkers()Finds all neighboring enemy Workers.protected voidoccupiedCellFalse()Sets false any occupied cell, i.e.voidreset()Sets the whole WorkerMap cells true.voidsetCell(int x, int y, boolean bool)Sets the value of a cell of the mapprotected voidsetCenterPosition(boolean value)Sets true or false the central cell of the WorkersMap, i.e.protected voidsetPerimeterFalse()Sets false Cells in perimeter.voidupdateCellsOutOfMap()Sets false cells not contained in Board.
-
Field Details
-
N
public static final int N- See Also:
- Constant Field Values
-
-
Constructor Details
-
WorkerMap
Creates the WorkerMap of a specific worker.- Parameters:
worker- Is the worker on which the WorkerMap is built referring to.
-
-
Method Details
-
getWorker
-
domeCellFalse
protected void domeCellFalse()Sets false any cell containing a dome. -
occupiedCellFalse
protected void occupiedCellFalse()Sets false any occupied cell, i.e. any cell containing a worker or a dome. -
friendlyWorkerCellFalse
protected void friendlyWorkerCellFalse()Sets false the cell containing the other worker of the same player. -
setCenterPosition
protected void setCenterPosition(boolean value)Sets true or false the central cell of the WorkersMap, i.e. the position of the worker.- Parameters:
value- value to set in the center of the matrix.
-
getBooleanCellWorkerMap
protected boolean getBooleanCellWorkerMap(int i, int j)Returns a cell of the WorkerMap given its relative coordinates.- Parameters:
i- Coordinate relative to the WorkerMap.j- Coordinate relative to the WorkerMap.- Returns:
- Selected cell of the WorkerMap.
-
getBooleanCellBoard
protected boolean getBooleanCellBoard(int i, int j)Returns a cell of the WorkerMap given its absolute coordinates i.e the coordinates of the Board.- Parameters:
i- Coordinate relative to the Board.j- Coordinate relative to the Board.- Returns:
- Selected cell of the WorkerMap.
-
getAbsolutePosition
Returns the cell of the Board given its coordinates relative to the WorkerMap.- Parameters:
i- Relative coordinate of MoveMatrix.j- Relative coordinate of MoveMatrix.- Returns:
- Returns Cell of Board given the relative coordinates of the worker, returns null if the Cell is out of the boundaries of the board.
-
levelDifferenceLessEqualThanX
public void levelDifferenceLessEqualThanX(int x)Sets false cells that are above the worker more than x levels. e.g. this is done because the worker cannot move to cells that are 2 or more levels higher.- Parameters:
x- Maximum level difference between any given cell of the WorkerMap and the Worker's cell.
-
anyCellOneLevelHigher
public boolean anyCellOneLevelHigher()Says if there is any near Cell 1 level higher than the worker's one.- Returns:
- True if there is at least one cell 1 level higher, false otherwise.
-
neighboringEnemyWorkers
Finds all neighboring enemy Workers.- Returns:
- Returns all enemy Workers adjacent to the worker.
-
anyTrueCell
protected boolean anyTrueCell()Checks if there is any true cell in the matrix. Useful for lose conditions.- Returns:
- true if there are any true cell, false otherwise.
-
reset
public void reset()Sets the whole WorkerMap cells true. -
updateCellsOutOfMap
public void updateCellsOutOfMap()Sets false cells not contained in Board. It is pretty useful for unableToMove/Build exceptions to work correctly. -
setPerimeterFalse
protected void setPerimeterFalse()Sets false Cells in perimeter. -
setCell
public void setCell(int x, int y, boolean bool)Sets the value of a cell of the map- Parameters:
x- Coordinate of the mapy- Coordinate of the mapbool- value to be set in the given cell
-