private void OnPredefinedBoardSelected(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { var predefinedBoard = PredefinedBoards.SelectedItem.ToString(); if (!string.IsNullOrEmpty(predefinedBoard)) { string predefinedBoardPath = Path.Combine(GetExeFolder(), predefinedBoard); if (File.Exists(predefinedBoardPath)) { BoardSetup boardSetup = BoardSetup.Load(predefinedBoardPath); Width.Text = boardSetup.Width.ToString(); Height.Text = boardSetup.Height.ToString(); Generations.Text = boardSetup.NumberOfGenerations.ToString(); _boardWidth = boardSetup.Width; _boardHeight = boardSetup.Height; _boardVisualisation.SetBoardSize(_boardWidth, _boardHeight); foreach (Tuple <int, int> liveCell in boardSetup.InitialLiveCells) { _boardVisualisation.SetCellExistence(liveCell.Item1, liveCell.Item2, true); } } } }
private void OnStartClicked(object sender, RoutedEventArgs e) { if (IsBoardSizeValid() && int.TryParse(Generations.Text, out int numberOfGenerations) && numberOfGenerations > 1) { List <Tuple <int, int> > initialLiveCells = _boardVisualisation.GetLiveCells(); var gameOfLife = new Model.GameOfLife(); var boardSetup = new BoardSetup { Width = _boardWidth, Height = _boardHeight, NumberOfGenerations = numberOfGenerations, InitialLiveCells = initialLiveCells }; gameOfLife.NextGeneration += OnNextGenerationGenerated; Task.Run(() => { gameOfLife.Play(_boardWidth, _boardHeight, numberOfGenerations, new GameOfLifeRules(), initialLiveCells, 250); }); } }