Can anyone help?
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.Color;
import com.codegym.engine.cell.Game;
import java.util.ArrayList;
import java.util.List;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private static final String MINE = "\uD83D\uDCA3";
private static final String FLAG = "\uD83D\uDEA9";
private GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
private int countFlags;
private boolean isGameStopped;
@Override
public void initialize() {
setScreenSize(SIDE, SIDE);
createGame();
}
private void createGame() {
for (int y = 0; y < SIDE; y++) {
for (int x = 0; x < SIDE; x++) {
boolean isMine = getRandomNumber(10) < 1;
if (isMine) {
countMinesOnField++;
}
gameField[y][x] = new GameObject(x, y, isMine);
setCellColor(x, y, Color.ORANGE);
}
}
countMineNeighbors();
countFlags = countMinesOnField;
isGameStopped = false;
}
private void openTile(int x, int y) {
gameField[y][x].isOpen = true;
setCellColor(x, y, Color.ORANGE);
if (gameField[y][x].isOpen || gameField[y][x].isFlag || isGameStopped == true) {
} else {
if (!gameField[y][x].isMine && gameField[y][x].countMineNeighbors >= 1) {
setCellNumber(x, y, gameField[y][x].countMineNeighbors);
} else if (gameField[y][x].isMine) {
setCellValueEx(x, y, Color.RED, MINE);
gameOver();
} else if (!gameField[y][x].isMine && gameField[y][x].countMineNeighbors == 0) {
setCellValue(x, y, "");
getNeighbors(gameField[y][x]);
int m = y, n = x;
if (m - 1 >= 0 && m - 1 < SIDE) {
if (!gameField[m - 1][n].isOpen)
openTile(n, m - 1);
if (n - 1 >= 0 && !gameField[m - 1][n - 1].isOpen)
openTile(n - 1, m - 1);
if (n + 1 < SIDE && !gameField[m - 1][n + 1].isOpen)
openTile(n + 1, m - 1);
}
if (m >= 0 && m < SIDE) {
if (n - 1 >= 0 && !gameField[m][n - 1].isOpen)
openTile(n - 1, m);
if (n + 1 < SIDE && !gameField[m][n + 1].isOpen)
openTile(n + 1, m);
}
if (m + 1 >= 0 && m + 1 < SIDE) {
if (!gameField[m + 1][n].isOpen)
openTile(n, m + 1);
if (n - 1 >= 0 && !gameField[m + 1][n - 1].isOpen)
openTile(n - 1, m + 1);
if (n + 1 < SIDE && !gameField[m + 1][n + 1].isOpen)
openTile(n + 1, m + 1);
}
}
}
}
private void markTile(int x, int y) {
if (isGameStopped == false) {
if (gameField[y][x].isOpen == true || countFlags == 0 && gameField[y][x].isFlag == false) {
} else if (gameField[y][x].isFlag == true) {
gameField[y][x].isFlag = false;
countFlags = countFlags+1;
setCellValue(x, y, "");
setCellColor(x, y, Color.ORANGE);
} else {
gameField[y][x].isFlag = true;
countFlags = countFlags-1;
setCellValue(x, y, FLAG);
setCellColor(x, y, Color.YELLOW);
}
}
}
@Override
public void onMouseRightClick(int x, int y) {
markTile(x,y);
}
@Override
public void onMouseLeftClick(int x, int y) {
openTile(x,y);
}
private void gameOver() {
isGameStopped=true;
showMessageDialog(Color.RED, "GAME OVER", Color.BLACK, 60);
}
private void countMineNeighbors(){
for(int y = 0; y < SIDE; y++){
for(int x = 0; x < SIDE; x++){
if(!gameField[y][x].isMine){
for(GameObject obj : getNeighbors(gameField[y][x])){
if(obj.isMine){gameField[y][x].countMineNeighbors++;}
}
}
}
}
}
private List<GameObject> getNeighbors(GameObject gameObject) {
List<GameObject> result = new ArrayList<>();
for (int y = gameObject.y - 1; y <= gameObject.y + 1; y++) {
for (int x = gameObject.x - 1; x <= gameObject.x + 1; x++) {
if (y < 0 || y >= SIDE) {
continue;
}
if (x < 0 || x >= SIDE) {
continue;
}
if (gameField[y][x] == gameObject) {
continue;
}
result.add(gameField[y][x]);
}
}
return result;
}
}