예제 #1
0
        public string ReceiveInstructions(string instructions)
        {
            try
            { if (!_inputValidator.ValidateRoverInstructions(instructions))
              {
                  return("Instructions are not Valid");
              }

              var instructionsParsed = _inputValidator.ParseInstructions(instructions);
              var position           = _inputValidator.ParsePosition(instructions);

              Rover = _roverFactory.CreateMarsRover(int.Parse(position[0]), int.Parse(position[1]), position[2]);
              AssignRover(Rover);
              for (int i = 0; i < instructionsParsed.Length; i++)
              {
                  if (instructionsParsed[i] == 'M')
                  {
                      Move();
                  }
                  else
                  {
                      Rotate(instructionsParsed[i].ToString());
                  }
              }
              return(string.Format("Mars Rover with instructions {0} successfully reached final destination {1}", instructions, Rover)); }
            catch (RoverLeavesPlateuException)
            {
                return("Instructions  " + instructions + "  invalid Rover will Leave plateau");
            }
        }