コード例 #1
0
 /// <summary>
 /// Create the mission control center (MCC) that is responsible for the provided deployment zone.
 /// </summary>
 /// <param name="deploymentZone">The zone that this MCC is responsible for exploring with its exploration crew.</param>
 /// <exception cref="ArgumentNullException">Thrown if provided deployment zone is null.</exception>
 public MissionControlCenter(IDeploymentZoneChart deploymentZone)
 {
     DeploymentDestination = deploymentZone ??
                             throw new ArgumentNullException(nameof(deploymentZone),
                                                             "Deployment zone cannot be null.");
     Explorers = new ExplorationTeam(deploymentZone);
     _setCommandChainExecutors = new Dictionary <CommandChainType, Action <IExplorerCommand> > {
         {
             CommandChainType.InitializeDeploymentZone, command => {
                 var deploymentZoneChartCommand = (DeploymentZoneChartCommand)command;
                 deploymentZoneChartCommand.SetDeploymentZoneChart(DeploymentDestination);
             }
         }, {
             CommandChainType.DeployExplorer, command => {
                 var deployExplorerCommand = (DeployExplorerCommand)command;
                 var rover = new Rover(Explorers);
                 deployExplorerCommand.SetExplorer(rover);
                 Explorers.Add(rover);
             }
         }, {
             CommandChainType.Explore, command => {
                 var exploreCommand = (ExploreCommand)command;
                 exploreCommand.SetExplorer(Explorers.Last());
             }
         }
     };
 }
コード例 #2
0
 public void SetDeploymentZoneChart(IDeploymentZoneChart deploymentZone) =>
 _associatedDeploymentZoneChart = deploymentZone;
コード例 #3
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();
        }
コード例 #4
0
ファイル: ExplorationTeam.cs プロジェクト: pengii23/MarsRover
 /// <summary>
 /// Constructs an exploration team responsible for the provided region.
 /// </summary>
 /// <param name="deploymentZoneChart">The region/zone that this exploration crew is responsible for exploring.
 /// </param>
 /// <exception cref="ArgumentNullException">Thrown if deployment zone chart is null.</exception>
 public ExplorationTeam(IDeploymentZoneChart deploymentZoneChart)
 => DeploymentZoneChart = deploymentZoneChart ??