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