Add main generation loop
This commit is contained in:
parent
5579f5d791
commit
bb3422f7d8
|
@ -100,3 +100,28 @@ class Generator:
|
||||||
|
|
||||||
return room, doory, doorx
|
return room, doory, doorx
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
height, width = self.params["height"], self.params["width"]
|
||||||
|
level = [[Tile.EMPTY for i in range(width)] for j in range(height)]
|
||||||
|
|
||||||
|
# the starting room must have no corridor
|
||||||
|
mem, self.params["corridor"] = self.params["corridor"], 0
|
||||||
|
starting_room, _, _, _, _ = self.create_random_room()
|
||||||
|
self.place_room(level, height//2, width//2, 0, 0, starting_room)
|
||||||
|
self.params["corridor"] = mem
|
||||||
|
|
||||||
|
tries, rooms_built = 0, 0
|
||||||
|
while tries < self.params["tries"] and rooms_built < self.params["max_rooms"]:
|
||||||
|
|
||||||
|
room, door_y, door_x, dy, dx = self.create_random_room()
|
||||||
|
positions = [i for i in range()]
|
||||||
|
shuffle(positions)
|
||||||
|
for pos in positions:
|
||||||
|
y, x = pos // height, pos % width
|
||||||
|
if self.room_fits(level, y, x, room, door_y, door_x, dy, dx):
|
||||||
|
self.place_room(level, y, x, door_y, door_x, room)
|
||||||
|
|
||||||
|
# post-processing
|
||||||
|
self.place_walls(level)
|
||||||
|
|
||||||
|
return level
|
||||||
|
|
Loading…
Reference in New Issue