public void onKeyPress(Key key) {
if (key == Key.UP){
if (snake.getDirection() == DOWN) return;
else
snake.setDirection(UP);
}
if (key == Key.DOWN){
if (snake.getDirection() == UP) return;
else
snake.setDirection(DOWN);
}
if (key == Key.LEFT){
if (snake.getDirection() == RIGHT) return;
else
snake.setDirection(LEFT);
}
if (key == Key.RIGHT){
if (snake.getDirection() == LEFT) return;
else
snake.setDirection(RIGHT);
}
}package com.javarush.games.snake;
import com.javarush.engine.cell.*;
public class Apple extends GameObject {
public Apple(int x, int y) {
super(x, y);
}
private static final String APPLE_SIGN = "\uD83C\uDF4E";
public void draw(Game game) {
game.setCellValueEx(x, y, Color.NONE, APPLE_SIGN, Color.GREEN, 75);
}
public boolean isAlive = true;
}
Вывод компилятора на сайте: