From b635c64d4f88c7e25074ab31e0272da5e341ccc8 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 15:12:36 +0100 Subject: [PATCH] Game End: Victory --- src/main/java/Minesweeper/Cell.java | 2 +- src/main/java/Minesweeper/Playfield.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/Minesweeper/Cell.java b/src/main/java/Minesweeper/Cell.java index 93f8799..fc7d393 100644 --- a/src/main/java/Minesweeper/Cell.java +++ b/src/main/java/Minesweeper/Cell.java @@ -56,7 +56,7 @@ public class Cell extends JButton { } setBackground(Color.LIGHT_GRAY); setEnabled(false); - + playfield.cellFlooded(); if (value == 0) { if (cord.y > 0) { if (playfield.cells[cord.y - 1][cord.x].type == CellType.Number diff --git a/src/main/java/Minesweeper/Playfield.java b/src/main/java/Minesweeper/Playfield.java index 38f61cc..c67c570 100644 --- a/src/main/java/Minesweeper/Playfield.java +++ b/src/main/java/Minesweeper/Playfield.java @@ -11,7 +11,9 @@ public class Playfield { private MinesweeperGame MsG; public Cell[][] cells; private int bombAmount; - + private int cellsFlooded = 0; + + public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) { MsG = _MsG; Size = _Size; @@ -123,5 +125,12 @@ public class Playfield { cells[row][column].update(); } - + + public void cellFlooded() { + cellsFlooded++; + if(cellsFlooded >= Size * Size - bombAmount) { + JOptionPane.showMessageDialog(MsG, "You won, congratulations!"); + System.exit(0); + } + } }