Browse Source

Made playfield resetable

feature_Minesweeper_Playfield
kfkama 3 years ago
parent
commit
d718f86c52
  1. 19
      src/main/java/Minesweeper/Playfield.java

19
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) {

Loading…
Cancel
Save