Navigate through different maps while climbing ladders

This commit is contained in:
Yohann D'ANELLO
2020-12-26 01:08:43 +01:00
parent 8636d571b5
commit 9a56b4d7e9
4 changed files with 30 additions and 9 deletions

View File

@ -140,12 +140,15 @@ class Map:
Put randomly {count} entities on the map, where it is available.
"""
for ignored in range(count):
y, x = 0, 0
while True:
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
tile = self.tiles[y][x]
if tile.can_walk():
break
try:
tile = self.tiles[y][x]
except Exception as e:
raise Exception(y, x, len(self.tiles))
else:
if tile.can_walk():
break
entity = choice(Entity.get_all_entity_classes())()
entity.move(y, x)
self.add_entity(entity)