Exemplo n.º 1
0
        private void MoveChecker(CheckerElementViewModel newSelectedChecker)
        {
            if (_game.IsGameFinished)
            {
                ShowNotificationMessage("Game is over!");
                return;
            }
            var validationManager = new MoveValidationManager(_selectedChecker
                                                              , newSelectedChecker
                                                              , NextMoveSide
                                                              , NextMovePlayer
                                                              , this);

            MoveValidationResult preValidationMoveValidationResult = validationManager.GetPreValidationResult();

            if (preValidationMoveValidationResult.Status == MoveValidationStatus.Error)
            {
                ShowNotificationMessage(preValidationMoveValidationResult.ErrorMessage);
                return;
            }

            if (preValidationMoveValidationResult.Status == MoveValidationStatus.NothingSelected)
            {
                return;
            }

            bool makeMoveStatus = IsCheckerMoved(newSelectedChecker, NextMovePlayer);

            if (makeMoveStatus == false)
            {
                return;
            }

            if (!_game.IsGameFinished)
            {
                WaitMove();
                return;
            }

            WinnerSide = _game.GetWinnerSide();
            RaisePropertyChangedEvent(nameof(CurrentGameStatus));
            RaisePropertyChangedEvent(nameof(IsCheckersMovable));
            ShowNotificationMessage(CurrentGameStatus);
        }
Exemplo n.º 2
0
        private bool IsCheckerMoved(CheckerElementViewModel newSelectedChecker, PlayerViewModel player)
        {
            var moveValidationManager = new MoveValidationManager(_selectedChecker
                                                                  , newSelectedChecker
                                                                  , NextMoveSide
                                                                  , player
                                                                  , this);
            MoveValidationResult validationResult = moveValidationManager.GetMoveValidationResult();

            if (validationResult.Status == MoveValidationStatus.NewItemSelected)
            {
                if (_selectedChecker != null)
                {
                    _selectedChecker.IsSelected = false;
                    _selectedChecker.DeSelectPossibleMovement();
                }
                _selectedChecker = newSelectedChecker;

                _selectedChecker.IsSelected = true;
                _selectedChecker.SelectPossibleMovement();
                return(false);
            }

            if (validationResult.Status == MoveValidationStatus.DeselectChecker)
            {
                _selectedChecker.IsSelected = false;
                _selectedChecker.DeSelectPossibleMovement();
                _selectedChecker = null;
                return(false);
            }

            if (validationResult.Status == MoveValidationStatus.Error)
            {
                ShowNotificationMessage(validationResult.ErrorMessage);
                return(false);
            }

            MoveCheckerToNewPlace(_selectedChecker, newSelectedChecker, player);
            _selectedChecker.IsSelected = false;
            _selectedChecker            = null;
            return(true);
        }