Created
December 13, 2020 13:04
-
-
Save MartinZikmund/e0917dc1de4b12032a2eadb84fcbf807 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 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