Beispiel #1
0
        private void cc_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var cc     = (ContentControl)sender;
            var square = (Square)cc.Content;

            if (MineField.State == WinState.Unknown)
            {
                switch (e.ChangedButton)
                {
                case MouseButton.Middle:

                    if (cc == _middleDownControl)
                    {
                        checkTimer();
                        MineField.ClearSquare(square.Column, square.Row);
                    }
                    _middleDownControl = null;
                    break;

                case MouseButton.Left:

                    if (cc == _leftDownControl)
                    {
                        checkTimer();
                        MineField.RevealSquare(square.Column, square.Row, _clickCount > 1);
                    }
                    _leftDownControl = null;
                    break;
                }
            }
        }
Beispiel #2
0
        private void cc_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var cc = (ContentControl)sender;

            _clickCount = 0;

            switch (e.ChangedButton)
            {
            case MouseButton.Middle:
                _middleDownControl = cc;
                break;

            case MouseButton.Left:
                _leftDownControl = cc;
                _clickCount      = e.ClickCount;
                break;

            case MouseButton.Right:
                var square = (Square)cc.Content;

                checkTimer();
                MineField.ToggleSquare(square.Column, square.Row);
                break;
            }
        }
Beispiel #3
0
        public MineFieldElement(MineField mineField)
        {
            _timer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1),
            };
            _timer.Tick += timerTick;

            _newGameCommand = new DelegateCommand(NewGame);
            _contentControls = new ContentControl[mineField.Squares.Count];

            Initialize(mineField);
        }
Beispiel #4
0
        public MineFieldElement(MineField mineField)
        {
            _timer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1),
            };
            _timer.Tick += timerTick;

            _newGameCommand  = new DelegateCommand(NewGame);
            _contentControls = new ContentControl[mineField.Squares.Count];

            Initialize(mineField);
        }
Beispiel #5
0
        private void Initialize(MineField mineField)
        {
            Util.ThrowUnless <ArgumentNullException>(mineField != null);

            if (MineField != null)
            {
                MineField.PropertyChanged -= MineField_PropertyChanged;
            }

            MineField = mineField;

            MineField.PropertyChanged += MineField_PropertyChanged;
        }
Beispiel #6
0
 private void Initialize(MineField mineField)
 {
     if (mineField == null)
     {
         throw new ArgumentNullException("mineField");
     }
     _mineField = mineField;
     _mineField.PropertyChanged += (sender, e) =>
     {
         if (e.PropertyName == MineField.MinesLeftPropertyName)
         {
             OnPropertyChanged(new PropertyChangedEventArgs(MineField.MinesLeftPropertyName));
         }
         else if (e.PropertyName == MineField.StatePropertyName)
         {
             stopTimer();
             OnPropertyChanged(new PropertyChangedEventArgs(MineField.StatePropertyName));
         }
     };
 }
Beispiel #7
0
        public Square(MineField owner, int row, int column, bool isMine)
        {
            Contract.Requires <ArgumentNullException>(owner != null);

            if (row < 0 || row >= owner.Rows)
            {
                throw new ArgumentOutOfRangeException("row");
            }
            if (column < 0 || column >= owner.Columns)
            {
                throw new ArgumentOutOfRangeException("column");
            }

            _owner  = owner;
            _row    = row;
            _column = column;
            _isMine = isMine;
            _state  = SquareState.Unknown;

            _numberCache = -1;
        }
Beispiel #8
0
        private void Initialize(MineField mineField)
        {
            Util.ThrowUnless<ArgumentNullException>(mineField != null);

            if (MineField != null)
            {
                MineField.PropertyChanged -= MineField_PropertyChanged;
            }

            MineField = mineField;

            MineField.PropertyChanged += MineField_PropertyChanged;
        }
Beispiel #9
0
 public MineFieldElement(MineField mineField)
 {
     Initialize(mineField);
 }
Beispiel #10
0
 private void Initialize(MineField mineField)
 {
     if (mineField == null) {
     throw new ArgumentNullException("mineField");
       }
       _mineField = mineField;
       _mineField.PropertyChanged += (sender, e) => {
     if (e.PropertyName == MineField.MinesLeftPropertyName) {
       OnPropertyChanged(new PropertyChangedEventArgs(MineField.MinesLeftPropertyName));
     }
     else if (e.PropertyName == MineField.StatePropertyName) {
       stopTimer();
       OnPropertyChanged(new PropertyChangedEventArgs(MineField.StatePropertyName));
     }
       };
 }
Beispiel #11
0
 public MineFieldElement(MineField mineField)
 {
     Initialize(mineField);
 }
Beispiel #12
0
        public Square(MineField owner, int row, int column, bool isMine)
        {
            Util.RequireNotNull(owner, "owner");
              if (row < 0 || row >= owner.Rows) {
            throw new ArgumentOutOfRangeException("row");
              }
              if (column < 0 || column >= owner.Columns) {
            throw new ArgumentOutOfRangeException("column");
              }

              _owner = owner;
              _row = row;
              _column = column;
              _isMine = isMine;
              _state = SquareState.Unknown;

              _numberCache = -1;
        }