Beispiel #1
0
        private static void MoveRover(IGrid grid, string locationLine, string movesLine)
        {
            IDirectionParser directionParser = (IDirectionParser)container[typeof(IDirectionParser)];
            ILocationParser locationParser = (ILocationParser)container[typeof(ILocationParser)];

            Direction direction = directionParser.GetDirection(locationLine);
            Point location = locationParser.GetLocation(locationLine);
            IMoveSupplier supplier = (IMoveSupplier)container[typeof(IMoveSupplier)];

            supplier.Init(movesLine);
            Rover rover = new Rover(direction, location, grid, supplier);
            try
            {
                rover.ExecuteMoves();
            }
            catch (InvalidLocationException ex)
            {
                Console.WriteLine(MarsRover.IllegalLocation);
            }
            Console.WriteLine(String.Format("{0} {1} {2}", rover.Location.X, rover.Location.Y, rover.Direction));

            container.Release(supplier);
            container.Release(directionParser);
            container.Release(locationParser);
        }