Class MapGrid

java.lang.Object
model.map.MapGrid

public class MapGrid extends Object
11x11 map grid storing all Cell objects, with helper methods for validating positions and movement.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Cell[][]
    2D array holding all cells.
    static final int
    Map size (11x11).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty MapGrid where every cell is NORMAL.
  • Method Summary

    Modifier and Type
    Method
    Description
    getCell(int row, int col)
    Returns the Cell at the specified position.
    Cell[][]
    Returns the full cell array (used by MapLoader to build the map).
    boolean
    isAdjacentMove(int fromRow, int fromCol, int toRow, int toCol)
    Checks whether a move is exactly 1 step in a straight line (no diagonal).
    boolean
    isValidPosition(int row, int col)
    Checks whether a position is within the map bounds.
    boolean
    isWalkable(int row, int col)
    Checks whether a cell is walkable (includes bounds checking).

    Methods inherited from class java.lang.Object

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

    • SIZE

      public static final int SIZE
      Map size (11x11).
      See Also:
    • cells

      private final Cell[][] cells
      2D array holding all cells.
  • Constructor Details

    • MapGrid

      public MapGrid()
      Creates an empty MapGrid where every cell is NORMAL.
  • Method Details

    • getCell

      public Cell getCell(int row, int col)
      Returns the Cell at the specified position.
      Parameters:
      row - Row (0-10)
      col - Column (0-10)
      Returns:
      Cell at that position
    • isValidPosition

      public boolean isValidPosition(int row, int col)
      Checks whether a position is within the map bounds.
      Parameters:
      row - Row to check
      col - Column to check
      Returns:
      true if the position is within bounds
    • isWalkable

      public boolean isWalkable(int row, int col)
      Checks whether a cell is walkable (includes bounds checking).
      Parameters:
      row - Row
      col - Column
      Returns:
      true if walkable
    • isAdjacentMove

      public boolean isAdjacentMove(int fromRow, int fromCol, int toRow, int toCol)
      Checks whether a move is exactly 1 step in a straight line (no diagonal).
      Parameters:
      fromRow - Starting row
      fromCol - Starting column
      toRow - Destination row
      toCol - Destination column
      Returns:
      true if the move is a single straight-line step
    • getCells

      public Cell[][] getCells()
      Returns the full cell array (used by MapLoader to build the map).
      Returns:
      The complete Cell[][] of the map