Package com.csse3200.game.minigames
Class Grid
java.lang.Object
com.csse3200.game.minigames.Grid
- Direct Known Subclasses:
SnakeGrid
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
ConstructorsConstructorDescriptionGrid
(int width, int height) Creates a new Grid with the specified dimensions. -
Method Summary
Modifier and TypeMethodDescriptiongetCell
(int x, int y) Gets the GridCell at the specified coordinates.int
Get the grids heightint
getWidth()
Get the grids widthboolean
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.
-
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
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
-