Ejemplo n.º 1
0
 /// <summary>
 /// Checks if the position is within the boundary of grid
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 private bool CheckRoverIsInPlateauBoundary(RoverPosition position)
 {
     if (position.x < 0 || position.y < 0 || position.x > PlateauGridDimensions.x || position.y > PlateauGridDimensions.y)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Moves rover one position ahead in the direction it is facing
        /// </summary>
        /// <returns></returns>
        private RoverPosition MoveAheadInTheSameDirection()
        {
            RoverPosition newPosition      = this.roverPosition;
            Direction     currentDirection = this.roverPosition.direction;

            switch (currentDirection)
            {
            case Direction.N:
                newPosition.y += 1;
                break;

            case Direction.E:
                newPosition.x += 1;
                break;

            case Direction.S:
                newPosition.y -= 1;
                break;

            case Direction.W:
                newPosition.x -= 1;
                break;

            default:
                break;
            }

            if (CheckRoverIsInPlateauBoundary(newPosition))
            {
                this.roverPosition = newPosition;
            }
            else
            {
                throw new RoverOutOfRangeException();
            }
            return(this.roverPosition);
        }