Hey, can anyone check what's wrong with my game? I probably mess something with drawing function at part 17/20. Since this time it doesn't draw game, just white square(it worked before). The game compile and I pass all further requirements but it's still not working :( Or is it possible to recover my progress at begin of part 17?
package com.codegym.games.snake;
import com.codegym.engine.cell.*;
public class SnakeGame extends Game {
public static final int HEIGHT = 15;
public static final int WIDTH = 15;
private static final int GOAL = 28;
private Snake snake;
private int turnDelay;
private Apple apple;
private boolean isGameStopped;
private int score;
@Override
public void initialize(){
setScreenSize(WIDTH,HEIGHT);
createGame();
}
@Override
public void onTurn(int x){
snake.move(apple);
if(!apple.isAlive){
createNewApple();
setScore(score=score+5);
setTurnTimer(turnDelay-=10);
}
if (!snake.isAlive)
gameOver();
if (snake.getLength() > GOAL)
win();
drawScene();
}
@Override
public void onKeyPress(Key key){
switch (key){
case LEFT :
snake.setDirection(Direction.LEFT);
break;
case RIGHT :
snake.setDirection(Direction.RIGHT);
break;
case UP :
snake.setDirection(Direction.UP);
break;
case DOWN :
snake.setDirection(Direction.DOWN);
break;
case SPACE :
if(isGameStopped)
createGame();
break;
}
}
private void createNewApple(){
do{
apple = new Apple (getRandomNumber(WIDTH),getRandomNumber(HEIGHT) );
} while (snake.checkCollision(apple));
}
private void createGame(){
score=0;
createNewApple();
isGameStopped = false;
turnDelay = 300;
setTurnTimer(turnDelay);
snake = new Snake(WIDTH / 2, HEIGHT / 2);
drawScene();
setScore(score);
}
private void gameOver(){
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.RED, "you lose", Color.BLUE, 75);
}
private void win(){
stopTurnTimer();
isGameStopped = true;
showMessageDialog(Color.RED, "congratulations", Color.BLUE, 75);
}
private void drawScene(){
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
setCellValueEx(x, y, Color.DARKSEAGREEN , "");
}
}
snake.draw(this);
apple.draw(this);
}
}