Beispiel #1
0
        static void Main(string[] args)
        {
            //register our service provider for DI
            RegisterServices();
            _inputValidator = _serviceProvider.GetService <IInputValidator>();
            _inputValidator.ValidateBoundaries("5 5");

            //Show instruction
            PrintInstructions();

            //get validated grid bounds
            var grid = GetGridBoundaries();

            //we know the data is valid so set the grid data
            var gridAry   = grid.Trim().ToUpper().Split(' ');
            int max_east  = int.Parse(gridAry[0]);
            int max_north = int.Parse(gridAry[1]);

            //while (exitLoop.ToUpper() != "EXIT")
            while (true)
            {
                //get validated Landing position and heading
                string landingPosition = GetLandingPosition(max_east, max_north);

                //split the input into by space and assign vars
                var landingAry = landingPosition.Trim().ToUpper().Split(' ');

                int  landing_X = int.Parse(landingAry[0]);
                int  landing_y = int.Parse(landingAry[1]);
                char landing_z = landingAry[2][0]; //converting from string to char here

                //get the Drive Instruction
                string instructions = GetDriveInstructions();

                //init the first rover
                IRover rover = new Rover(landing_X, landing_y, landing_z, max_east, max_north);


                try
                {
                    //try to drive it
                    rover.Drive(instructions.ToUpper());
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine();
                Console.WriteLine("*** ROVER'S FINAL POSITION ***");
                Console.WriteLine(rover.GetPosition());

                Console.WriteLine();
                Console.WriteLine("INITIALIZING A NEW ROVER");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Size of Plateau :");
            var plateauSizeCommand = Console.ReadLine();

            var inputCommandPlateauSize = Helper.InputCommandPlateauSize(plateauSizeCommand);

            Plateau.SetPlateau(inputCommandPlateauSize.Width, inputCommandPlateauSize.Height);

            Console.WriteLine("Rover Position :");
            var roverPositionCommand = Console.ReadLine();

            var inputCommandRoverPosition = Helper.InputCommandRoverPosition(roverPositionCommand);
            var rover = new Rover(inputCommandRoverPosition.PositionX, inputCommandRoverPosition.PositionY, inputCommandRoverPosition.Direction);

            Console.WriteLine("Command :");
            var command = Console.ReadLine();

            rover.Drive(command);
            rover.GetPosition();

            Console.ReadLine();
        }