예제 #1
0
파일: Game.cs 프로젝트: pavolr/minesweeper
        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());
            }
        }
예제 #2
0
파일: Board.cs 프로젝트: pavolr/minesweeper
 public bool IsMoveAvailable(BoardPosition currentPosition, MoveDirection intendedMove)
 {
     return(isPositionOnTheBoard(BoardUtil.GetNewBoardPosition(currentPosition, intendedMove)));
 }