Skip to content

Commit

Permalink
fix: could flag clicked cells; clicking a cell did not uncover it
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmo117 committed May 19, 2019
1 parent 9b223f4 commit 615fee7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/main/java/net/darmo_creations/minesweeper/model/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public int performMainClick(CellClickedEvent event) {
if (!cell.isFlagged()) {
int nearbyMines = getNearbyMinesNumber(row, col);

if (getNearbyFlagsNumber(row, col) == nearbyMines) {
if (cell.isClicked() && getNearbyFlagsNumber(row, col) == nearbyMines) {
if (row > 0)
exploreGrid(row - 1, col, false);
if (row > 0 && col < getColumns() - 1)
Expand Down Expand Up @@ -116,19 +116,21 @@ public void performSecondaryClick(CellClickedEvent event) {
Cell cell = this.grid[row][col];
CellLabel label = event.getCell();

if (cell.isFlagged()) {
cell.setMarked(true);
label.setIcon(Images.MARK);
this.flags++;
}
else if (cell.isMarked()) {
cell.setMarked(false);
label.setIcon(Images.EMPTY_CELL);
}
else {
cell.setFlagged(true);
label.setIcon(Images.FLAG);
this.flags--;
if (!cell.isClicked()) {
if (cell.isFlagged()) {
cell.setMarked(true);
label.setIcon(Images.MARK);
this.flags++;
}
else if (cell.isMarked()) {
cell.setMarked(false);
label.setIcon(Images.EMPTY_CELL);
}
else {
cell.setFlagged(true);
label.setIcon(Images.FLAG);
this.flags--;
}
}
}

Expand Down

0 comments on commit 615fee7

Please sign in to comment.