Browse Source

Game End: Victory

feature_Minesweeper_Playfield
kfkama 2 years ago
parent
commit
b635c64d4f
  1. 2
      src/main/java/Minesweeper/Cell.java
  2. 13
      src/main/java/Minesweeper/Playfield.java

2
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

13
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);
}
}
}
Loading…
Cancel
Save