コード例 #1
0
ファイル: RoverController.cs プロジェクト: saragargom/Rover
        public static void ExploreArea(IPlanet mars, IRover rover)
        {
            Console.WriteLine(string.Format("Initial rover location- X:{0}, Y:{1}, Direction:{2}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString()));
            foreach (char command in rover.Instruction)
            {
                bool resultMove = true;
                Console.WriteLine("Processing : " + command);

                if (command == (char)Common.TurnDirection.L)
                {
                    rover.TurnRight();
                }
                else if (command == (char)Common.TurnDirection.R)
                {
                    rover.TurnLeft();
                }
                else if (command == Common.ForwardCommand)
                {
                    resultMove = mars.MoveRover(rover);
                }
                else
                {
                    Console.WriteLine("Invalid Command: " + command);
                }

                // For each robot position/ instruction in the input, the output should indicate the final grid position and orientation of the robot.
                // If a robot falls off the edge of the grid the word "LOST" should be printed after the position and orientation.
                Console.WriteLine(string.Format("{0}, {1}, {2} {3}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString(), resultMove? "": "LOST"));
            }

            Console.WriteLine(string.Format("Final rover location- X:{0}, Y:{1}, Direction:{2}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString()));
        }