Esempio n. 1
0
        private static void CheckCell(Location location)
        {
            var currentCell = _table[location.Y][location.X];

            CellSelectedEvent?.Invoke(location, currentCell.Type);

            if (currentCell.Type != CellType.Bed || currentCell.Checked)
            {
                return;
            }

            _table[location.Y][location.X].Check();

            if (location.X != 0)
            {
                CheckCell(new Location(location.X - 1, location.Y));
            }

            if (location.Y != 0)
            {
                CheckCell(new Location(location.X, location.Y - 1));
            }

            if (location.Y < _table.Count - 1)
            {
                CheckCell(new Location(location.X, location.Y + 1));
            }

            if (location.X < _table.FirstOrDefault().Count - 1)
            {
                CheckCell(new Location(location.X + 1, location.Y));
            }
        }
Esempio n. 2
0
        public CellViewModel(Cell cell, IEventAggregator events)
        {
            _cell = cell;

            GotFocus = new DelegateCommand<string>( CellFocused);

            _selectionEvent = events.GetEvent<CellSelectedEvent>();
            _selectionEvent.Subscribe( c =>
                                  {
                                      Selected = _cell == c;
                                  }); // Note: Could be memory leak due to event link

            events.GetEvent<HintProvidedEvent>().Subscribe( hint =>
                {
                    if( hint.Cells.Contains( _cell ) )
                    {
                        if (CellHinted != null) CellHinted(this, EventArgs.Empty);
                    }
                });

            var numberRequestEvent = events.GetEvent<NumberRequestEvent>();
            numberRequestEvent.Subscribe(ToggleNumber);

            var modeRequestEvent = events.GetEvent<ModeRequestEvent>();
            modeRequestEvent.Subscribe(ChangeMode);
        }