на данном этапе змейка уже должна менять направление при нажатии клавиш?
package com.javarush.games.snake;
import com.javarush.engine.cell.*;
public class SnakeGame extends Game {
public static final int WIDTH = 15;
public static final int HEIGHT = 15;
private Snake snake;
private int turnDelay;
@Override
public void initialize(){
setScreenSize(WIDTH, HEIGHT);
createGame();
}
public void onTurn(int turnDelay){
snake.move();
drawScene();
}
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.UP){
snake.setDirection(Direction.UP);
} else {
snake.setDirection(Direction.DOWN);
}
}
private void createGame(){
snake = new Snake(WIDTH/2, HEIGHT/2);
turnDelay = 300;
setTurnTimer(turnDelay);
drawScene();
}
private void drawScene(){
for (int i = 0; i < WIDTH; i++){
for (int j = 0; j < HEIGHT; j++){
setCellValueEx(i, j, Color.DARKSEAGREEN, "");
}
}
snake.draw(this);
}
}