I am building a little Minesweeper program at the moment. I initiate the playing field with a 2D array made of cells. When I initiate this array, all entry are null. How do I initiate it correctly?
public Cell[,] _playField;
...
public void GeneratePlayField(PlayField playField)
{
_playField = new Cell[XSize, YSize];
foreach (Cell cell in playField._playField)
{
if (playField._random.NextDouble() <= playField.FillAmount)
{
cell.IsMine = true;
}
}
}
...
internal class Cell
{
public int Neighbors;
public bool IsMine;
public Cell(int neighbors, bool isMine)
{
Neighbors = neighbors;
IsMine = isMine;
}
}