You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
package Minesweeper;
|
|
|
|
public class Playfield {
|
|
|
|
private static final int CELLSIZE = 40;
|
|
private int playfieldSize;
|
|
private MinesweeperGame MsG;
|
|
public Cell[][] playfield;
|
|
|
|
public Playfield(MinesweeperGame _MsG, int _playfieldSize, int _bombAmount) {
|
|
MsG = _MsG;
|
|
playfieldSize = _playfieldSize;
|
|
|
|
playfield = new Cell[playfieldSize][playfieldSize];
|
|
|
|
int[] bPlacement = new int[_bombAmount];
|
|
for (int i = 0; i < bPlacement.length; i++) {
|
|
bPlacement[i] = (int) (Math.random() * playfieldSize * playfieldSize);
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
if (bPlacement[i] == bPlacement[j]) {
|
|
i--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < playfieldSize; i++) {
|
|
for (int j = 0; j < playfieldSize; j++) {
|
|
playfield[i][j] = new Cell(CellType.Number);
|
|
|
|
playfield[i][j].setBounds(j * CELLSIZE + (MsG.WIDTH / 2 - playfieldSize * CELLSIZE / 2),
|
|
i * CELLSIZE + (MsG.HEIGTH / 2 - playfieldSize * CELLSIZE / 2), CELLSIZE, CELLSIZE);
|
|
MsG.add(playfield[i][j]);
|
|
|
|
for (int k = 0; k < bPlacement.length; k++) {
|
|
if (bPlacement[k] == i * playfieldSize + j) {
|
|
playfield[i][j].type = CellType.Bomb;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|