예제 #1
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);
        }
예제 #2
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();
        }