Не пойму что не так(
package com.javarush.games.game2048;
import com.javarush.engine.cell.*;
public class Game2048 extends Game {
private static final int SIDE = 4;
private int [] [] gameField = new int [SIDE][SIDE];
@Override
public void initialize() {
setScreenSize(SIDE, SIDE);
createGame();
drawScene();
}
private void createGame(){
createNewNumber();
createNewNumber();
}
private void drawScene(){
for (int i = 0; i < 4; i++ ){
for (int j = 0; j < 4; j++ ){
setCellColoredNumber(i, j, gameField[j][i]);
}
}
}
private void createNewNumber(){
int x;
int y;
while (true){
x = getRandomNumber(SIDE);
y = getRandomNumber(SIDE);
if (gameField[x][y] == 0){
break;
}
}
int ran = getRandomNumber(10);
if (ran == 9){
gameField[x][y] = 4;
} else {
gameField[x][y] = 2;
}
}
private void setCellColoredNumber(int x, int y, int value){
Color newColor = getColorByValue(value);
String newValue = Integer.toString(value);
if (value==0) setCellValueEx(x, y, newColor, "");
else setCellValueEx(x, y, newColor, newValue );
}
private Color getColorByValue(int value){
switch (value){
case 0 : return Color.GREEN;
case 2 : return Color.WHITE;
case 4 : return Color.YELLOW;
case 8 : return Color.GOLD;
case 16 : return Color.ORANGE;
case 32 : return Color.RED;
case 64 : return Color.DARKRED;
case 128 : return Color.MAGENTA;
case 256 : return Color.PURPLE;
case 512 : return Color.DARKBLUE;
case 1024 : return Color.BLUE;
case 2024 : return Color.BLACK;
default: return Color.NONE;
}
}
private boolean compressRow(int[] row){
boolean tF = false;
int [] rowCopy = row;
for (int i = 0; i < row.length; i++){
if (row[i] == 0){
for (int j = i; j < row.length-1; j++){
row [j] = row [j+1];
}
row[row.length-1] = 0;
}
}
if (rowCopy != row){
tF = true;
}
return tF;
}
}