예제 #1
0
        /// <summary>
        /// Run the generator and export the result.
        /// </summary>
        public void Run()
        {
            //md ## Generating the level
            //md To generate the level, we need to create an instance of the `GraphBasedGenerator<TRoom>` class. As we use integers to identify individual rooms, we will substitute the generic type parameter with `int` and pass the level description to the constructor of the generator.

            //md_hide-next
            var levelDescription = GetLevelDescription();

            var generator = new GraphBasedGeneratorGrid2D <int>(levelDescription);

            //md When we have an instance of the generator, we simply call the `GenerateLayout()` method and wait until the generator finds a valid layout based on our level description.

            var layout = generator.GenerateLayout();

            //md The result contains information about all the rooms in the level such as outline of the room or its position.

            //md ## Saving the result
            //md If we want to quickly visualize the result, we can use the `DungeonDrawer<TRoom>` class and export the layout as a PNG image.

            var drawer = new DungeonDrawer <int>();

            drawer.DrawLayoutAndSave(layout, "basics.png", new DungeonDrawerOptions()
            {
                Width  = 2000,
                Height = 2000,
            });

            #region hidden no-clean

            var roomTemplates = levelDescription
                                .GetGraph().Vertices
                                .Select(levelDescription.GetRoomDescription)
                                .Where(x => x.IsCorridor == false)
                                .SelectMany(x => x.RoomTemplates)
                                .Distinct()
                                .ToList();
            var roomTemplatesDrawer = new RoomTemplateDrawer();
            var roomTemplatesBitmap = roomTemplatesDrawer.DrawRoomTemplates(roomTemplates, new DungeonDrawerOptions()
            {
                Width           = 1200,
                Height          = 600,
                PaddingAbsolute = 100,
                FontSize        = 1,
                EnableHatching  = false
            });
            roomTemplatesBitmap.Save(ExamplesGenerator.AssetsFolder + "/room_templates.png");

            var graphDrawer = new GraphDrawer <int>();
            var graphBitmap = graphDrawer.DrawGraph(levelDescription, new Dictionary <int, Vector2Int>()
            {
                { 0, new Vector2Int(0, 0) },
                { 1, new Vector2Int(0, -1) },
                { 2, new Vector2Int(1, -1) },
                { 3, new Vector2Int(1, 0) },
                { 4, new Vector2Int(-1, 0) },
            }, new DungeonDrawerOptions()
            {
                Width           = 2500,
                Height          = 700,
                PaddingAbsolute = 80,
                FontSize        = 3,
            });
            graphBitmap.Save(ExamplesGenerator.AssetsFolder + "/graph.png");

            #endregion
        }