Grid Cell - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

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.

Class: GridCell

Package

package com.csse3200.game.components.minigame;

Description

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.

Fields

  • x

    • Type: int
    • Description: x-coordinate of the cell.
  • y

    • Type: int
    • Description: y-coordinate of the cell.
  • occupied

    • Type: boolean
    • Description: A flag indicating whether the cell is currently occupied. It is initially set to false.

Constructor

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.

Methods

public int getX() and public int getY()

  • Description: Retrieves the x-coordinate/ y-coordinate of the cell.
  • Returns: The x-coordinate/ y-coordinate of the cell.

public boolean isOccupied()

  • Description: Checks if the cell is currently occupied.
  • Returns: true if the cell is occupied, false otherwise.

public void setOccupied(boolean occupied)

  • Description: Sets the occupancy status of the cell.
  • Parameters:
    • occupied - true to mark the cell as occupied, false to mark it as unoccupied.