Ejemplo n.º 1
0
        public void AdvanceGame(MoveDirection moveDirection)
        {
            if (_board.IsMoveAvailable(_currentPosition, moveDirection))
            {
                _currentPosition = BoardUtil.GetNewBoardPosition(_currentPosition, moveDirection);
                _moves++;

                var messageAlreadyGiven = false;

                if (_board.IsMinePresent(_currentPosition))
                {
                    _lives--;
                    _board.ExplodeMine(_currentPosition);
                    MineFound?.Invoke(this, GetGameStatusArguments());
                    messageAlreadyGiven = true;

                    if (_lives < 1)
                    {
                        LivesRunOut?.Invoke(this, GetGameStatusArguments());
                        return;
                    }
                }

                if (_board.IsGoalReached(_currentPosition))
                {
                    GameGoalReached?.Invoke(this, GetGameStatusArguments());
                    messageAlreadyGiven = true;
                }

                if (!messageAlreadyGiven)
                {
                    MoveReported?.Invoke(this, GetGameStatusArguments());
                }
            }
            else
            {
                MoveNotAvailable?.Invoke(this, GetGameStatusArguments());
            }
        }
Ejemplo n.º 2
0
 public bool IsMoveAvailable(BoardPosition currentPosition, MoveDirection intendedMove)
 {
     return(isPositionOnTheBoard(BoardUtil.GetNewBoardPosition(currentPosition, intendedMove)));
 }