My method seems to work ok when I play the game. I am not sure why it is not passing.
private void openTile(int x, int y) {
// 3. The openTile(int, int) method must not do anything if the game is stopped (isGameStopped == true).
if (isGameStopped) {
return;
}
// 2. The openTile(int, int) method must not do anything if the element is flagged.
if (gameField[y][x].isFlag) {
return;
}
// 1. The openTile(int, int) method must not do anything if the element is already revealed.
if (gameField[y][x].isOpen) {
return;
}
if (gameField[y][x].isMine) {
setCellValueEx(x, y, Color.RED, MINE);
gameOver();
}
// The openTile(int, int) method must draw the number of adjacent mines
// if the gameObject at the passed coordinates is not a mine.
else {
gameField[y][x].isOpen = true;
--countClosedTiles;
if (gameField[y][x].countMineNeighbors != 0) {
setCellNumber(x, y, gameField[y][x].countMineNeighbors);
}
else {
setCellValue(x, y, "");
for (GameObject neighbor : getNeighbors(gameField[y][x])) {
if (!gameField[neighbor.y][neighbor.x].isOpen) {
openTile(neighbor.x, neighbor.y);
}
}
}
setCellColor(x, y, Color.GREEN);
}
// 6. The openTile(int, int) method must call the win() method if the number of hidden cells
// is equal to the number of mines on the field and the last revealed cell is not a mine.
if (countClosedTiles == countMinesOnField) {
win();
}
}
package com.codegym.games.minesweeper;
/*
Requirements:
1. There must be a public GameObject class.
2. The GameObject class must have a public int x field.
3. The GameObject class must have a public int y field.
4. The GameObject class must have one constructor with two int parameters
that are used to initialize the x and y fields, in that order.
Requirements:
1. The GameObject class must have a public boolean isMine field.
2. The GameObject class must have one constructor with (int, int, boolean) parameters
that are used to initialize the x, y, and isMine fields, in that order.
Requirements:
1. The GameObject class must have a public int countMineNeighbors field.
5. The GameObject class must have a public boolean isOpen field.
4. The GameObject class must have a public boolean isFlag field.
*/
public class GameObject {
public int x;
public int y;
public boolean isMine;
public boolean isOpen;
public boolean isFlag;
public int countMineNeighbors = 0;
public GameObject(int x, int y, boolean isMine) {
this.x = x;
this.y = y;
this.isMine = isMine;
}
}