Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created December 13, 2020 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinZikmund/e0917dc1de4b12032a2eadb84fcbf807 to your computer and use it in GitHub Desktop.
Save MartinZikmund/e0917dc1de4b12032a2eadb84fcbf807 to your computer and use it in GitHub Desktop.
private void LayoutGameBoard()
{
var minDimension = Math.Min(GameCanvasContainer.ActualHeight, GameCanvasContainer.ActualWidth);
var cellSize = (int)minDimension / _gameState.Size;
// make cell size a multiple of 4 for proper scaling
cellSize = (cellSize / 4) * 4;
if (cellSize <= 0)
{
cellSize = 4;
}
GameCanvas.Height = GameCanvas.Width = cellSize * _gameState.Size;
for (var row = 0; row < _gameState.Size; row++)
{
for (var column = 0; column < _gameState.Size; column++)
{
var cell = GetCell(row, column);
cell.SetValue(Canvas.LeftProperty, (double)(column * cellSize));
cell.SetValue(Canvas.TopProperty, (double)(row * cellSize));
cell.Height = cellSize - 1;
cell.Width = cellSize - 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment