From d718f86c52e7de7c05d24980d9c10bfeb16c7229 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 14:58:58 +0100 Subject: [PATCH] Made playfield resetable --- src/main/java/Minesweeper/Playfield.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/Minesweeper/Playfield.java b/src/main/java/Minesweeper/Playfield.java index 3fc9006..eed046b 100644 --- a/src/main/java/Minesweeper/Playfield.java +++ b/src/main/java/Minesweeper/Playfield.java @@ -8,18 +8,20 @@ public class Playfield { public int Size; private MinesweeperGame MsG; public Cell[][] cells; + private int bombAmount; public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) { MsG = _MsG; Size = _Size; - generatePlayfield(_bombAmount); + bombAmount = _bombAmount; + generatePlayfield(); } - public void generatePlayfield(int _bombAmount) { + public void generatePlayfield() { cells = new Cell[Size][Size]; - int[] bPlacement = new int[_bombAmount]; + int[] bPlacement = new int[bombAmount]; for (int i = 0; i < bPlacement.length; i++) { bPlacement[i] = (int) (Math.random() * Size * Size); @@ -57,7 +59,16 @@ public class Playfield { } } } - + + public void reset() { + for (int i = 0; i < Size; i++) { + for (int j = 0; j < Size; j++) { + MsG.remove(cells[i][j]); + } + } + generatePlayfield(); + } + public void calculateBombProximity(int row, int column) { if (row > 0) {