public ActionResult Index(string command)
        {
            string[] commandLines;
            string roversPosition, roversInstruction, result = null;

            if (!String.IsNullOrEmpty(command))
            {
                Plateau plateau = null;
                command = command.Trim().Replace("\r\n", ",");
                commandLines = command.Split(',');

                if (commandLines.Length > 0) {
                    plateau = DefiningPlateauSize(commandLines[0]);
                }

                for (int i = 1; i < commandLines.Length; i = i + 2)
                {
                    roversPosition = commandLines[i];
                    roversInstruction = commandLines[i + 1];

                    string[] roversPositionSplitted = roversPosition.Split(' ');

                    try
                    {
                        Rover rover = new Rover(
                        Convert.ToInt32(roversPositionSplitted[0]),
                        Convert.ToInt32(roversPositionSplitted[1]),
                        (CardinalCompass)Convert.ToChar(roversPositionSplitted[2]));

                        result = result + "\r\n" + rover.SetCommands(roversInstruction, plateau);
                    }
                    catch (Exception exception)
                    {
                        result = exception.Message;
                    }
                }

                @ViewBag.Result = result;
            }

            return View();
        }
Esempio n. 2
0
 private void WhenACommandIsExecuted(Rover rover, string command)
 {
     rover.SetCommands(command, PlateauFeature.GivenAPlateau(5, 5));
 }