Example #1
0
        static void Main(string[] args)
        {
            StreamReader file = new StreamReader(@"./testInput.txt");

            var rightConnerXAndY = file.ReadLine()?.Split(" ");

            if (rightConnerXAndY == null || rightConnerXAndY.Length != 2)
            {
                Console.WriteLine("Invalid input");
            }

            var upperRightX    = int.Parse(rightConnerXAndY[0]);
            var upperRightY    = int.Parse(rightConnerXAndY[1]);
            var commandFactory = new RoverCommandFactory();

            string[] LocationAndDirection;
            while ((LocationAndDirection = file.ReadLine()?.Split(" ")) != null)
            {
                var x = int.Parse(LocationAndDirection[0]);
                var y = int.Parse(LocationAndDirection[1]);

                var rove          = new MarsRover.Rover.Rover(LocationAndDirection[2], x, y, upperRightX, upperRightY);
                var commandString = file.ReadLine();

                Array.ForEach(commandString.ToCharArray(),
                              commandChar =>
                {
                    var command = commandFactory.GetRoverCommand(rove, commandChar);
                    command.Execute();
                });

                Console.WriteLine(rove.ToString());
            }
        }
 public RoverControl(Rover rover)
 {
     _commandParser = new RoverCommandFactory(rover);
     Commands       = new List <RoverCommand>();
 }
Example #3
0
 public RoverCommandCenter(Rover rover, Planet planet)
 {
     _planet = planet;
     _roverCommandFactory = new RoverCommandFactory();
     Rover = rover;
 }