示例#1
0
文件: Rover.cs 项目: snes20/Rover
        public static void Main()
        {
            Console.WriteLine(Constants.WELCOME);
            var rover = RoverPosition.GetInstance();

            PrintRoverPosition(rover.RoverPositionX, rover.RoverPositionY, rover.RoverFacingPosition);

            while (true)
            {
                Console.WriteLine(Constants.COMMAND_PROMPT);
                try
                {
                    var command = Console.ReadLine().Trim();
                    var isValid = ValidateCommand(command);

                    if (!isValid)
                    {
                        Console.WriteLine(Constants.INVALID_COMMAND);
                    }
                    else
                    {
                        ExecuteCommand(command, rover);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"There was an error and the application will terminate. {ex.Message}");
                    System.Environment.Exit(1);
                }
            }
        }
示例#2
0
        public static RoverPosition GetInstance()
        {
            if (instance == null)
            {
                instance = new RoverPosition();
            }

            return(instance);
        }