help me please :(
package com.codegym.games.snake;
import com.codegym.engine.cell.*;
public class SnakeGame extends Game{
private static final int GOAL = 28;
public static final int HEIGHT = 15;
public static final int WIDTH = 15;
private Snake snake;
private int turnDelay;
private Apple apple;
private boolean isGameStopped;
@Override
public void initialize(){
setScreenSize(WIDTH,HEIGHT);
createGame();
}
@Override
public void onTurn(int x){
if(apple.isAlive == false){
createNewApple();
}
snake.move(apple);
if(snake.isAlive == false){
gameOver();
}
if(snake.getLength() > GOAL){
win();
}
drawScene();
//apple.move();
}
@Override
public void onKeyPress(Key key){
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);
}
else
if(key == Key.SPACE && isGameStopped == true){
createGame();
}
}
private void createGame(){
snake = new Snake(WIDTH/2,HEIGHT/2);
//apple = new Apple(5,5);
isGameStopped = false;
createNewApple();
drawScene();
//snake.move(apple);
turnDelay =300;
setTurnTimer(turnDelay);
/*Apple apple = new Apple(7,7);
apple.draw(this);*/
}
private void gameOver(){
//@Override
stopTurnTimer();
//if(isGameStopped == true) {
isGameStopped = true;
showMessageDialog(Color.NONE, "END GAME", Color.RED, 25);
}
private void win(){
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.NONE, "YOU WON THE GAME", Color.GREEN, 25);
}
private void drawScene(){
for(int x = 0; x<WIDTH; x++){
for(int y = 0; y<HEIGHT; y++){
setCellValueEx(x, y, Color.GREEN,"");
}
}
snake.draw(this);
apple.draw(this);
}
private void createNewApple(){
while(true){
int x = getRandomNumber(WIDTH);
int y = getRandomNumber(HEIGHT);
apple = new Apple(x,y);
boolean checCol = snake.checkCollision(apple);
if(checCol == false)
break;
}
}
}