Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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