@@ -26,11 +26,11 @@ class Generator:
2626 """
2727
2828 def __init__ (
29- self ,
30- seed : str ,
31- output_file_name : str ,
32- output_file_path : str = "" ,
33- stage_id : int = 2 ,
29+ self ,
30+ seed : str ,
31+ output_file_name : str ,
32+ output_file_path : str = "" ,
33+ stage_id : int = 2 ,
3434 ):
3535 """
3636 Creates a new generator with the given arguments.
@@ -53,22 +53,22 @@ def to_json(self, indent: int) -> str:
5353 indent_s = my_globals .BASE_INDENT * indent
5454
5555 j = (
56- "{\n "
57- + indent_s
58- + '"_width": '
59- + str (my_globals .FLOOR_WIDTH )
60- + ",\n "
61- + indent_s
62- + '"_height": '
63- + str (my_globals .FLOOR_HEIGHT )
64- + ",\n "
65- + indent_s
66- + '"_floor": '
67- + self ._floor .to_json (indent + 1 )
68- + ",\n "
69- + indent_s
70- + '"_generated_by": "python"'
71- + "\n }"
56+ "{\n "
57+ + indent_s
58+ + '"_width": '
59+ + str (my_globals .FLOOR_WIDTH )
60+ + ",\n "
61+ + indent_s
62+ + '"_height": '
63+ + str (my_globals .FLOOR_HEIGHT )
64+ + ",\n "
65+ + indent_s
66+ + '"_floor": '
67+ + self ._floor .to_json (indent + 1 )
68+ + ",\n "
69+ + indent_s
70+ + '"_generated_by": "python"'
71+ + "\n }"
7272 )
7373 return j
7474
@@ -78,7 +78,9 @@ def _create_floor(self) -> None:
7878 """
7979 self ._floor = Floor (my_globals .FLOOR_HEIGHT , my_globals .FLOOR_WIDTH , self ._seed )
8080
81- def _add_new_room (self , new_room_tuple : Tuple [int , int ], room_tuple_queue : deque ) -> bool :
81+ def _add_new_room (
82+ self , new_room_tuple : Tuple [int , int ], room_tuple_queue : deque
83+ ) -> bool :
8284 """
8385 Checks if a room can be added at the new position
8486 and if possible adds it to the queue and floor grid.
@@ -87,10 +89,12 @@ def _add_new_room(self, new_room_tuple: Tuple[int, int], room_tuple_queue: deque
8789 @return: True if the position was added to the queue otherwise False
8890 """
8991 if (
90- self ._floor .is_within_border (new_room_tuple )
91- and (not self ._floor .contains_room (new_room_tuple ))
92- and (self ._floor .count_neighbours (new_room_tuple [0 ], new_room_tuple [1 ]) <= 1 )
93- and util_functions .place_room ()
92+ self ._floor .is_within_border (new_room_tuple )
93+ and (not self ._floor .contains_room (new_room_tuple ))
94+ and (
95+ self ._floor .count_neighbours (new_room_tuple [0 ], new_room_tuple [1 ]) <= 1
96+ )
97+ and util_functions .place_room ()
9498 ):
9599 room_tuple_queue .append (new_room_tuple )
96100 self ._floor .add_to_floor_grid (* new_room_tuple )
@@ -155,8 +159,8 @@ def mark_dead_ends(self) -> list:
155159 for i in range (len (floor .get_rooms ())):
156160 room = floor .get_rooms ()[i ]
157161 if (
158- floor .is_dead_end (room [0 ], room [1 ])
159- and room .get_type () == RoomType .NORMAL_ROOM
162+ floor .is_dead_end (room [0 ], room [1 ])
163+ and room .get_type () == RoomType .NORMAL_ROOM
160164 ):
161165 room .set_type (RoomType .DEAD_END )
162166 dead_end_indices += (i ,)
@@ -205,9 +209,9 @@ def add_boss_room(self, dead_end_indices: list, start_room: tuple) -> None:
205209 direction , (boss_room_x , boss_room_y )
206210 )
207211 if (
208- self ._floor .is_within_border (new_boss_tuple )
209- and floor .count_neighbours (new_boss_tuple [0 ], new_boss_tuple [1 ]) == 1
210- and not self ._floor .contains_room (new_boss_tuple )
212+ self ._floor .is_within_border (new_boss_tuple )
213+ and floor .count_neighbours (new_boss_tuple [0 ], new_boss_tuple [1 ]) == 1
214+ and not self ._floor .contains_room (new_boss_tuple )
211215 ):
212216 possible_locations .append (direction )
213217
@@ -221,9 +225,9 @@ def add_boss_room(self, dead_end_indices: list, start_room: tuple) -> None:
221225 boss_room_placed = self ._place_big_boss_room (possible_locations , boss_room )
222226
223227 if (
224- not boss_room_placed
225- and len (possible_locations ) >= 1
226- and random .randint (0 , 10 ) < 5
228+ not boss_room_placed
229+ and len (possible_locations ) >= 1
230+ and random .randint (0 , 10 ) < 5
227231 ):
228232 # Create a 1 * 2 boss-room
229233 floor .add_room_next_to (boss_room , possible_locations [0 ], RoomType .BOSS_ROOM )
@@ -249,9 +253,9 @@ def _place_big_boss_room(self, possible_locations: List, boss_room: Room) -> boo
249253 direction [2 ], (boss_room [0 ], boss_room [1 ])
250254 )
251255 if (
252- direction [0 ] in possible_locations
253- and direction [1 ] in possible_locations
254- and self ._floor .has_no_neighbours (corner )
256+ direction [0 ] in possible_locations
257+ and direction [1 ] in possible_locations
258+ and self ._floor .has_no_neighbours (corner )
255259 ):
256260 self ._add_rooms_next_to_room (boss_room , direction )
257261 return True
@@ -272,17 +276,17 @@ def _place_boss_with_teleport_room(self, boss_room) -> None:
272276 boss_room .set_cord (0 , my_globals .FLOOR_HEIGHT - 1 )
273277
274278 elif self ._check_if_not_contains_room_and_has_no_neighbours (
275- floor .bottom_left ()
279+ floor .bottom_left ()
276280 ):
277281 boss_room .set_cord (my_globals .FLOOR_WIDTH - 1 , my_globals .FLOOR_HEIGHT - 1 )
278282
279283 elif self ._check_if_not_contains_room_and_has_no_neighbours (
280- floor .bottom_right ()
284+ floor .bottom_right ()
281285 ):
282286 boss_room .set_cord (my_globals .FLOOR_WIDTH - 1 , 0 )
283287
284288 def _check_if_not_contains_room_and_has_no_neighbours (
285- self , point : Tuple [int , int ]
289+ self , point : Tuple [int , int ]
286290 ) -> bool :
287291 floor = self ._floor
288292 return not floor .contains_room (
@@ -316,9 +320,12 @@ def place_super_secret_room(self) -> None:
316320 neighbour = util_functions .add_direction_to_coordinates (
317321 direction , (room [0 ], room [1 ])
318322 )
319- if (floor .is_within_border (neighbour ) and not floor .contains_room (neighbour )
320- and not floor .has_boos_room_as_neighbour (neighbour )
321- and floor .count_neighbours (neighbour [0 ],neighbour [1 ]) == 1 ):
323+ if (
324+ floor .is_within_border (neighbour )
325+ and not floor .contains_room (neighbour )
326+ and not floor .has_boos_room_as_neighbour (neighbour )
327+ and floor .count_neighbours (neighbour [0 ], neighbour [1 ]) == 1
328+ ):
322329 distance = util_functions .calculate_distance (boss_room , neighbour )
323330 if distance < distance_to_boss :
324331 distance_to_boss = distance
@@ -336,12 +343,16 @@ def place_secret_room(self) -> None:
336343 while not secret_room_placed :
337344 for room in reversed (floor .get_rooms ()):
338345 # Check all neighbours of the room
339- secret_room_placed = self ._check_directions_for_secret_room (room , neighbour_rooms )
346+ secret_room_placed = self ._check_directions_for_secret_room (
347+ room , neighbour_rooms
348+ )
340349 if secret_room_placed :
341350 break
342351 neighbour_rooms -= 1
343352
344- def _check_directions_for_secret_room (self , room : Room , neighbour_rooms : int ) -> bool :
353+ def _check_directions_for_secret_room (
354+ self , room : Room , neighbour_rooms : int
355+ ) -> bool :
345356 """
346357 Checks if a secret room can be placed next to a given room.
347358 @param room: room to check
@@ -358,7 +369,10 @@ def _check_directions_for_secret_room(self, room: Room, neighbour_rooms: int) ->
358369 if floor .has_special_room_as_neighbour (neighbour ):
359370 continue
360371 current_neighbour = floor .count_neighbours (neighbour [0 ], neighbour [1 ])
361- if current_neighbour >= neighbour_rooms and not floor .has_boos_room_as_neighbour (neighbour ):
372+ if (
373+ current_neighbour >= neighbour_rooms
374+ and not floor .has_boos_room_as_neighbour (neighbour )
375+ ):
362376 floor .add_room (neighbour [0 ], neighbour [1 ], RoomType .SECRET_ROOM )
363377 return True
364378 return False
0 commit comments