示例#1
0
        static async Task Main(string[] args)
        {
            ServiceCollection serviceCollection = ConfigureServices();

            var             services   = serviceCollection.BuildServiceProvider();
            IPonyAPIClient  ponyAPI    = services.GetRequiredService <IPonyAPIClient>();
            IMazeFactory    factory    = services.GetRequiredService <IMazeFactory>();
            IMazePathfinder pathfinder = services.GetRequiredService <IMazePathfinder>();
            IMazeWalker     walker     = services.GetRequiredService <IMazeWalker>();

            Maze maze = null;

            while (maze is null)
            {
                Console.WriteLine("Enter a maze GUID or press enter for a new maze:");
                string input = Console.ReadLine();
                if (input != "")
                {
                    if (Guid.TryParse(input, out Guid mazeId))
                    {
                        maze = await factory.FromID(mazeId);
                    }
                    else
                    {
                        Console.WriteLine("Could not parse mazeId");
                    }
                }
                else
                {
                    maze = await factory.Create();

                    Console.WriteLine($"Maze ID {maze.MazeId} created.");
                }
            }
            Console.WriteLine(await ponyAPI.GetVisualMaze(maze.MazeId));

            Path ponyPath = pathfinder.Solve(maze);

            Console.WriteLine("Here's the ideal path of the pony, let's see it in action:");
            Console.WriteLine(ponyPath);
            await walker.Walk(ponyPath);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();

            services.Dispose();
        }
示例#2
0
 public MazeFactory(IPonyAPIClient ponyClient)
 {
     this.ponyClient = ponyClient;
 }
示例#3
0
 public MazeWalker(IPonyAPIClient ponyClient, IMazeFactory factory)
 {
     this.ponyClient = ponyClient;
     this.factory    = factory;
 }