Exemple #1
0
        /// <summary>
        /// This method accepts user instructions, checks validity of user instructions and moves the rover according to them
        /// </summary>
        /// <param name="rover"></param>
        /// <returns></returns>
        private void ProcessInstructions(IRover rover)
        {
            //Get user input
            Console.WriteLine();
            Console.WriteLine("ENTER INSTRUCTIONS FOR THE ROVER TO MOVE ON THE PLATEAU:");
            Console.WriteLine("(Note: Use L to turn left, R to turn right, M to move one position ahead in the direction of facing)");

            string enteredInstructions = Console.ReadLine().ToUpper();

            //Check format
            InputValidator validator = new InputValidator();
            bool           isValid   = validator.IsInstructionsFormatValid(enteredInstructions);

            while (!isValid)
            {
                Console.WriteLine();
                Console.WriteLine("ERROR! Please enter in valid format:");
                Console.WriteLine("(Valid values: series of characters containing only L,R and M)");
                enteredInstructions = Console.ReadLine();
                isValid             = validator.IsInstructionsFormatValid(enteredInstructions);
            }

            try
            {
                //Process instructions
                rover.ProcessInstructions(enteredInstructions);
            }
            catch (RoverOutOfRangeException ex)
            {
                Console.WriteLine("Operation aborted!! Rover is at the edge, can not move ahead.");
            }
        }