Пример #1
0
Файл: Robot.cs Проект: stimin/FF
        public Robot(Wall wall, string startPosition)
        {
            // Wall must be valid for us to set the robot
            if (wall != null && wall.Valid && startPosition != null)
            {
                var startValues = startPosition.Split(' ');

                // Ensure we have 3 values
                if (startValues.Count() == 3)
                {
                    int x;
                    int y;
                    // Ensure both are positive integers
                    if (int.TryParse(startValues[0], out x) && int.TryParse(startValues[1], out y))
                    {
                        // Check co-ordinates are valid and orientataion is valid
                        if (x >= 0 && y >= 0
                            && wall.WithinWalls(x, y)
                            && IsDirectionValid(startValues[2]))
                        {
                            X = x;
                            Y = y;
                            Orientation = startValues[2];
                            Wall = wall;
                            Valid = true;
                        }
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
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;
        }