I'm declaring the ![]()
isOpen
boolean in the public MinesweeperGame class and it's not working at line 80!
And if you find anything else that is wrong or missing then pls 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 GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
private static final String MINE = "\uD83D\uDCA3";
public boolean isOpen;
@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();
}
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++) {
GameObject obj = gameField[y][x];
if (!obj.isMine) {
List<GameObject> neighbors = getNeighbors(obj);
for (GameObject neighbor : neighbors){
if (neighbor.isMine){
obj.countMineNeighbors++;
}
}
}
}
}
}
private void openTile(int x, int y){
if(gameField[y][x].isMine){
setCellValue(x, y, MINE);
}
else {
setCellNumber(x,y,gameField[x][y].countMineNeighbors);
}
gameField[x][y].isOpen = true;
setCellColor(x,y,Color.GREEN);
}
}