Я понимаю, что решение громоздкое, но все равно не могу понять, почему валидатор не пропускает ни один пункт... Помогите
package com.javarush.games.game2048;
import com.javarush.engine.cell.*;
public class Game2048<v> extends Game{
private static final int SIDE = 4;
private int gameField[][] = new int [SIDE][SIDE];
public void initialize(){
setScreenSize(SIDE, SIDE);
createGame();
drawScene();
}
private void createGame(){
createNewNumber();
createNewNumber();
}
private void setCellColoredNumber(int x, int y, int value){
Color color = getColorByValue(gameField[y][x] );
// как кастануть??!!
String v = String.valueOf(value);
if(value==0)setCellValueEx(x, y, color, "");
else setCellValueEx(x, y, color, v);
}
private boolean compressRow(int []row){
boolean r = false;
for(int j = 0; j < row.length-1;j++){
for(int i = 0; i < row.length-1;i++) {
if (row[i] == 0 && row[i+1]!= 0) {
row[i] = row[i+1];
row[i+1] = 0;
r=true;
}
}
}
return r;
}
private boolean mergeRow(int [] row){
boolean change = false;
for(int i = 0; i < row.length-1; i++) {
if ((row[i] == row[i+1])&& row[i]!=0) {
row[i] = (row[i])*2;
row[i+1] = 0;
change=true;
}
}
return change;
}
public void onKeyPress(Key key){
if(key == Key.LEFT) {moveLeft();drawScene();}
if(key == Key.RIGHT) {moveRight();drawScene();}
if(key == Key.UP) {moveUp();drawScene();}
if(key == Key.DOWN) {moveDown(); drawScene();}
}
private void moveLeft(){
boolean change = false;
//проходим по каждой строке,
for(int i =0; i <SIDE; i++) {
int gameFieldN[] = new int[SIDE];
int gameFieldN1[]= new int[SIDE];
//копируем данные в одномерный массив
for(int k = 0; k<SIDE; k++) {
gameFieldN [i] = gameField[i][SIDE];
gameFieldN1 [i] = gameField[i][SIDE];
}
// проходим методами по каждой строке
compressRow(gameFieldN);
mergeRow(gameFieldN);
compressRow(gameFieldN);
// проверяем были ли изменения
for (int j = 0; j < SIDE; j++) {
if (gameFieldN[j] != gameFieldN[j]) {
change = true;
}
}
}
if(change) {
createNewNumber();
}
}
private void moveRight(){
}
private void moveUp(){
}
private void moveDown(){
}
private Color getColorByValue(int value){
int v = value;
Color c = null;
if(v==2) c= Color.DARKORCHID;
if(v==4) c= Color.GAINSBORO;
if(v==8) c= Color.CORNSILK;
if(v==16) c=Color.LAVENDER;
if(v==32) c=Color.MAGENTA;
if(v==64) c=Color.TOMATO;
if(v==128) c=Color.DARKCYAN;
if(v==256) c=Color.DARKGREEN;
if(v==512) c=Color.DARKGOLDENROD;
if(v==1024) c=Color.LIGHTCORAL;
if(v==2048) c= Color.LIGHTBLUE;
if(v==0) c=Color.WHITE;
return c;
}
private void createNewNumber(){
int x;
int y;
while (true){
x = getRandomNumber(SIDE);
y = getRandomNumber(SIDE);
if(gameField[x][y]==0) break;
}
int num = getRandomNumber(10);
if(num==9){
gameField[x][y]=4;
}else gameField[x][y]=2;
}
private void drawScene(){
for(int i = 0; i<4;i++){
for(int j = 0; j<4;j++){
int v = gameField[i][j];
setCellColoredNumber(j,i,v);
}
}
}
}