示例#1
0
文件: Robot.cs 项目: stimin/FF
        public string Run(string instruction)
        {
            string output          = "";
            var    instructionList = instruction.ToLower().ToList();

            foreach (var movement in instructionList)
            {
                switch (movement)
                {
                case 'l':
                case 'r':
                    Turn(movement);
                    break;

                case 'f':
                    Forward();
                    break;
                }

                if (!Wall.WithinWalls(X, Y))
                {
                    // If not within walls, set message and break out of loop
                    output = "Failed: robot went out of bounds!";
                    break;
                }
            }

            // If not out of bounds then return final position
            if (output == "")
            {
                output = X + " " + Y + " " + Orientation;
            }

            return(output);
        }
示例#2
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;
                        }
                    }
                }
            }
        }
示例#3
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;
                        }
                    }
                }
            }
        }