예제 #1
0
        /**
         * Select random points in the room using the <see cref="oneInXChanceToGenerateARoom"/> function,
         * then create new, smaller rooms of varying size <see cref="SelectRoomWidth"/> & <see cref="SelectRoomHeight"/>
         * and lastly, use <see cref="ITileService"/> to remove merge overlapping rooms into one bigger, more naturally
         * looking room.
         */
        private async Task <List <Tile> > GenerateRooms(int wallThickness)
        {
            var allRooms = new List <Room>();

            for (var x = wallThickness; x < Width - wallThickness - MinimumRoomSize; x++)
            {
                for (var y = wallThickness; y < Height - wallThickness - MinimumRoomSize; y++)
                {
                    if (OneIn(oneInXChanceToGenerateARoom))
                    {
                        var room = await RoomBuilder.Create()
                                   .WithWidth(SelectRoomWidth)
                                   .WithHeight(SelectRoomHeight)
                                   .WithStartingPosition(new Position(x, y))
                                   .WithOutsideWalls()
                                   .WithInsideTilesOfType(TileType.Floor)
                                   .BuildAsync();

                        allRooms.Add(room);
                    }
                }
            }
            allRooms = roomService.TrimSpilledRooms(allRooms).ToList();
            var mergedRooms = roomService.MergeAllRooms(allRooms).ToList();

            mergedRooms = hallwayService.CreateDoors(mergedRooms).ToList();
            var hallways = hallwayService.CreateHallways(mergedRooms);

            var allTiles = hallwayService.HandleDoorTiles(mergedRooms.SelectMany(r => r.Tiles).Concat(hallways)).ToList();

            allTiles = allTiles.Distinct().ToList();
            return(allTiles);
        }
예제 #2
0
        public async Task <Grid> GenerateGridAsync()
        {
            var room = await RoomBuilder.Create()
                       .WithHeight(Height)
                       .WithWidth(Width)
                       .WithOutsideWalls()
                       .WithInsideTiles(wallThickness => CreateFloor(wallThickness))
                       .BuildAsync();

            return(new Grid(settings.GridSettings.Height, settings.GridSettings.Width,
                            new TileConfig(settings.TileSettings.Size), room.Tiles));
        }