Привет.
package com.javarush.games.minigames.mini08;
import com.javarush.engine.cell.Color;
import com.javarush.engine.cell.Game;
import com.javarush.engine.cell.Key;
/*
Работа с клавиатурой
*/
public class KeyboardGame extends Game {
@Override
public void initialize() {
setScreenSize(3, 3);
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
setCellColor(x, y, Color.WHITE);
}
}
}
@Override
public void onKeyPress(Key key) {
if (key == Key.LEFT) {
for (int i = 0; i < getScreenHeight(); i++) {
setCellColor(0, i, Color.GREEN);
}
}
if (key == Key.RIGHT) {
for (int i = 0; i < getScreenHeight(); i++) {
setCellColor(getScreenWidth() - 1, i, Color.GREEN);
}
}
if (key == Key.DOWN) {
for (int i = 0; i < getScreenWidth(); i++) {
setCellColor(i, getScreenHeight() - 1, Color.GREEN);
}
}
if (key == Key.UP) {
for (int i = 0; i < getScreenWidth(); i++) {
setCellColor(i, 0, Color.GREEN);
}
}
}
@Override
public void onKeyReleased(Key key) {
switch (key) {
case DOWN:
case UP:
case LEFT:
case RIGHT:
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
setCellColor(x, y, Color.WHITE);
}
}
break;
}
}
//напишите тут ваш код
}