Skip to content

Commit a863c34

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in fd2d8fe according to the output from Autopep8. Details: None
1 parent e743c6a commit a863c34

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Procedural Dungeon Generator/dungeon_generator.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import random
22

3+
34
class DungeonGenerator:
45
def __init__(self, width, height, num_levels):
56
self.width = width
@@ -9,7 +10,8 @@ def __init__(self, width, height, num_levels):
910

1011
def generate(self):
1112
for _ in range(self.num_levels):
12-
dungeon = [[' ' for _ in range(self.width)] for _ in range(self.height)]
13+
dungeon = [[' ' for _ in range(self.width)]
14+
for _ in range(self.height)]
1315
self.add_rooms(dungeon)
1416
self.add_corridors(dungeon)
1517
self.add_doors(dungeon)
@@ -27,36 +29,36 @@ def add_rooms(self, dungeon):
2729
x = random.randint(1, self.width - room_width - 1)
2830
y = random.randint(1, self.height - room_height - 1)
2931
self.create_room(dungeon, x, y, room_width, room_height)
30-
32+
3133
def create_room(self, dungeon, x, y, width, height):
3234
for i in range(x, x + width):
3335
for j in range(y, y + height):
3436
dungeon[j][i] = '.'
35-
37+
3638
def add_corridors(self, dungeon):
3739
for i in range(len(dungeon) - 1):
3840
for j in range(len(dungeon[0]) - 1):
3941
if dungeon[i][j] == '.' and dungeon[i+1][j] == '.':
4042
self.create_vertical_corridor(dungeon, i, j)
4143
if dungeon[i][j] == '.' and dungeon[i][j+1] == '.':
4244
self.create_horizontal_corridor(dungeon, i, j)
43-
45+
4446
def create_vertical_corridor(self, dungeon, x, y):
4547
while y < len(dungeon[0]) - 1 and dungeon[x][y] != '#':
4648
dungeon[x][y] = '#'
4749
y += 1
48-
50+
4951
def create_horizontal_corridor(self, dungeon, x, y):
5052
while x < len(dungeon) - 1 and dungeon[x][y] != '#':
5153
dungeon[x][y] = '#'
5254
x += 1
53-
55+
5456
def add_doors(self, dungeon):
5557
for i in range(1, len(dungeon) - 1):
5658
for j in range(1, len(dungeon[0]) - 1):
5759
if dungeon[i][j] == '.' and random.random() < 0.02:
5860
dungeon[i][j] = '+'
59-
61+
6062
def add_enemies(self, dungeon):
6163
num_enemies = random.randint(5, 15)
6264
enemy_types = ['Goblin', 'Skeleton', 'Orc', 'Spider']
@@ -66,7 +68,7 @@ def add_enemies(self, dungeon):
6668
if dungeon[y][x] == '.':
6769
enemy_type = random.choice(enemy_types)
6870
dungeon[y][x] = 'E(' + enemy_type[0] + ')'
69-
71+
7072
def add_treasures(self, dungeon):
7173
num_treasures = random.randint(5, 10)
7274
treasure_types = ['Gold', 'Gem', 'Artifact']
@@ -76,7 +78,7 @@ def add_treasures(self, dungeon):
7678
if dungeon[y][x] == '.':
7779
treasure_type = random.choice(treasure_types)
7880
dungeon[y][x] = '$(' + treasure_type[0] + ')'
79-
81+
8082
def add_traps(self, dungeon):
8183
num_traps = random.randint(5, 10)
8284
trap_types = ['Spikes', 'Poison', 'Fire']
@@ -86,21 +88,22 @@ def add_traps(self, dungeon):
8688
if dungeon[y][x] == '.':
8789
trap_type = random.choice(trap_types)
8890
dungeon[y][x] = '^(' + trap_type[0] + ')'
89-
91+
9092
def add_stairs(self, dungeon):
9193
for _ in range(2):
9294
x = random.randint(1, self.width - 2)
9395
y = random.randint(1, self.height - 2)
9496
if dungeon[y][x] == '.':
9597
dungeon[y][x] = '<' if _ == 0 else '>'
96-
98+
9799
def print_dungeons(self):
98100
for level, dungeon in enumerate(self.dungeons, start=1):
99101
print(f"Level {level} Dungeon:")
100102
for row in dungeon:
101103
print(''.join(row))
102104
print()
103105

106+
104107
# Create a dungeon generator and generate dungeons
105108
dungeon_generator = DungeonGenerator(80, 40, num_levels=3)
106109
dungeon_generator.generate()

0 commit comments

Comments
 (0)