Class SnakeGame

java.lang.Object
com.csse3200.game.minigames.snake.SnakeGame

public class SnakeGame extends Object
Manages the logic and state of the Snake mini-game, including snake movement, scoring, and game-over conditions.
  • Constructor Details

    • SnakeGame

      public SnakeGame()
      Initialises a new SnakeGame with a grid, snake, apple, and controller.
  • Method Details

    • getSnake

      public Snake getSnake()
      methods to return snake object
      Returns:
      the snake
    • getApple

      public Apple getApple()
      Method to return apple object
      Returns:
      the apple
    • getGrid

      public SnakeGrid getGrid()
      Methods to return grid object
      Returns:
      the grid
    • getIsGameOver

      public boolean getIsGameOver()
    • setIsGameOver

      public void setIsGameOver()
    • getScore

      public int getScore()
    • attemptEatFruit

      public boolean attemptEatFruit()
      Attempts to eat the apple in the snake game if the snake has reached it. If the snake can eat the apple then a new apple will spawn, the snake will grow and the score will increase.
    • handleSnakeInput

      public void handleSnakeInput(Direction direction)
      Update snake direction based on an input direction. If the input direction is reversed 180 degrees from the current direction of the snake, it will not change.
      Parameters:
      direction - the direction to update to
    • snakeMove

      public void snakeMove(float delta)
      Moves the snake and checks for game-over conditions.
      Parameters:
      delta - The time elapsed since the last update.
    • boundaryDetection

      public boolean boundaryDetection()
      Detects if the snake it at the boundary of the grid
      Returns:
      true if it is, false otherwise
    • snakeCollisionDetection

      public boolean snakeCollisionDetection()
      Determines if the snake has run into itself
      Returns:
      true if the head of the snake has run into the body, otherwise false
    • increaseSnakeSpeed

      public void increaseSnakeSpeed()