I think i haven't understood the requirements correctly
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.*;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private int countMinesOnField;
public void initialize() {
setScreenSize(SIDE, SIDE);
createGame();
}
private GameObject[][] gameField = new GameObject[SIDE][SIDE];
private void createGame() {
for(int i = 0; i < gameField[0].length; i++) {
for(int j = 0; j < gameField.length; j++) {
int n = getRandomNumber(10);
if(n == 1){
gameField[i][j] = new GameObject(j, i,true);
countMinesOnField++;
}
else
gameField[i][j] = new GameObject(j, i,false);
setCellColor(j, i, Color.GREEN);
}
}
countMineNeighbors();
}
private void countMineNeighbors() {
for(int i = 0; i < gameField[0].length; i++) {
for(int j = 0; j < gameField.length; j++) {
GameObject gameObject = gameField[i][j];
if(!gameObject.isMine)
getNeighbors(gameObject);
}
}
}
public void getNeighbors(GameObject gameObject){
int x = gameObject.x;
int y = gameObject.y;
int count = 0;
if(gameField[x + 1][y].isMine)
count++;
if(gameField[x - 1][y].isMine)
count++;
if(gameField[x][y + 1].isMine)
count++;
if(gameField[x][y - 1].isMine)
count++;
if(gameField[x + 1][y + 1].isMine)
count++;
if(gameField[x + 1][y - 1].isMine)
count++;
if(gameField[x - 1][y + 1].isMine)
count++;
if(gameField[x - 1][y - 1].isMine)
count++;
gameObject.countMineNeighbors = count;
}
}