X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fgenerators%2Fmaps.py;h=ae174d5cd7bb4ed54902850ca2f7e33dbf1f8b30;hb=723e1584330175d8156805bff09c334bb31a2c57;hp=dc36956ef08ef95e8a5d8335ef2f63e3f6ab1af0;hpb=6bd243ccffe7e577144df14586039da4a51916cd;p=koperkapel.git diff --git a/koperkapel/generators/maps.py b/koperkapel/generators/maps.py index dc36956..ae174d5 100644 --- a/koperkapel/generators/maps.py +++ b/koperkapel/generators/maps.py @@ -28,6 +28,11 @@ ATTRIBUTE_MAP = { } +def random_cardinal(): + """Return a random cardinal direction for random walks.""" + return random.choice([(0, 1), (0, -1), (1, 0), (-1, 0)]) + + class LevelGenerator: width = 0 height = 0 @@ -112,16 +117,14 @@ class LevelGenerator: for walk in range(random.randint(3, 6)): x = width // 2 + random.randint(-8, 8) y = height // 2 + random.randint(-8, 8) - dir_x = random.randint(-1, 1) - dir_y = random.randint(-1, 1) + dir_x, dir_y = random_cardinal() max_steps = random.randint(40, width * height // 4) for step in range(20, max_steps): if 0 < x < width - 1: if 0 < y < height - 1: self.underlayer[y][x] = '-' if random.random() > 0.7: - dir_x = random.randint(-1, 1) - dir_y = random.randint(-1, 1) + dir_x, dir_y = random_cardinal() x += dir_x y += dir_y