Problems with createNewApple() method.
At this stage, we have a bug — an apple can appear on top of the snake.
To fix the bug, use our checkCollision(GameObject) method. The createNewApple() method must create a new apple (with new coordinates) in a loop until the call to the checkCollision(GameObject) method returns false.
Let's also implement logic to restart the game by pressing the SPACE key. The game restarts only if it is stopped.
Requirements:
- The createNewApple() method must call the checkCollision(GameObject) method, passing an Apple object as the argument.
- The createNewApple() method must call the checkCollision(GameObject) method as long as the apple's coordinates match the coordinates of any of the snake segments.
- The onKeyPress(Key) method must call the createGame() method if the passed argument is Key.SPACE and the game is stopped (isGameStopped == true).
Bud1% @ @ @ @E%DSDB` @ @ @