Nur die besten Spiele ;3
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.0 KiB

package Minesweeper;
public class Playfield {
private static final int CELLSIZE = 40;
private int Size;
private MinesweeperGame MsG;
public Cell[][] cells;
public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) {
MsG = _MsG;
Size = _Size;
cells = new Cell[Size][Size];
int[] bPlacement = new int[_bombAmount];
for (int i = 0; i < bPlacement.length; i++) {
bPlacement[i] = (int) (Math.random() * Size * Size);
for (int j = 0; j < i; j++) {
if (bPlacement[i] == bPlacement[j]) {
i--;
break;
}
}
}
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
cells[i][j] = new Cell(CellType.Number);
cells[i][j].setBounds(j * CELLSIZE + (MsG.WIDTH / 2 - Size * CELLSIZE / 2),
i * CELLSIZE + (MsG.HEIGTH / 2 - Size * CELLSIZE / 2), CELLSIZE, CELLSIZE);
MsG.add(cells[i][j]);
for (int k = 0; k < bPlacement.length; k++) {
if (bPlacement[k] == i * Size + j) {
cells[i][j].type = CellType.Bomb;
break;
}
}
}
}
}
}