Привет. В коде метод вызывается, при нажатии пробела полсе проигрыша - занаво отрисовывается поле, но валидатор не принмает.
Подскажите, пожалуйста в чём проблема?
public void onKeyPress(Key key) {
if (isGameStopped){
if (key == Key.SPACE) {
isGameStopped = false;
createGame();
drawScene();
}
else {
return;
}
}
if (!canUserMove()) {
gameOver();
return;
}
if (key == Key.LEFT){
moveLeft();
}
.
.
.package com.javarush.games.game2048;
public class Test {
private static int SIDE = 4;
public static void main(String[] args) {
int arr[][] = new int[][]{
{4, 4, 2, 4},
{4, 2, 4, 2},
{2, 4, 2, 4},
{4, 2, 4, 2}
};
System.out.println(canUserMove(arr));
}
static boolean canUserMove(int[][] gameField) {
boolean canUserMove = false;
for (int row = 0; row < gameField.length - 1; row++) {
for (int col = 0; col < gameField[col].length - 1; col++) {
int currentTail = gameField[row][col];
canUserMove |= (currentTail == 0
|| currentTail == gameField[row][col + 1]
|| currentTail == gameField[row + 1][col]);
}
}
//check right-end column
for (int row = 0; row < gameField.length; row++) {
canUserMove |= (gameField[row][SIDE - 1] == 0
|| gameField[row][SIDE - 1] == gameField[row][SIDE - 1 - 1]);
}
//check bottom-end row
for (int col = 0; col < gameField[SIDE - 1].length; col++) {
canUserMove |= (gameField[SIDE - 1][col] == 0
|| gameField[SIDE - 1][col] == gameField[SIDE - 1 - 1][col]);
}
return canUserMove;
}
}