示例#1
0
    void MakeConnection(DungeonRoom first, DungeonRoom second)
    {
        var connection = new RoomConnection(new[] { first, second });

        first.AddConnection(connection);
        second.AddConnection(connection);
    }
示例#2
0
    public DungeonRoom AddRandomRoom(int id)
    {
        if (Rooms.Count == 0)
        {
            return(AddStartingRoom());
        }

        DungeonRoom parentRoom = GetRandomParentRoom();
        var         dir        = DirectionUtility.GetRandom();

        // Get a coordinate that isn't taken up by an existing room
        DungeonRoom roomInDirection;

        do
        {
            dir             = dir.GetClockwise();
            roomInDirection = GetRoomInDirection(parentRoom, dir);
        } while (roomInDirection != null);

        // Create new room, connect newRoom to parentRoom
        var coord   = parentRoom.Coordinate + dir.ToVector();
        var width   = Rand.NextGaussian(RoomWidthMean, RoomWidthStd);
        var height  = Rand.NextGaussian(RoomHeightMean, RoomHeightStd);
        var newRoom = new DungeonRoom(id, Level, coord, width, height);

        parentRoom.AddConnection(dir, id);
        newRoom.AddConnection(dir.GetOpposite(), parentRoom.Id);

        Rooms.Add(newRoom);

        return(newRoom);
    }