Esempio n. 1
0
        /// <summary>
        /// The creation of ObstacleDetector requires the map of known obstacles
        /// </summary>
        /// <param name="obstacleList">The map of known obstacles</param>
        /// <returns></returns>
        public static ObstacleDetector Create(List <Coordinates> obstacleMap)
        {
            if (obstacleMap == null)
            {
                throw new ArgumentNullException($"{nameof(obstacleMap)}");
            }

            ObstacleDetector obj = new ObstacleDetector();

            obj.obstacleMap = obstacleMap;
            return(obj);
        }
Esempio n. 2
0
        /// <summary>
        /// Instantiates a new Rover instance given the initial position coordinates, the initial direction
        /// and provides the Rover with an obstacle detection system
        /// </summary>
        /// <param name="initialPositionX">The starting X position on planet surface</param>
        /// <param name="initialPositionY">The starting Y position on planet surface</param>
        /// <param name="direction">The starting direction on planet surface</param>
        /// <param name="obstacleDetector">The obstacle detection system is mandatory for safely reasons</param>
        /// <returns></returns>
        public static Rover Create(int initialPositionX, int initialPositionY, string direction, ObstacleDetector obstacleDetector)
        {
            if (obstacleDetector == null)
            {
                throw new ArgumentNullException($"{nameof(obstacleDetector)}");
            }

            var initialPosition  = Coordinates.Create(initialPositionX, initialPositionY);
            var initialDirection = DirectionsList.GetByCode(direction);

            if (initialDirection == null)
            {
                throw new ArgumentException($"{nameof(initialDirection)} was not recognized as valid direction");
            }

            Rover newRover = new Rover();

            newRover.Position         = initialPosition;
            newRover.Direction        = initialDirection;
            newRover.obstacleDetector = obstacleDetector;
            return(newRover);
        }