|
|
@ -11,20 +11,26 @@ public class MinesweeperGame extends JPanel { |
|
|
|
private static final int CELLSIZE = 40; |
|
|
|
private int playfieldSize; |
|
|
|
|
|
|
|
public Cell[][] playfield; |
|
|
|
|
|
|
|
public MinesweeperGame(int _playfieldSize) { |
|
|
|
this.setSize(WIDTH, HEIGTH); |
|
|
|
playfieldSize = _playfieldSize; |
|
|
|
setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
initPlayfield(); |
|
|
|
} |
|
|
|
|
|
|
|
private void initPlayfield() { |
|
|
|
|
|
|
|
playfield = new Cell[playfieldSize][playfieldSize]; |
|
|
|
|
|
|
|
for (int i = 0; i < playfieldSize; i++) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|