def test_straight_horizontal(self): """ Test that straight horizontal corridor can be made """ edge_connection = Connection(connection=None, location=(10, 5), direction="left", section=self.section) room_connection = Connection(connection=None, location=(5, 5), direction="right", section=self.section) add_section_connection(self.section, edge_connection) add_room_connection(self.section, (5, 5), "right") generator = CorridorGenerator(start_point=edge_connection, end_point=room_connection, wall_tile=None, floor_tile=self.floor_rock) generator.generate() for x_loc in range(5, 11): assert_that(floor_tile(self.level, (x_loc, 5)), is_(equal_to(self.floor_rock)))
def test_bent_vertical(self): """ Test that horizontal corridor with bend can be made """ edge_connection = Connection(connection=None, location=(9, 0), direction="down", section=self.section) room_connection = Connection(connection=None, location=(2, 9), direction="up", section=self.section) add_section_connection(self.section, edge_connection) add_room_connection(self.section, (2, 9), "up") generator = CorridorGenerator(start_point=edge_connection, end_point=room_connection, wall_tile=None, floor_tile=self.floor_rock) generator.generate() assert_that(wall_tile(self.level, (9, 0)), is_(equal_to(None))) assert_that(wall_tile(self.level, (2, 9)), is_(equal_to(None))) assert_that(self.level, is_fully_accessible())
def test_straight_vertical(self): """ Test that straight vertical corridor can be made """ edge_connection = Connection(connection=None, location=(5, 0), direction="down", section=self.section) room_connection = Connection(connection=None, location=(5, 5), direction="up", section=self.section) add_section_connection(self.section, edge_connection) add_room_connection(self.section, (5, 5), "up") generator = CorridorGenerator(start_point=edge_connection, end_point=room_connection, wall_tile=None, floor_tile=self.floor_rock) generator.generate() for y_loc in range(0, 6): assert_that(floor_tile(self.level, (5, y_loc)), is_(equal_to(self.floor_rock)))
def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ middle_height = section_height(section) // 2 middle_width = section_width(section) // 2 if len([x for x in section_connections(section) if x.direction == 'right']) > 0: room_left_edge = self.rng.randint(2, middle_width - 2) else: room_left_edge = 1 if len([x for x in section_connections(section) if x.direction == 'left']) > 0: room_right_edge = self.rng.randint(middle_width + 2, section_width(section) - 2) else: room_right_edge = section_width(section) - 1 if len([x for x in section_connections(section) if x.direction == 'down']) > 0: room_top_edge = self.rng.randint(2, middle_height - 2) else: room_top_edge = 1 if len([x for x in section_connections(section) if x.direction == 'up']) > 0: room_bottom_edge = self.rng.randint(middle_height + 2, section_height(section) - 2) else: room_bottom_edge = section_height(section) - 1 for loc_y in range(room_top_edge + 1, room_bottom_edge): for loc_x in range(room_left_edge + 1, room_right_edge): section_floor(section, (loc_x, loc_y), self.floor_tile, 'room') section_wall(section, (loc_x, loc_y), self.empty_tile, None) center_x = (room_right_edge - room_left_edge) // 2 + room_left_edge center_y = (room_bottom_edge - room_top_edge) // 2 + room_top_edge add_room_connection(section, (center_x, room_top_edge), "up") add_room_connection(section, (center_x, room_bottom_edge), "down") add_room_connection(section, (room_left_edge, center_y), "left") add_room_connection(section, (room_right_edge, center_y), "right") self.add_corridors(section) self.room_corners = [] self.room_corners.append((room_left_edge + 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_bottom_edge - 1)) self.room_corners.append((room_left_edge + 1, room_bottom_edge - 1)) self.add_rows()
def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ middle_height = section_height(section) // 2 middle_width = section_width(section) // 2 if len([ x for x in section_connections(section) if x.direction == 'right' ]) > 0: room_left_edge = self.rng.randint(2, middle_width - 2) else: room_left_edge = 1 if len( [x for x in section_connections(section) if x.direction == 'left' ]) > 0: room_right_edge = self.rng.randint(middle_width + 2, section_width(section) - 2) else: room_right_edge = section_width(section) - 1 if len( [x for x in section_connections(section) if x.direction == 'down' ]) > 0: room_top_edge = self.rng.randint(2, middle_height - 2) else: room_top_edge = 1 if len([ x for x in section_connections(section) if x.direction == 'up' ]) > 0: room_bottom_edge = self.rng.randint(middle_height + 2, section_height(section) - 2) else: room_bottom_edge = section_height(section) - 1 for loc_y in range(room_top_edge + 1, room_bottom_edge): for loc_x in range(room_left_edge + 1, room_right_edge): section_floor(section, (loc_x, loc_y), self.floor_tile, 'room') section_wall(section, (loc_x, loc_y), self.empty_tile, None) center_x = (room_right_edge - room_left_edge) // 2 + room_left_edge center_y = (room_bottom_edge - room_top_edge) // 2 + room_top_edge add_room_connection(section, (center_x, room_top_edge), "up") add_room_connection(section, (center_x, room_bottom_edge), "down") add_room_connection(section, (room_left_edge, center_y), "left") add_room_connection(section, (room_right_edge, center_y), "right") self.add_corridors(section) self.room_corners = [] self.room_corners.append((room_left_edge + 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_bottom_edge - 1)) self.room_corners.append((room_left_edge + 1, room_bottom_edge - 1)) self.add_rows()