Nothing is working. I tried the following -
1. Incrementing the countMinesOnField within the createGame method.
2. Using a local variable to count and then assigning its value to countMinesOnField in createGame method.
3. Using a local variable to count and then assigning its value to countMinesOnField in initialize method.
4. Using "this.countMinesOnField" and "countMinesOnField " in all the above 3 scenarios.
Any pointers?
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.*;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
public void initialize() {
//Setting the field size as 9 X 9 cells
setScreenSize(SIDE,SIDE);
createGame();
}
private void createGame() {
boolean putMine = false;
int totalMines = 0;
for(int i = 0; i < SIDE; i++) {
for(int j = 0; j < SIDE; j++) {
putMine = (getRandomNumber(10) == 1);
gameField[i][j] = new GameObject(j,i,putMine);
//increment the total mines count by 1 if the cell is initiated with a mine
totalMines = (putMine)? totalMines++ : totalMines;
setCellColor(i,j,Color.ORANGE);
}
}
this.countMinesOnField = totalMines;
}
}