Exemple #1
0
def generate_random_levels():
    levels = {idx: Level(reduce_map(generate_random_walls(MAX_ROOMS)))
              for idx in xrange(0, NUM_LEVELS)}

    #build stairs
    for idx in xrange(0, NUM_LEVELS - 1):
        while True:
            stairs_pos = (random.randint(1, MAP_WIDTH - 1),
                          random.randint(1, MAP_HEIGHT - 1),
                          0)
            if not levels[idx].is_blocked(stairs_pos) and \
               not levels[idx + 1].is_blocked(stairs_pos):
                break

        levels[idx].stairs = Stairs(stairs_pos)

    return levels
Exemple #2
0
 def json(self):
     return {'walls': reduce_map(self.walls),
             'explored': reduce_map(self.explored),
             'stairs': self.stairs.position if self.stairs else None}