I don't know why. I don't have any errors, but my snake doesn't show up when I start the game. I can see my apple, but no snake. I managed to pass the last few parts, it was saying I had everything right and I could move to the next step, but everytime I passed, I still wasn't able to get my snake to show up in the screen. My snake was showing up in the part where we created the draw method, but as I advanced further into this, it stopped drawing my snake and I have no idea why ?
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 Snake snake;
private Apple apple;
private int turnDelay;
@Override
public void initialize()
{
setScreenSize(WIDTH, HEIGHT);
createGame();
}
private void createGame()
{
snake = new Snake(WIDTH / 2, HEIGHT / 2);
createNewApple();
turnDelay = 300;
setTurnTimer(turnDelay);
drawScene();
}
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);
}
@Override
public void onTurn(int s)
{
snake.move(apple);
if (!apple.isAlive)
createNewApple();
drawScene();
}
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;
default:
break;
}
}
private void createNewApple()
{
int rndX = getRandomNumber(WIDTH);
int rndY = getRandomNumber(HEIGHT);
apple = new Apple(rndX, rndY);
}
}