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