just need a little nudge. looks like it checks each neighbor and opens it but the verification doesn't like it.
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 GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
private static final String MINE = "\uD83D\uDCA3";
private static final String FLAG = "\uD83D\uDEA9";
private int countFlags = 0;
@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.BLUE);
}
}
countMineNeighbors();
countFlags = countMinesOnField;
}
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;
}
private void countMineNeighbors(){
for (int y = 0; y < SIDE; y++) {
for (int x = 0; x < SIDE; x++) {
if (gameField[y][x].isMine == false){
for (GameObject g : getNeighbors(gameField[y][x])){
if (g.isMine == true){
gameField[y][x].countMineNeighbors++;
}
}
}
}
}
}
private void openTile(int x, int y){
if (gameField[y][x].isOpen = false){
gameField[y][x].isOpen = true;
if (gameField[y][x].isMine){
setCellValue(x, y, MINE);
setCellColor(x, y, Color.RED);
}
else if (gameField[y][x].isMine == false && gameField[y][x].countMineNeighbors == 0){
String s = "";
setCellNumber(x, y, Integer.parseInt(0+s));
setCellColor(x, y, Color.GREEN);
for (GameObject g : getNeighbors(gameField[y][x])){
if (g.isOpen == false && g.isMine == false && g.countMineNeighbors == 0){
openTile(g.x, g.y);
}
}
} else {
setCellNumber(x, y, gameField[y][x].countMineNeighbors);
setCellColor(x, y, Color.GREEN);
}
}
}
@Override
public void onMouseLeftClick(int x, int y){
openTile(x, y);
}
}