示例#1
0
        public ViewModel(Model.Model model)
        {
            this._model = model;
            //this._playIcon = "";
            _model.CellChanged       += new EventHandler <CellChangedEventArgs>(Model_CellChanged);
            _model.SizeChanged       += new EventHandler(Model_SizeChanged);
            _model.GenerationChanged += new EventHandler(Model_GenerationChanged);
            _model.LoadComplete      += new EventHandler(Model_LoadComplete);

            LoadConfigurationCommand = new DelegateCommand(x => OnLoadConfiguration());
            StepCommand = new DelegateCommand(x => OnStep());
            PlayCommand = new DelegateCommand(x => {
                OnPlay();
            });
            //PauseCommand = new DelegateCommand(x => OnPause());
            DeleteCellCommand = new DelegateCommand(x =>
            {
                CellField field = (CellField)x;
                _model.ChangeCell((int)((field.Row + 0.001) / CellSizeY), (int)((field.Column + 0.001) / CellSizeX));
            });
            CanvasClickCommand = new DelegateCommand(x => {
                OnCanvasClick();
            });
            NewPatternCommand          = new DelegateCommand(x => OnNewPattern());
            CreateEmptyPatternCommand  = new DelegateCommand(x => OnCreateEmptyPattern());
            CreateRandomPatternCommand = new DelegateCommand(x => OnCreateRandomPattern());

            Cells = new ObservableCollection <CellField>();
        }
示例#2
0
        private void Model_CellChanged(Object sender, CellChangedEventArgs e)
        {
            if (e.CellState == Cell.Dead)
            {
                CellField cellToRemove = Cells.Single(cell => Math.Abs(cell.Row - e.PosX * CellSizeY) < 0.0001 && Math.Abs(cell.Column - e.PosY * CellSizeX) < 0.0001);
                Cells.Remove(cellToRemove);
            }
            else
            {
                Cells.Add(new CellField
                {
                    CellState = (int)Cell.Alive,
                    Row       = e.PosX * CellSizeY,
                    Column    = e.PosY * CellSizeX
                });
            }

            OnPropertyChanged("Generation");
        }