Exemple #1
0
        static void Main(string[] args)
        {
            var gameCoordinator  = ToyRobot.InitializeGame();
            var commandProcessor = new CommandProcessor(gameCoordinator);

            string launchMessage =
                @"  
                  **************************************
                  **                                  **
                  **          TOY ROBOT GAME          **
                  **                                  **
                  **************************************
                  

                  Place the toy robot (using the command below)
                  on the 5 x 5 grid to begin the game:

                     PLACE X,Y,F 
                     (X and Y must be between 0 - 4)
                     (F is either NORTH, SOUTH, EAST or WEST)

                  Once the Robot is placed the following Commands 
                  can be issued to operate the game:
                                
                     REPORT – Shows the current status of the toy. 
                     LEFT   – turns the toy 90 degrees left.
                     RIGHT  – turns the toy 90 degrees right.
                     MOVE   – Moves the toy 1 unit in the facing direction.
                     TEST   - Perform tests based on the test cases provided
                     EXIT   – Exits the game.
                ";

            var stopApplication = false;
            var robotPlaced     = false;

            Console.WriteLine(launchMessage);
            do
            {
                Console.Write(robotPlaced ? "Robot>" : "Game>");

                var command = Console.ReadLine();
                if (command == null)
                {
                    continue;
                }

                switch (command.ToLower())
                {
                case "exit":
                    stopApplication = true;
                    break;

                case "test":
                    RunTests();
                    break;

                default:
                    try
                    {
                        command = command.Trim();

                        var input = CalculateInputCommand(command);

                        string report;
                        (robotPlaced, report) = commandProcessor.ProcessCommand(input);

                        if (report != string.Empty)
                        {
                            Console.WriteLine(report);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }

                    break;
                }
            } while (!stopApplication);
        }