From c6c2328e4ac5f8a1082b6d3f735be23d6e309772 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 18:32:48 +0100 Subject: [PATCH] Changed victory end to reset --- src/main/java/Minesweeper/Cell.java | 2 ++ src/main/java/Minesweeper/Playfield.java | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/Minesweeper/Cell.java b/src/main/java/Minesweeper/Cell.java index 8b05e78..8311365 100644 --- a/src/main/java/Minesweeper/Cell.java +++ b/src/main/java/Minesweeper/Cell.java @@ -8,6 +8,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; +import javax.swing.JOptionPane; enum CellType { Number, Bomb @@ -53,6 +54,7 @@ public class Cell extends JButton { if (type != CellType.Bomb) { flood(); } else { + 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 86d14fb..f757df8 100644 --- a/src/main/java/Minesweeper/Playfield.java +++ b/src/main/java/Minesweeper/Playfield.java @@ -12,8 +12,7 @@ public class Playfield { public Cell[][] cells; private int bombAmount; private int cellsFlooded = 0; - - + public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) { MsG = _MsG; Size = _Size; @@ -65,7 +64,6 @@ public class Playfield { } public void reset() { - JOptionPane.showMessageDialog(MsG,"KABOOM! Try again!"); cellsFlooded = 0; for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { @@ -126,15 +124,15 @@ public class Playfield { cells[row][column].update(); } - + public void cellFlooded() { cellsFlooded++; - if(cellsFlooded >= Size * Size - bombAmount) { + if (cellsFlooded >= Size * Size - bombAmount) { JOptionPane.showMessageDialog(MsG, "You won, congratulations!"); - System.exit(0); + reset(); } } - + public void cellDried() { cellsFlooded--; }