Java-Snake-Game icon indicating copy to clipboard operation
Java-Snake-Game copied to clipboard

Snake slightly leaves the board before wall collision is handled

Open Zsozsiii opened this issue 1 month ago • 0 comments

When the snake hits a wall, the head can step slightly beyond the visible board boundary before the game over state is triggered. If the snake moves towards a wall, on the last step its head coordinate briefly exceeds the board limit (e.g. X or Y becomes equal to or greater than the board size). Only after this happens does the collision logic stop the game. Visually, the snake appears to “step out of the board” for one tick before the game ends. The game should detect the wall collision at the boundary: the head should not move outside the playable area. As soon as the next move would cross the board limit, the game should register a collision and immediately trigger game over, without an intermediate position beyond the board.

Zsozsiii avatar Dec 06 '25 13:12 Zsozsiii