Class SnakeGame
java.lang.Object
com.csse3200.game.minigames.snake.SnakeGame
Manages the logic and state of the Snake mini-game, including snake movement, scoring, and
game-over conditions.
-
Constructor Summary
ConstructorsConstructorDescriptionInitialises a new SnakeGame with a grid, snake, apple, and controller. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Attempts to eat the apple in the snake game if the snake has reached it.boolean
Detects if the snake it at the boundary of the gridgetApple()
Method to return apple objectgetGrid()
Methods to return grid objectboolean
int
getScore()
getSnake()
methods to return snake objectvoid
handleSnakeInput
(Direction direction) Update snake direction based on an input direction.void
void
boolean
Determines if the snake has run into itselfvoid
snakeMove
(float delta) Moves the snake and checks for game-over conditions.
-
Constructor Details
-
SnakeGame
public SnakeGame()Initialises a new SnakeGame with a grid, snake, apple, and controller.
-
-
Method Details
-
getSnake
methods to return snake object- Returns:
- the snake
-
getApple
Method to return apple object- Returns:
- the apple
-
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
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()
-