Exemplo n.º 1
0
        private int CalculateRoomPlacementScore(Vector2I location, LabyrinthDungeon dungeon, Room room)
        {
            // Check if the room at the given location will fit inside the bounds of the map.
            if (Contains(dungeon.Bounds, location, room))
            {
                var roomPlacementScore = 0;

                // Loop for each cell in the room.
                for (var column = 0; column < room.Columns; column++)
                {
                    for (var row = 0; row < room.Rows; row++)
                    {
                        // Translate the room cell location to its location in the dungeon.
                        var dungeonLocation = location + new Vector2I(column, row);

                        // Add 1 point for each adjacent corridor to the cell.
                        if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.North))
                        {
                            roomPlacementScore++;
                        }
                        if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.South))
                        {
                            roomPlacementScore++;
                        }
                        if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.West))
                        {
                            roomPlacementScore++;
                        }
                        if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.East))
                        {
                            roomPlacementScore++;
                        }

                        // Add 3 points if the cell overlaps an existing corridor.
                        if (dungeon[dungeonLocation].IsCorridor)
                        {
                            roomPlacementScore += 3;
                        }

                        // Add 100 points if the cell overlaps any existing room cells.
                        foreach (var dungeonRoom in dungeon.Rooms)
                        {
                            if (dungeonRoom.Bounds.Contains(dungeonLocation))
                            {
                                roomPlacementScore += 100;
                            }
                        }
                    }
                }

                return(roomPlacementScore);
            }
            else
            {
                return(int.MaxValue);
            }
        }
Exemplo n.º 2
0
        private void PlaceDoors(LabyrinthDungeon dungeon)
        {
            foreach (var room in dungeon.Rooms)
            {
                var hasNorthDoor = false;
                var hasSouthDoor = false;
                var hasWestDoor  = false;
                var hasEastDoor  = false;

                // TODO: Convert this into 4 loops on the sides of the room.
                for (var row = 0; row < room.Rows; row++)
                {
                    for (var column = 0; column < room.Columns; column++)
                    {
                        var cellLocation = new Vector2I(column, row);

                        // Translate the room cell location to its location in the dungeon:
                        var dungeonLocation = new Vector2I(room.Bounds.X, room.Bounds.Y) + cellLocation;

                        // Check if we are on the west boundary of our roomand if there is a corridor to the west:
                        if (!hasWestDoor && (cellLocation.X == 0) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.West))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.West);
                            hasWestDoor = true;
                        }

                        // Check if we are on the east boundary of our room and if there is a corridor to the east
                        if (!hasEastDoor && (cellLocation.X == room.Columns - 1) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.East))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.East);
                            hasEastDoor = true;
                        }

                        // Check if we are on the north boundary of our room and if there is a corridor to the north
                        if (!hasNorthDoor && (cellLocation.Y == 0) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.North))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.North);
                            hasNorthDoor = true;
                        }

                        // Check if we are on the south boundary of our room and if there is a corridor to the south
                        if (!hasSouthDoor && (cellLocation.Y == room.Rows - 1) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.South))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.South);
                            hasSouthDoor = true;
                        }
                    }
                }
            }
        }