why is this part of my code causing problems and saying illegal start of expression for public void move (Apple apple) ? im really lost (im referring to the commented part in the Snake class inside the setDirection method)
package com.codegym.games.snake;
import com.codegym.engine.cell.*;
public class SnakeGame extends Game {
public static final int WIDTH = 15;
public static final int HEIGHT = 15;
private static final int GOAL = 28;
private Snake snake;
private Apple apple;
private int turnDelay;
private boolean isGameStopped;
@Override
public void initialize() {
setScreenSize(WIDTH, HEIGHT);
createGame();
}
private void createGame(){
turnDelay = 300;
setTurnTimer(turnDelay);
snake = new Snake(WIDTH/2, HEIGHT/2);
createNewApple();
isGameStopped = false;
drawScene();
}
private void drawScene(){
for (int x = 0; x < WIDTH; x++){
for (int y = 0; y < HEIGHT; y++){
setCellValueEx(x, y, Color.DARKGREEN, "");
}
}
snake.draw(this);
apple.draw(this);
}
private void createNewApple(){
Apple newApple;
do {
int x = getRandomNumber(WIDTH);
int y = getRandomNumber(HEIGHT);
newApple = new Apple(x, y);
}
while (snake.checkCollision(newApple));
apple = newApple;
}
@Override
public void onTurn(int go){
snake.move(apple);
if (apple.isAlive == false){
createNewApple();
}
if (!snake.isAlive){
gameOver();
}
if (snake.getLength() > GOAL){
win();
}
drawScene();
}
@Override
public void onKeyPress(Key key){
if (key == Key.SPACE && isGameStopped == true){
createGame();
}
if (key == Key.LEFT){
snake.setDirection(Direction.LEFT);
} else if (key == Key.RIGHT){
snake.setDirection(Direction.RIGHT);
} else if (key == Key.DOWN){
snake.setDirection(Direction.DOWN);
} else if (key == Key.UP){
snake.setDirection(Direction.UP);
}
}
private void gameOver(){
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.NONE, "GAME OVER!", Color.RED, 50);
}
private void win(){
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.WHITE, "u win!", Color.BLUE, 50);
}
}