-
Notifications
You must be signed in to change notification settings - Fork 1
Grid Cell
rp3002 edited this page Aug 26, 2024
·
1 revision
The GridCell
class is an important component of the Snake mini-game, representing a single cell within the game's grid. Each GridCell
has a fixed position on the grid and can be either occupied or unoccupied, which is essential for managing the game's logic, such as detecting collisions and determining valid spawn locations for the snake or apples.
package com.csse3200.game.components.minigame;
The GridCell
class defines the properties and behaviour of an individual cell on the game's grid where each cell has specific position (x and y coordinates) and which maintains an occupancy status indicating whether the cell is occupied by the snake or any other object.
-
x
-
Type:
int
- Description: x-coordinate of the cell.
-
Type:
-
y
-
Type:
int
- Description: y-coordinate of the cell.
-
Type:
-
occupied
-
Type:
boolean
-
Description: A flag indicating whether the cell is currently occupied. It is initially set to
false
.
-
Type:
public GridCell(int x, int y)
-
Description: Creates a new
GridCell
at the specified coordinates. The cell is initialized as unoccupied. -
Parameters:
-
x
- x-coordinate of the cell. -
y
- y-coordinate of the cell.
-
- Description: Retrieves the x-coordinate/ y-coordinate of the cell.
- Returns: The x-coordinate/ y-coordinate of the cell.
- Description: Checks if the cell is currently occupied.
-
Returns:
true
if the cell is occupied,false
otherwise.
- Description: Sets the occupancy status of the cell.
-
Parameters:
-
occupied
-true
to mark the cell as occupied,false
to mark it as unoccupied.
-