Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private readonly List<Image> _cells = new List<Image>();
private void PrepareGrid()
{
GameCanvas.Children.Clear();
for (var row = 0; row < _gameState.Size; row++)
{
for (var column = 0; column < _gameState.Size; column++)
{
var cell = GetCell(row, column);
cell.Source = _gameState.Cells[row, column] == CellState.Alive ?
_aliveBitmap : _deadBitmap;
GameCanvas.Children.Add(cell);
}
}
}
private Image GetCell(int row, int column)
{
var index = row * _gameState.Size + column;
return GetCell(index);
}
private Image GetCell(int order)
{
while (_cells.Count <= order)
{
_cells.Add(CreateCell());
}
return _cells[order];
}
private Image CreateCell() => new Image();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment