Example #1
0
        static void Print(RoverService firstRover, RoverService secondRover)
        {
            var builder = new StringBuilder();

            builder.AppendLine($"{"Plateau max X and Y",25}  {"Starting coordinates",25}  {"Directions",25} {"Expected Result",25}");
            builder.AppendLine($"{"5,5",25} {"1 2 N",25} {"LMLMLMLMM",25} {firstRover.Print(),25} \t");
            builder.AppendLine($"{"5,5",25} {"3 3 E",25} {"MMRMMRMRRM",25} {secondRover.Print(),25} \t");
            Console.WriteLine(builder.ToString());
        }
Example #2
0
        static void Main(string[] args)
        {
            IRoverService roverService = new RoverService();
            Plateau       plateau      = new Plateau(5, 5);
            Coordinates   coordinates  = new Coordinates(2, 0);

            Rover rover = new Rover(plateau, Domain.Enum.Direction.South, coordinates);

            roverService.ApplyCommand(rover, "MLLM");
            Console.WriteLine(rover.coordinates.xCoordinate + " " + rover.coordinates.yCoordinate + " " + rover.direction);

            coordinates = new Coordinates(3, 3);
            rover       = new Rover(plateau, Domain.Enum.Direction.East, coordinates);
            roverService.ApplyCommand(rover, "MMRMMRMRRM");
            Console.WriteLine(rover.coordinates.xCoordinate + " " + rover.coordinates.yCoordinate + " " + rover.direction);
        }
Example #3
0
        static Result ReadRovers()
        {
            Result result     = new Result();
            var    roverInput = Console.ReadLine().Split(' ');

            int       x         = Convert.ToInt32(roverInput[0]);
            int       y         = Convert.ToInt32(roverInput[1]);
            Direction direction = new Direction();

            switch (roverInput[2].ToString())
            {
            case ("N"):
                direction = Direction.N;
                break;

            case ("E"):
                direction = Direction.E;
                break;

            case ("S"):
                direction = Direction.S;
                break;

            case ("W"):
                direction = Direction.W;
                break;

            default:
                result.SetError("Wrong direction");
                break;
            }
            if (result.IsSuccess)
            {
                Rover        rover        = new Rover(new Position(x, y), direction);
                RoverService roverService = new RoverService(rover, plateau, result);
                if (result.IsSuccess)
                {
                    roverService.Process(Console.ReadLine());
                    result.ResultDescription = roverService.GetCurrentLocation();
                }
                return(result);
            }
            return(result);
        }
Example #4
0
        static void Main()
        {
            SetGlobalExceptionHandler();

            //First Rover
            var firstPlateau = new Plateau(new Position(5, 5));
            var firstRover   = new RoverService(firstPlateau, new Position(1, 2), Directions.N);

            firstRover.Process("LMLMLMLMM");

            //Second Rover
            var secondPlateau = new Plateau(new Position(5, 5));
            var secondRover   = new RoverService(secondPlateau, new Position(3, 3), Directions.E);

            secondRover.Process("MMRMMRMRRM");

            Print(firstRover, secondRover);

            Console.ReadKey();
        }