Skip to content

Instantly share code, notes, and snippets.

View MartinZikmund's full-sized avatar
⌨️
Coding

Martin Zikmund MartinZikmund

⌨️
Coding
View GitHub Profile
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"));
}
private GameTheme _currentTheme = GameTheme.Classic;
public GameTheme[] Themes { get; } = new GameTheme[]
{
GameTheme.Classic,
GameTheme.Bacteria,
GameTheme.CatMouse,
GameTheme.FireWater
};
public enum GameTheme
{
Classic,
CatMouse,
Bacteria,
FireWater
}
var swap = Cells;
Cells = _nextGeneration;
_nextGeneration = swap;
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++)
{
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);
}