Exemple #1
0
        public void ExecuteAllTest()
        {
            IDeploymentZoneChart deploymentZoneChart = new Plateau {
                Size = new Size(5, 5)
            };
            var mcc = new MissionControlCenter(deploymentZoneChart);

            mcc.ExecuteAll();

            Assert.IsTrue(mcc.NumberTotalCommandsExecutedSuccessfully == 0);

            mcc.SetCommands(new List <IExplorerCommand> {
                new DeploymentZoneChartCommand(new Size(4, 4))
            });

            mcc.ExecuteAll();
            Assert.IsTrue(mcc.NumberTotalCommandsExecutedSuccessfully == 1);
        }
Exemple #2
0
        private static void DirectCommandLineInput()
        {
            string consoleInput;
            var    commandParser = new CommandParser();
            IDeploymentZoneChart deploymentZone = null;

            do
            {
                Console.WriteLine("Enter the size of the deployment zone for your spacecraft:  ");
                consoleInput = Console.ReadLine();
                var deploymentZoneCommand = commandParser.ParseCommandBlock(consoleInput);
                if (deploymentZoneCommand == null || !(deploymentZoneCommand.ToList().First()
                                                       is DeploymentZoneChartCommand deploymentZoneChartCommand))
                {
                    continue;
                }

                // Right now, only supporting one type of deployment zone: Plateau.
                // Definitely room for improvement here to make it more versile with many different kinds of deployment
                // zones. Adding a factory for this would be good.
                deploymentZone = new Plateau();
                deploymentZoneChartCommand.SetDeploymentZoneChart(deploymentZone);
                // Set the size of the new deployment zone based on the provided command input.
                deploymentZoneChartCommand.Execute();

                Console.WriteLine("Deployment zone initialized successfully.");
            } while (deploymentZone == null);

            Console.WriteLine("Bringing Mission Control Center (MCC) online...");
            var mcc = new MissionControlCenter(deploymentZone);

            Console.WriteLine("MCC Online.");

            // Must deploy at least one explorer successfully before providing any other commands.
            Explorer explorer = new Rover(mcc.Explorers);

            do
            {
                Console.WriteLine("Enter deployment coordinates and heading of exploration module:  ");
                consoleInput = Console.ReadLine()?.Trim();

                var launchRoverCommand = commandParser.ParseCommandBlock(consoleInput);
                // Cannot have empty input at this point.
                if (launchRoverCommand == null ||
                    !(launchRoverCommand.ToList().First() is DeployExplorerCommand launchCommand))
                {
                    continue;
                }

                // Execute the single explorer creation command.
                launchCommand.SetExplorer(explorer);

                if (launchCommand.Execute())
                {
                    mcc.Explorers.Add(explorer);
                }
            } while (!mcc.HasDeployedAnExplorer());

            do
            {
                Console.WriteLine(
                    "Execute explorer action command by entering string of movement commands, deploy a new rover to " +
                    "provided coordinates and heading, or enter nothing to compose report:  ");
                consoleInput = Console.ReadLine()?.Trim();

                var nextCommand = commandParser.ParseCommandBlock(consoleInput);
                var commandList = nextCommand.ToList();
                // User is requesting report due to blank input being provided.
                if (commandList.Contains(null))
                {
                    break;
                }

                mcc.SetCommands(commandList);
                mcc.ExecuteAll();
            } while (true);

            // TODO: Add in report generation capability at any point, not just at the end.

            Console.WriteLine("Composing exploration report...");
            Console.WriteLine(mcc.Explorers.GenerateExplorationReport());
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }