Exemplo n.º 1
0
        private static (Room room, List <Point>, Direction direction) GetStartTiles(
            List <Room> rooms,
            List <Corridor> corridors,
            int corridorWidth,
            List <int> wideIndexList
            )
        {
            var minNumberOfCorridors = rooms.Min(room => room.Corridors.Count);
            var startRoomCanddiates  = (minNumberOfCorridors == 0)
                ? rooms.Where(room => room.Corridors.Count == 0).ToList()
                : rooms;

            var room           = startRoomCanddiates[Luck.Next(startRoomCanddiates.Count)];
            var availableTiles = new List <(List <Point> tiles, Direction direction)>();

            var upTilesList = GetUpOrDownStartTiles(room, rooms, corridors, corridorWidth, wideIndexList, upOrDown: true);

            upTilesList.ForEach(upTiles => availableTiles.Add((upTiles, Direction.UP)));

            var downTilesList = GetUpOrDownStartTiles(room, rooms, corridors, corridorWidth, wideIndexList, upOrDown: false);

            downTilesList.ForEach(downTiles => availableTiles.Add((downTiles, Direction.DOWN)));

            var leftTiles = GetLeftOrRightStartTiles(room, rooms, corridors, corridorWidth, wideIndexList, leftOrRight: true);

            leftTiles.ForEach(leftTiles => availableTiles.Add((leftTiles, Direction.LEFT)));

            var rightTilesList = GetLeftOrRightStartTiles(room, rooms, corridors, corridorWidth, wideIndexList, leftOrRight: false);

            rightTilesList.ForEach(rightTiles => availableTiles.Add((rightTiles, Direction.RIGHT)));

            if (!availableTiles.Any())
            {
                return(default, default, default);
Exemplo n.º 2
0
        private static void AddNewRoom(IMapGenerationParams mapParams, List <Room> rooms)
        {
            var newRoom = new Room()
            {
                TilePos = new Point(
                    x: Luck.Next(1, mapParams.Width - 1),  // external wall border required
                    y: Luck.Next(1, mapParams.Height - 1)  // external wall border required
                    ),
                Size = new Size(1, 1)
            };

            var isNotAdjacentToOtherRooms = rooms
                                            .All(room => !room.Intersects(newRoom, mapParams.MinRoomSeparation));

            if (isNotAdjacentToOtherRooms)
            {
                rooms.Add(newRoom);
            }
        }
Exemplo n.º 3
0
        public override void Init(Game game)
        {
            var boardComp     = game.Entities.GetSingleComponent <BoardComp>();
            var tilePositions = boardComp
                                .TilePositionsByTileId
                                .Select(tileIdAndPosition => tileIdAndPosition.Value)
                                .ToList();

            var tilesPosWithSpaceAround = tilePositions
                                          .Where(tilePos => HasSpaceAround(tilePositions, tilePos))
                                          .ToList();

            var occupiedTiles = new List <Point>();

            var playerTile = tilesPosWithSpaceAround[Luck.Next(tilesPosWithSpaceAround.Count)];

            game.AddEntity(CreatePlayer(playerTile));
            occupiedTiles.Add(playerTile);

            var tilePosAndDistances = GetDistancesFrom(boardComp, playerTile)
                                      .Where(tile => tilePositions.Contains(tile.tilePos))
                                      .ToList();

            var enemiesCounter    = 0;
            var totalEnemiesCount = SpawnConfig.GetEnemyNumber(FloorFactor);
            var enemySpeedRange   = SpawnConfig.GetEnemySpeedRangeInGameTicks(FloorFactor);

            while (enemiesCounter < totalEnemiesCount)
            {
                var enemy = CreateEnemy(enemySpeedRange, boardComp, tilePosAndDistances, occupiedTiles);
                if (enemy == null)
                {
                    continue;
                }

                game.AddEntity(enemy);
                enemiesCounter++;
            }

            var maxDistance = tilePosAndDistances.Max(tcd => tcd.distance);

            // TODO avoid spawining 2 items in the same tile

            game.AddEntity(CreateFood(tilePosAndDistances, occupiedTiles, maxDistance));
            game.AddEntity(CreateTorch(tilePosAndDistances, occupiedTiles, maxDistance));
            game.AddEntity(CreateMapRevealer(tilePosAndDistances, occupiedTiles, maxDistance));

            var isLastFloor = FloorFactor == 1f;

            if (isLastFloor)
            {
                game.AddEntity(CreateAmulet(tilePosAndDistances, occupiedTiles, maxDistance));
            }
            else
            {
                var tilePosAndDistWithSpaceAround = tilePosAndDistances
                                                    .Where(tpad => tilesPosWithSpaceAround.Contains(tpad.tilePos))
                                                    .ToList();

                game.AddEntity(CreateDownStairs(tilePosAndDistWithSpaceAround, occupiedTiles, maxDistance));
            }

            var isFirstFloor = PreviousFloorResult == null;

            if (!isFirstFloor)
            {
                game.AddEntity(CreateUpStairs(playerTile));
            }

            game.RemoveSystem(this);
        }