Esempio n. 1
0
class Room:
    """A room, which has not yet been drawn.  Performs some light randomization
    of the room shape.
    """
    MINIMUM_SIZE = Size(5, 5)

    def __init__(self, region):
        self.region = region
        self.size = Size(
            random_normal_range(self.MINIMUM_SIZE.width, region.width),
            random_normal_range(self.MINIMUM_SIZE.height, region.height),
        )
        left = region.left + random.randint(0, region.width - self.size.width)
        top = region.top + random.randint(0, region.height - self.size.height)
        self.rect = Rectangle(Point(left, top), self.size)

    def draw_to_canvas(self, canvas):
        assert self.rect in canvas.rect

        for point in self.rect.iter_points():
            canvas.set_architecture(point, e.Floor)

        # Top and bottom
        for x in self.rect.range_width():
            canvas.set_architecture(Point(x, self.rect.top), Wall)
            canvas.set_architecture(Point(x, self.rect.bottom), Wall)

        # Left and right (will hit corners again, whatever)
        for y in self.rect.range_height():
            canvas.set_architecture(Point(self.rect.left, y), Wall)
            canvas.set_architecture(Point(self.rect.right, y), Wall)