|
|
@ -2,7 +2,7 @@ package Minesweeper; |
|
|
|
|
|
|
|
public class Playfield { |
|
|
|
|
|
|
|
private static final int CELLSIZE = 40; |
|
|
|
private static final int CELLSIZE = 50; |
|
|
|
private int Size; |
|
|
|
private MinesweeperGame MsG; |
|
|
|
public Cell[][] cells; |
|
|
@ -10,7 +10,7 @@ public class Playfield { |
|
|
|
public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) { |
|
|
|
MsG = _MsG; |
|
|
|
Size = _Size; |
|
|
|
|
|
|
|
|
|
|
|
cells = new Cell[Size][Size]; |
|
|
|
|
|
|
|
int[] bPlacement = new int[_bombAmount]; |
|
|
@ -41,6 +41,64 @@ public class Playfield { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < Size; i++) { |
|
|
|
for (int j = 0; j < Size; j++) { |
|
|
|
if (cells[i][j].type == CellType.Number) { |
|
|
|
calculateBombProximity(i, j); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void calculateBombProximity(int row, int column) { |
|
|
|
|
|
|
|
if (row > 0) { |
|
|
|
if (column > 0) { |
|
|
|
if (cells[row - 1][column - 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (cells[row - 1][column].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
|
|
|
|
if (column < cells.length - 1) { |
|
|
|
if (cells[row - 1][column + 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (row < cells.length - 1) { |
|
|
|
if (column > 0) { |
|
|
|
if (cells[row + 1][column - 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (cells[row + 1][column].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
|
|
|
|
if (column < cells.length - 1) { |
|
|
|
if (cells[row + 1][column + 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (column > 0) { |
|
|
|
if (cells[row][column - 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (column < cells.length - 1) { |
|
|
|
if (cells[row][column + 1].type == CellType.Bomb) { |
|
|
|
cells[row][column].value++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |