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) { if (type != CellType.Bomb) {
flood(); flood();
} else { } else {
playfield.revealAllBombs();
JOptionPane.showMessageDialog(getParent(),"KABOOM! Try again!"); JOptionPane.showMessageDialog(getParent(),"KABOOM! Try again!");
playfield.reset(); playfield.reset();
} }

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

@ -127,11 +127,23 @@ public class Playfield {
public void cellFlooded() { public void cellFlooded() {
cellsFlooded++; cellsFlooded++;
if (cellsFlooded >= Size * Size - bombAmount) { if (cellsFlooded >= Size * Size - bombAmount) {
revealAllBombs();
JOptionPane.showMessageDialog(MsG, "You won, congratulations!"); JOptionPane.showMessageDialog(MsG, "You won, congratulations!");
reset(); 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() { public void cellDried() {
cellsFlooded--; cellsFlooded--;
} }
Loading…
Cancel
Save