Esempio n. 1
0
        /// <summary>
        /// Start executing the Mission Orders
        /// </summary>
        public bool ExecuteOrders()
        {
            // Assumptions: The Mission Orders have already been parsed by Regex to only contain 'M', 'L' or 'R' characters.

            bool          orderCarriedOut       = false;
            RoverLocation previousRoverLocation = null;

            // Log the start of the mission
            AddToEventLog(string.Format("{0}: Starting Mission", Name));

            foreach (char currentOrder in this.m_MissionOrders.ToCharArray())
            {
                // Remember the current location, for comparison with the new location.
                previousRoverLocation = m_currentLocation.Clone();

                // Log the next order
                AddToEventLog(string.Format("{0}: Processing Order:{1}", Name, currentOrder));

                switch (currentOrder)
                {
                case Constants.INPUT_ORDER_MOVE:
                    orderCarriedOut = MoveForward();
                    break;

                case Constants.INPUT_ORDER_LEFT:
                    orderCarriedOut = TurnLeft();
                    break;

                case Constants.INPUT_ORDER_RIGHT:
                    orderCarriedOut = TurnRight();
                    break;

                default:
                    throw new Exceptions.UnknownRoverOrderException(currentOrder);
                }

                // If an order was unsuccesful, stop processing further mission orders.
                if (!orderCarriedOut)
                {
                    AddToEventLog(string.Format("{0}: Mission Failed!", Name));
                    return(false);
                }

                // Log the succesful movement
                AddToEventLog(string.Format("{0}: Succesfully changed position from '{1}' to '{2}'", Name, previousRoverLocation, m_currentLocation));
            }

            // Nothing has gone wrong, mark the mission as a success
            AddToEventLog(string.Format("{0}: Mission Completed!", Name));
            m_currentStatus = RoverStatus.MissionComplete;
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Tell the rover that it has landed and is about to start wondering about.
        /// </summary>
        /// <returns></returns>
        public bool LandOnPlateau()
        {
            if (m_plateauXDimension == 0 || m_plateauYDimension == 0)
            {
                throw new Exceptions.NotReadyForLandingException("This Rover doesn't know the size of the plateau to land on.");
            }

            // Set the current location to the pre-programmed starting location
            m_currentLocation = m_startingLocation.Clone();

            // Update the status of the rover
            m_currentStatus = RoverStatus.Roving;

            return(true);
        }