Browse Source

Reveal all bombs on game end

feature_Minesweeper_Playfield
kfkama 3 years ago
parent
commit
02c2b01d95
  1. 1
      src/main/java/Minesweeper/Cell.java
  2. 12
      src/main/java/Minesweeper/Playfield.java

1
src/main/java/Minesweeper/Cell.java

@ -59,6 +59,7 @@ public class Cell extends JButton {
if (type != CellType.Bomb) {
flood();
} else {
playfield.revealAllBombs();
JOptionPane.showMessageDialog(getParent(),"KABOOM! Try again!");
playfield.reset();
}

12
src/main/java/Minesweeper/Playfield.java

@ -127,11 +127,23 @@ public class Playfield {
public void cellFlooded() {
cellsFlooded++;
if (cellsFlooded >= Size * Size - bombAmount) {
revealAllBombs();
JOptionPane.showMessageDialog(MsG, "You won, congratulations!");
reset();
}
}
public void revealAllBombs() {
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
if(cells[i][j].type == CellType.Bomb) {
cells[i][j].reveal();
}
}
}
MsG.repaint();
}
public void cellDried() {
cellsFlooded--;
}
Loading…
Cancel
Save