Beispiel #1
0
        private FieldViewModel CreateFieldViewModel(int x, int y)
        {
            var fieldViewModel = new FieldViewModel(x, y, _gameController.LifeBoard[x, y]);

            fieldViewModel.LifeStateChangeRequested += ToggleLifeState;
            return(fieldViewModel);
        }
Beispiel #2
0
        /// <summary>
        /// Changes the old game to a new game.
        /// </summary>
        /// <param name="game">The new game.</param>
        private void ChangeGame(Game game)
        {
            if (_gameController != null)
            {
                _gameController.LifeBoardChanged -= ReflectChanges;
                _fields = null;
            }

            if (game != null)
            {
                _gameController = _gameService.CurrentGame;
                _gameController.LifeBoardChanged += ReflectChanges;

                _fields = new FieldViewModel[_gameController.LifeBoard.Width][];

                for (int y = 0; y < Rows; ++y)
                {
                    for (int x = 0; x < Columns; ++x)
                    {
                        if (y == 0)
                        {
                            _fields[x] = new FieldViewModel[_gameController.LifeBoard.Height];
                        }

                        _fields[x][y] = CreateFieldViewModel(x, y);
                    }
                }

                NewRuleDescription = _gameController.Rules.RuleDescription;
                RaisePropertyChanged(null); // Refresh every property
            }
        }