Hey,
I'm trying to implement mine sweeper game's 6th part but couldn't achieve the goal that indicated at 3rd condition.
Could one of you guys please help me to understand the problem ?
Thanks
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 GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
@Override
public void initialize() {
setScreenSize(SIDE, SIDE);
createGame();
}
private void createGame() {
int randNum = getRandomNumber(10);
for (int x = 0; x < SIDE; x++) {
for (int y = 0; y < SIDE; y++) {
if (randNum == 4) {
gameField[y][x] = new GameObject(x, y, true);
countMinesOnField++;
}
else {
gameField[y][x] = new GameObject(x, y, false);
}
setCellColor(x, y, Color.GREY);
}
}
countMineNeighbors();
}
private void countMineNeighbors() {
for (int x=0; x<SIDE; x++) {
for (int y=0; y<SIDE; y++) {
if (!(gameField[x][y]).isMine){
getNeighbors(gameField[x][y]);
}
}
}
}
private void getNeighbors(GameObject gameObject) {
for (int x = gameObject.x - 1; x <= gameObject.x+1; x++) {
for (int y = gameObject.y - 1; y <= gameObject.y+1; y++) {
if(x >= 0 && y >= 0 && x < SIDE && y < SIDE) {
if ((gameField[x][y]).isMine) {
gameObject.countMineNeighbors++;
}
}
}
}
}
}