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")); | |
| } |
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 GameTheme _currentTheme = GameTheme.Classic; | |
| public GameTheme[] Themes { get; } = new GameTheme[] | |
| { | |
| GameTheme.Classic, | |
| GameTheme.Bacteria, | |
| GameTheme.CatMouse, | |
| GameTheme.FireWater | |
| }; |
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 enum GameTheme | |
| { | |
| Classic, | |
| CatMouse, | |
| Bacteria, | |
| FireWater | |
| } |
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
| var swap = Cells; | |
| Cells = _nextGeneration; | |
| _nextGeneration = swap; |
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 CellState[,] _nextGeneration = null; | |
| public void Tick() | |
| { | |
| _nextGeneration = _nextGeneration ?? new CellState[Size, Size]; | |
| for (int row = 0; row < Size; row++) | |
| { | |
| for (int column = 0; column < 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 readonly Random _random = new Random(); | |
| public void Randomize() | |
| { | |
| for (int row = 0; row < Size; row++) | |
| { | |
| for (int column = 0; column < Size; column++) | |
| { | |
| Cells[row, column] = (CellState)_random.Next(0, 2); | |
| } |