Where is it wrong?
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.*;
import java.util.*;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private int countMinesOnField = 0;
private GameObject gameField[][] = new GameObject[SIDE][SIDE];
public void initialize()
{
setScreenSize(SIDE,SIDE);
createGame();
}
private void createGame()
{
for(int x =0;x<SIDE;x++)
{
for(int y=0;y<SIDE;y++)
{
gameField[y][x] = new GameObject(x,y,false);
setCellColor(x,y,Color.ORANGE);
int random = getRandomNumber(10);
if(random==1)//any one number between 0-9 to get 10% probability
{
gameField[y][x] = new GameObject(x,y,true);
countMinesOnField++;
}
}
}
countMineNeighbors();
}
private void countMineNeighbors()
{
for(int x=0;x<SIDE;x++)
{
for(int y=0;y<SIDE;y++)
{
if(!gameField[y][x].isMine)
{
for(GameObject g:getNeighbors(gameField[y][x]))
{
if(g.isMine)
gameField[y][x].countMineNeighbors++;
}
}
}
}
}
private ArrayList<GameObject> getNeighbors(GameObject gameObject)
{
ArrayList<GameObject> neighbors = new ArrayList<>();
int m = gameObject.y;
int n = gameObject.x;
for(int x=m-1;x<m+1;x++)
{
for(int y=n-1;y<n+1;y++)
{
if(x<0 || x>SIDE)
continue;
if(y<0 || y>SIDE)
continue;
if(gameField[y][x]==gameObject)
continue;
neighbors.add(gameField[y][x]);
}
}
return neighbors;
}
}