Please somebody give us a hint.
I'm starting to give up on this one
Cheers
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.*;
import java.util.*;
public class MinesweeperGame extends Game {
private int countMinesOnField;
private static final int SIDE = 9;
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++){
int random = getRandomNumber(10);
boolean isMine = false;
if( random == 1){
isMine = true;
countMinesOnField++;
}
gameField[x][y] = new GameObject(x, y, isMine);
setCellColor(x, y, Color.ORANGE) ;
}
}
countMineNeighbors();
}
private void countMineNeighbors(){
for( int x=0; x<SIDE; x++ ){
for( int y=0; y<SIDE; y++){
if(!gameField[x][y].isMine){
ArrayList<GameObject> neibrList = getNeighbors(gameField[x][y]);
int noOfMined = 0;
for(GameObject neibr : neibrList){
if(neibr.isMine){
noOfMined++;
}
}
gameField[x][y].countMineNeighbors = noOfMined;
}
}
}
}
private ArrayList<GameObject> getNeighbors(GameObject cell){
ArrayList<GameObject> neibrList = new ArrayList<GameObject>();
int x = cell.x;
int y = cell.y;
if(validCell(x - 1, y - 1)) neibrList.add(gameField[x - 1][y - 1]);
if(validCell(x, y - 1)) neibrList.add(gameField[x][y - 1]);
if(validCell(x + 1, y - 1)) neibrList.add(gameField[x + 1][y - 1]);
if(validCell(x - 1, y)) neibrList.add(gameField[x - 1][y]);
if(validCell(x + 1, y)) neibrList.add(gameField[x + 1][y]);
if(validCell(x - 1, y + 1)) neibrList.add(gameField[x - 1][y + 1]);
if(validCell(x, y + 1)) neibrList.add(gameField[x][y + 1]);
if(validCell(x + 1, y + 1)) neibrList.add(gameField[x + 1][y + 1]);
return neibrList;
}
private boolean validCell(int x, int y){
int uppBound = 8;
int bottBound = 0;
return (x >= bottBound && x <= uppBound) && (y >= bottBound && y <= uppBound);
}
}