Подскажите, пожалуйста, в чем ошибка?
package com.javarush.games.snake;
import com.javarush.engine.cell.*;
public class SnakeGame extends Game {
private Snake snake;
private Apple apple;
public static final int WIDTH = 15;
public static final int HEIGHT = 15;
private static final int GOAL = 28;
private boolean isGameStopped;
private int turnDelay;
public void initialize() {
setScreenSize(WIDTH, HEIGHT);
createGame();
}
public void onKeyPress(Key key) {
if (key == Key.UP) {
snake.setDirection(Direction.UP);
}
else if (key == Key.DOWN) {
snake.setDirection(Direction.DOWN);
}
else if (key == Key.LEFT) {
snake.setDirection(Direction.LEFT);
}
else if (key == Key.RIGHT) {
snake.setDirection(Direction.RIGHT);
}
else if (key == Key.SPACE && isGameStopped) {
createGame();
}
}
private void createNewApple() {
int applex = getRandomNumber(WIDTH);
int appley = getRandomNumber(HEIGHT);
apple = new Apple(applex, appley);
while (snake.checkCollision(apple)) {
applex = getRandomNumber(WIDTH);
appley = getRandomNumber(HEIGHT);
apple = new Apple(applex, appley);
}
}
private void drawScene() {
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < WIDTH; y++) {
setCellValueEx(x, y, Color.DARKSEAGREEN, "");
}
}
snake.draw(this);
apple.draw(this);
}
public void onTurn(int x) {
snake.move(apple);
if (apple.isAlive == false) {
createNewApple();
}
if (snake.isAlive == false) {
gameOver();
}
if (snake.getLength() > GOAL) {
win();
}
drawScene();
}
private void win() {
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.WHITE, "YOU WIN", Color.BLACK, 7);
}
private void createGame() {
Snake snake1 = new Snake(WIDTH / 2, HEIGHT / 2);
createNewApple();
snake = snake1;
turnDelay = 300;
setTurnTimer(turnDelay);
isGameStopped = false;
drawScene();
}
private void gameOver() {
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.WHITE, "GAMEOVER", Color.BLACK, 5);
}
}