From 02c2b01d95728a768c63d6a87f08795f76009ddf Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 19:01:56 +0100 Subject: [PATCH] Reveal all bombs on game end --- src/main/java/Minesweeper/Cell.java | 1 + src/main/java/Minesweeper/Playfield.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/Minesweeper/Cell.java b/src/main/java/Minesweeper/Cell.java index 2252b7d..4991e9e 100644 --- a/src/main/java/Minesweeper/Cell.java +++ b/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(); } diff --git a/src/main/java/Minesweeper/Playfield.java b/src/main/java/Minesweeper/Playfield.java index f2036df..372b715 100644 --- a/src/main/java/Minesweeper/Playfield.java +++ b/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--; }