не прохожу по 2-м последним пунктам
package com.javarush.games.game2048;
import com.javarush.engine.cell.*;
public class Game2048 extends Game {
private static final int SIDE = 4;
Color[] colors = Color.values();
private int[][] gameField = new int[SIDE][SIDE];
private boolean isGameStopped = false;
@Override
public void initialize(){
setScreenSize(SIDE,SIDE);
createGame();
gameField[3][0] = 2048;
drawScene();
}
private void win(){
isGameStopped = true;
showMessageDialog(Color.BLACK, "GAME WON!!!", Color.WHITE, 100);
}
private int getMaxTileValue(){
int max = gameField[0][0];
for(int x = 0; x < SIDE; x++){
for(int y = 0; y < SIDE; y++){
if(max < gameField[y][x]){
max = gameField[y][x];
}
}
}
return max;
}
private void rotateClockwise(){
int rowA[] = new int[4];
rowA[0] = gameField[0][0];
rowA[1] = gameField[0][1];
rowA[2] = gameField[0][2];
rowA[3] = gameField[0][3];
int rowB[] = new int[4];
rowB[0] = gameField[1][0];
rowB[1] = gameField[1][1];
rowB[2] = gameField[1][2];
rowB[3] = gameField[1][3];
int rowC[] = new int[4];
rowC[0] = gameField[2][0];
rowC[1] = gameField[2][1];
rowC[2] = gameField[2][2];
rowC[3] = gameField[2][3];
int rowD[] = new int[4];
rowD[0] = gameField[3][0];
rowD[1] = gameField[3][1];
rowD[2] = gameField[3][2];
rowD[3] = gameField[3][3];
for(int n = 0; n < 4; n++){
gameField[n][3] = rowA[n];
gameField[n][2] = rowB[n];
gameField[n][1] = rowC[n];
gameField[n][0] = rowD[n];
}
}
public void onKeyPress(Key key){
if(key == Key.LEFT){
moveLeft();
drawScene();
}
else if(key == Key.RIGHT){
moveRight();
drawScene();
}
else if(key == Key.UP){
moveUp();
drawScene();
}
else if(key == key.DOWN){
moveDown();
drawScene();
}
}
private void moveLeft(){
boolean compRow = false;
boolean mRow = false;
boolean bigBol = false;
for(int i = 0; i <SIDE; i++){
compRow = compressRow(gameField[i]);
mRow = mergeRow(gameField[i]);
compressRow(gameField[i]);
if(compRow == true || mRow == true){
bigBol = true;
}
}
if(bigBol == true){
createNewNumber();
}
}
private void moveRight(){
rotateClockwise();
rotateClockwise();
moveLeft();
rotateClockwise();
rotateClockwise();
}
private void moveDown(){
rotateClockwise();
moveLeft();
rotateClockwise();
rotateClockwise();
rotateClockwise();
}
private void moveUp(){
rotateClockwise();
rotateClockwise();
rotateClockwise();
moveLeft();
rotateClockwise();
}
private boolean mergeRow(int[] row){
boolean bol = false;
for(int i = 0; i < SIDE - 1; i++){
if(row[i] == row[i+1] && row[i] != 0){
row[i] = row[i] + row[i+1];
row[i+1] = 0;
bol = true;
}
}
return bol;
}
private boolean compressRow(int[] row){
boolean bol = false;
for(int j = 0; j < SIDE; j++){
for(int i = 0; i < SIDE-1; i++){
if(row[i] == 0 && row[i+1] != 0){
row[i] = row[i+1];
row[i+1] = 0;
bol = true;
}
}
}
return bol;
}
private void setCellColoredNumber(int x, int y, int val){
if(val == 0){
Color col = getColorByValue(val);
setCellValueEx(x, y, col, "");
}
else{
Color col = getColorByValue(val);
String str = Integer.toString(val);
setCellValueEx(x, y, col, str);
}
}
private Color getColorByValue(int val){
if(val == 2){
return Color.PURPLE;
}
if(val == 4){
return Color.BLUE;
}
if(val == 8){
return Color.CYAN;
}
if(val == 16){
return Color.GREEN;
}
if(val == 32){
return Color.YELLOW;
}
if(val == 64){
return Color.ORANGE;
}
if(val == 128){
return Color.RED;
}
if(val == 256){
return Color.MAROON;
}
if(val == 512){
return Color.PINK;
}
if(val == 1024){
return Color.BEIGE;
}
if(val == 2048){
return Color.GREY;
}
else{
return Color.WHITE;
}
}
private void createGame(){
createNewNumber();
createNewNumber();
}
private void drawScene(){
for(int x = 0; x < SIDE; x++){
for(int y = 0; y < SIDE; y++){
setCellColoredNumber(x, y, gameField[y][x]);
}
}
}
private void createNewNumber(){
getMaxTileValue();
for(int x = 0; x < SIDE; x++){
for(int y = 0; y < SIDE; y++){
if( gameField[y][x] == 2048){
win();
}
}
int i = getRandomNumber(SIDE);
int j = getRandomNumber(SIDE);
int val = getRandomNumber(10);
while(gameField[i][j] != 0){
i = getRandomNumber(SIDE);
j = getRandomNumber(SIDE);
}
if(val == 0){
gameField[i][j] = 4;
setCellNumber(j, i, 4);
}
else{
gameField[i][j] = 2;
setCellNumber(j, i, 4);
}
}
}
}