|
@ -11,6 +11,8 @@ public class MinesweeperGame extends JPanel { |
|
|
private static final int CELLSIZE = 40; |
|
|
private static final int CELLSIZE = 40; |
|
|
private int playfieldSize; |
|
|
private int playfieldSize; |
|
|
|
|
|
|
|
|
|
|
|
public Cell[][] playfield; |
|
|
|
|
|
|
|
|
public MinesweeperGame(int _playfieldSize) { |
|
|
public MinesweeperGame(int _playfieldSize) { |
|
|
this.setSize(WIDTH, HEIGTH); |
|
|
this.setSize(WIDTH, HEIGTH); |
|
|
playfieldSize = _playfieldSize; |
|
|
playfieldSize = _playfieldSize; |
|
@ -20,11 +22,15 @@ public class MinesweeperGame extends JPanel { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void initPlayfield() { |
|
|
private void initPlayfield() { |
|
|
|
|
|
|
|
|
|
|
|
playfield = new Cell[playfieldSize][playfieldSize]; |
|
|
|
|
|
|
|
|
for (int i = 0; i < playfieldSize; i++) { |
|
|
for (int i = 0; i < playfieldSize; i++) { |
|
|
for (int j = 0; j < playfieldSize; j++) { |
|
|
for (int j = 0; j < playfieldSize; j++) { |
|
|
JButton b = new JButton(); |
|
|
|
|
|
b.setBounds(j * CELLSIZE, i * CELLSIZE, CELLSIZE, CELLSIZE); |
|
|
|
|
|
add(b); |
|
|
|
|
|
|
|
|
Cell c = new Cell(CellType.Number); |
|
|
|
|
|
c.setBounds(j * CELLSIZE + (WIDTH / 2 - playfieldSize * CELLSIZE / 2), i * CELLSIZE + (HEIGTH / 2 - playfieldSize * CELLSIZE / 2), CELLSIZE, |
|
|
|
|
|
CELLSIZE); |
|
|
|
|
|
add(c); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|