From 5d1aba44082f7911b0dd17ab58ac4669e9721551 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 16:38:16 +0100 Subject: [PATCH] Flagged number cells count as flooded --- src/main/java/Minesweeper/Cell.java | 8 ++++++-- src/main/java/Minesweeper/Playfield.java | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/Minesweeper/Cell.java b/src/main/java/Minesweeper/Cell.java index d67ba5b..8b05e78 100644 --- a/src/main/java/Minesweeper/Cell.java +++ b/src/main/java/Minesweeper/Cell.java @@ -62,16 +62,20 @@ public class Cell extends JButton { if (isEnabled()) { if (flagged) { flagged = false; - + if (type == CellType.Number) { setBackground(Color.gray); + playfield.cellDried(); } else { setBackground(Color.red); } - + } else { flagged = true; setBackground(Color.cyan); + if (type == CellType.Number) { + playfield.cellFlooded(); + } } } } diff --git a/src/main/java/Minesweeper/Playfield.java b/src/main/java/Minesweeper/Playfield.java index 754dd52..86d14fb 100644 --- a/src/main/java/Minesweeper/Playfield.java +++ b/src/main/java/Minesweeper/Playfield.java @@ -134,4 +134,8 @@ public class Playfield { System.exit(0); } } + + public void cellDried() { + cellsFlooded--; + } } \ No newline at end of file