Browse Source

Changed victory end to reset

feature_Minesweeper_Playfield
kfkama 3 years ago
parent
commit
c6c2328e4a
  1. 2
      src/main/java/Minesweeper/Cell.java
  2. 4
      src/main/java/Minesweeper/Playfield.java

2
src/main/java/Minesweeper/Cell.java

@ -8,6 +8,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JOptionPane;
enum CellType { enum CellType {
Number, Bomb Number, Bomb
@ -53,6 +54,7 @@ public class Cell extends JButton {
if (type != CellType.Bomb) { if (type != CellType.Bomb) {
flood(); flood();
} else { } else {
JOptionPane.showMessageDialog(getParent(),"KABOOM! Try again!");
playfield.reset(); playfield.reset();
} }
} }

4
src/main/java/Minesweeper/Playfield.java

@ -13,7 +13,6 @@ public class Playfield {
private int bombAmount; private int bombAmount;
private int cellsFlooded = 0; private int cellsFlooded = 0;
public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) { public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) {
MsG = _MsG; MsG = _MsG;
Size = _Size; Size = _Size;
@ -65,7 +64,6 @@ public class Playfield {
} }
public void reset() { public void reset() {
JOptionPane.showMessageDialog(MsG,"KABOOM! Try again!");
cellsFlooded = 0; cellsFlooded = 0;
for (int i = 0; i < Size; i++) { for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) { for (int j = 0; j < Size; j++) {
@ -131,7 +129,7 @@ public class Playfield {
cellsFlooded++; cellsFlooded++;
if (cellsFlooded >= Size * Size - bombAmount) { if (cellsFlooded >= Size * Size - bombAmount) {
JOptionPane.showMessageDialog(MsG, "You won, congratulations!"); JOptionPane.showMessageDialog(MsG, "You won, congratulations!");
System.exit(0);
reset();
} }
} }

Loading…
Cancel
Save