Skip to content

Instantly share code, notes, and snippets.

View MartinZikmund's full-sized avatar
⌨️
Coding

Martin Zikmund MartinZikmund

⌨️
Coding
View GitHub Profile
private void NextGeneration()
{
_gameState?.Tick();
RedrawBoard();
}
public void Clear()
{
for (int row = 0; row < Size; row++)
{
for (int column = 0; column < Size; column++)
{
Cells[row, column] = CellState.Dead;
}
}
}
private void Clear()
{
_gameState?.Clear();
RedrawBoard();
}
private BitmapImage _aliveBitmap = new BitmapImage(new Uri($"ms-appx:///Assets/Classic_alive.png"));
private BitmapImage _deadBitmap = new BitmapImage(new Uri($"ms-appx:///Assets/Classic_dead.png"));
private void RedrawBoard()
{
for (var row = 0; row < _gameState.Size; row++)
{
for (var column = 0; column < _gameState.Size; column++)
{
var cell = GetCell(row, column);
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;
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++)
{
private GameState _gameState;
private void StartNewGame()
{
var boardSize = (int)BoardSizeNumberBox.Value;
if (_gameState?.Size != boardSize)
{
_gameState = new GameState(boardSize);
PrepareGrid();
LayoutGameBoard();
<Page
...
xmlns:controls="using:Microsoft.UI.Xaml.Controls">
<Grid
Padding="12"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
RowSpacing="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<ComboBox
x:Name="ThemeComboBox"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Stretch"
Header="Theme"
ItemsSource="{x:Bind Themes}"
SelectedItem="{x:Bind CurrentTheme, Mode=TwoWay}" />
private void UpdateBitmaps()
{
_aliveBitmap = new BitmapImage(new Uri($"ms-appx:///Assets/{_currentTheme}_alive.png"));
_deadBitmap = new BitmapImage(new Uri($"ms-appx:///Assets/{_currentTheme}_dead.png"));
}