Не могу прикрепить код решения всей задачи, поэтому только главный класс
public class MoonLanderGame extends Game {
public static final int WIDTH = 100;
public static final int HEIGHT = 100;
private Rocket rocket;
private GameObject landscape;
private GameObject platform;
private GameObject secondplatform;
private boolean isUpPressed;
private boolean isLeftPressed;
private boolean isRightPressed;
private boolean isGameStopped;
private int score;
private int turnDelay;
@Override
public void initialize() {
setScreenSize(WIDTH, HEIGHT);
createGame();
showGrid(false);
}
private void createGame() {
setTurnTimer(50);
createGameObjects();
drawScene();
isUpPressed = false;
isLeftPressed = false;
isRightPressed = false;
isGameStopped = false;
score = 1000;
}
private void drawScene() {
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
setCellColor(x, y, Color.DARKRED);
}
}
landscape.draw(this);
rocket.draw(this);
}
private void createGameObjects(){
rocket = new Rocket(WIDTH / 2.0, 0);
landscape = new GameObject(0, 25, ShapeMatrix.LANDSCAPE);
platform = new GameObject(43, 86, ShapeMatrix.PLATFORM);
secondplatform = new GameObject(82, 63, ShapeMatrix.PLATFORM);
}
@Override
public void setTurnTimer(int timeMs) {
super.setTurnTimer(50);
}
@Override
public void onTurn(int step) {
rocket.move(isUpPressed, isLeftPressed, isRightPressed);
check();
drawScene();
if (score > 0) {
score--;
}
setScore(score);
}
@Override
public void setCellColor(int x, int y, Color color) {
if (x > WIDTH - 1 || x < 0 || y < 0 || y > HEIGHT - 1) {
return;
}
super.setCellColor(x, y, color);
}
@Override
public void onKeyPress(Key key) {
if (Key.RIGHT == key) {
isRightPressed = true;
isLeftPressed = false;
} else if (Key.LEFT == key) {
isLeftPressed = true;
isRightPressed = false;
} else if (Key.UP == key) {
isUpPressed = true;
}
if (isGameStopped && Key.SPACE == key) {
createGame();
}
}
@Override
public void onKeyReleased(Key key) {
if (Key.RIGHT == key) {
isRightPressed = false;
} else if (Key.LEFT == key) {
isLeftPressed = false;
} else if (Key.UP == key) {
isUpPressed = false;
}
}
private void check() {
if (rocket.isCollision(platform) && rocket.isStopped()) {
win();
} else if (rocket.isCollision(secondplatform) && rocket.isStopped()){
win();
} else if (rocket.isCollision(landscape)) {
gameOver();
}
}
private void win() {
rocket.land();
isGameStopped = true;
showMessageDialog(Color.NONE, "YOU WIN", Color.LIGHTGRAY, 70);
stopTurnTimer();
}
private void gameOver() {
rocket.crash();
isGameStopped = true;
showMessageDialog(Color.NONE, "YOU LOSE", Color.LIGHTGRAY, 70);
stopTurnTimer();
score = 0;
}
}
Никак не получается реализовать такую функцию