Last active
December 13, 2020 13:03
-
-
Save MartinZikmund/c4629d76894e3a13722b64050293f569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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