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
| <XamlControlsResources ControlsResourcesVersion="Version2" xmlns="using:Microsoft.UI.Xaml.Controls" /> |
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
| <XamlControlsResources Version="Latest" xmlns="using:Microsoft.UI.Xaml.Controls" /> |
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 Image CreateCell() | |
| { | |
| var cell = new Image(); | |
| cell.Tapped += OnCellTapped; | |
| return cell; | |
| } | |
| private void OnCellTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) | |
| { | |
| var index = _cells.IndexOf((Image)sender); |
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 MainPage() | |
| { | |
| this.InitializeComponent(); | |
| _timer.Tick += OnTimerTick; | |
| } | |
| private void OnTimerTick(object sender, object e) | |
| { | |
| _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
| private readonly DispatcherTimer _timer = new DispatcherTimer() | |
| { | |
| Interval = TimeSpan.FromSeconds(1) | |
| }; | |
| private void AutoPlayToggled() | |
| { | |
| if (AutoPlayToggleSwitch.IsOn) | |
| { | |
| _timer.Start(); |
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; |