Ejemplo n.º 1
0
        public ActionResult Index(Form form)
        {
            // Output the error messages if input invalid
            var wall = new Wall(form.WallSize);

            if (!wall.Valid)
            {
                ModelState.AddModelError("WallSize", "Value must be two numbers separated by space (i.e. '5 8')");
            }

            var robot = new Robot(wall, form.RobotStart);

            if (!robot.Valid)
            {
                ModelState.AddModelError("RobotStart", "Value must be two numbers within set wall size and either Left, Right, Up or Down, separated by space (i.e. '2 3 Up')");
            }

            if (ModelState.IsValid)
            {
                // Everything valid so run instructions
                form.Output = robot.Run(form.Instructions);
            }
            return View(form);
        }
Ejemplo n.º 2
0
        private string TestForm(string wallSize, string robotStart, string instructions)
        {
            var wall = new Wall(wallSize);
            var robot = new Robot(wall, robotStart);
            var output = robot.Run(instructions);

            return output;
        }