Class Grid

java.lang.Object
com.csse3200.game.minigames.Grid
Direct Known Subclasses:
SnakeGrid

public class Grid extends Object
Represents a grid composed of GridCells. The grid has a fixed width and height and can be used to track the occupancy of cells.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Grid(int width, int height)
    Creates a new Grid with the specified dimensions.
  • Method Summary

    Modifier and Type
    Method
    Description
    getCell(int x, int y)
    Gets the GridCell at the specified coordinates.
    int
    Get the grids height
    int
    Get the grids width
    boolean
    isOccupied(int x, int y)
    Checks if the cell at the specified coordinates is occupied.
    void
    setOccupied(int x, int y, boolean occupied)
    Sets the occupancy status of the cell at the specified coordinates.

    Methods inherited from class java.lang.Object

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

    • Grid

      public Grid(int width, int height)
      Creates a new Grid with the specified dimensions. The grid is composed of GridCells that are initially unoccupied.
      Parameters:
      width - The width of the grid (number of cells in the x-direction).
      height - The height of the grid (number of cells in the y-direction).
  • Method Details

    • getCell

      public GridCell getCell(int x, int y)
      Gets the GridCell at the specified coordinates.
      Parameters:
      x - The x-coordinate of the cell.
      y - The y-coordinate of the cell.
      Returns:
      The GridCell at the specified position, or null if the coordinates are out of bounds.
    • isOccupied

      public boolean isOccupied(int x, int y)
      Checks if the cell at the specified coordinates is occupied.
      Parameters:
      x - The x-coordinate of the cell.
      y - The y-coordinate of the cell.
      Returns:
      True if the cell is occupied, false otherwise.
    • setOccupied

      public void setOccupied(int x, int y, boolean occupied)
      Sets the occupancy status of the cell at the specified coordinates.
      Parameters:
      x - The x-coordinate of the cell.
      y - The y-coordinate of the cell.
      occupied - True if the cell should be marked as occupied, false otherwise.
    • getWidth

      public int getWidth()
      Get the grids width
      Returns:
      the grids width
    • getHeight

      public int getHeight()
      Get the grids height
      Returns:
      the grids height