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 int N  
  • Constructor Summary

    Constructors 
    Constructor Description
    WorkerMap​(Worker worker)
    Creates the WorkerMap of a specific worker.
  • Method Summary

    Modifier and Type Method Description
    boolean anyCellOneLevelHigher()
    Says if there is any near Cell 1 level higher than the worker's one.
    protected boolean anyTrueCell()
    Checks if there is any true cell in the matrix.
    protected void domeCellFalse()
    Sets false any cell containing a dome.
    protected void friendlyWorkerCellFalse()
    Sets false the cell containing the other worker of the same player.
    protected Cell getAbsolutePosition​(int i, int j)
    Returns the cell of the Board given its coordinates relative to the WorkerMap.
    protected boolean getBooleanCellBoard​(int i, int j)
    Returns a cell of the WorkerMap given its absolute coordinates i.e the coordinates of the Board.
    protected boolean getBooleanCellWorkerMap​(int i, int j)
    Returns a cell of the WorkerMap given its relative coordinates.
    protected Worker getWorker()  
    void levelDifferenceLessEqualThanX​(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 void occupiedCellFalse()
    Sets false any occupied cell, i.e.
    void reset()
    Sets the whole WorkerMap cells true.
    void setCell​(int x, int y, boolean bool)
    Sets the value of a cell of the map
    protected void setCenterPosition​(boolean value)
    Sets true or false the central cell of the WorkersMap, i.e.
    protected void setPerimeterFalse()
    Sets false Cells in perimeter.
    void updateCellsOutOfMap()
    Sets false cells not contained in Board.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • WorkerMap

      public WorkerMap​(Worker worker)
      Creates the WorkerMap of a specific worker.
      Parameters:
      worker - Is the worker on which the WorkerMap is built referring to.
  • Method Details

    • getWorker

      protected Worker 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

      protected Cell getAbsolutePosition​(int i, int j)
      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

      public java.util.ArrayList<Worker> 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 map
      y - Coordinate of the map
      bool - value to be set in the given cell