예제 #1
0
    def _paint(self):
        if self._show_label and self._label_dirty:
            self._font_surface = create_label(self.font_renderer, self.label, BLACK)

        if self._show_icon and self._icon_dirty:
            image_path = os.path.join("assets", self.icon_path)
            image_width, image_height = \
                (self.label_height - (self._padding * 2)), \
                (self.label_height - (self._padding * 2))
            self._icon_surface = pygame.image.load(image_path)
            self._icon_surface = pygame.transform.smoothscale(self._icon_surface, (image_width, image_height))
        else:
            image_width = 0

        if self._label_dirty or self._icon_dirty:
            display_width = self.get_width()
            display_height = self.get_height()
            display_surface = pygame.Surface(
                (display_width,
                 display_height)
            )
            display_surface.fill(BLACK)
            fill_gradient(
                display_surface,
                WHITE,
                GREY,
                rect=Rect(
                    1,
                    1,
                    display_width - 3,
                    display_height - 2),
                forward=self._fill_forward
            )

            if self._show_icon:
                display_surface.blit(self._icon_surface, (self._padding, self._padding))
            display_surface.blit(self._font_surface,
                                 (self._padding + image_width, self._padding)) if self._show_label else None

            self.image = display_surface
            self.set_rect(self._x, self._y, self.image.get_width(), self.image.get_height())
예제 #2
0
def reset_total():
    """
    Resets the label and updates it with the proper number of disks
    """
    total_disks.fill((0, 0, 0, 0))
    total_disks.blit(gamefont.create_label(font_renderer, "Total Disks {}".format(len(disk_sprites))), (0, 0))
예제 #3
0
window = width, height = 800, 600
screen = pygame.display.set_mode(window)
pygame.display.set_caption("Tower of Hanoi")

default_font, font_renderer = gamefont.init()

solve_button = GameButton(font_renderer, "Solve")
reset_button = GameButton(font_renderer, "Reset")
add_disk_button = GameButton(font_renderer, "Add Disk")
remove_disk_button = GameButton(font_renderer, "Remove Disk")

tower_a_disks = []
tower_b_disks = []
tower_c_disks = []
total_disks = gamefont.create_label(font_renderer, "Total Disks {}  ".format(0))

button_sprites = pygame.sprite.RenderPlain(
    solve_button,
    add_disk_button,
    remove_disk_button,
    reset_button)

tower_platform = pygame.sprite.Sprite()
tower_platform.image = pygame.Surface([700, 40])
tower_platform.rect = tower_platform.image.get_rect()
tower_platform.rect.x = 50
tower_platform.rect.y = 500
fill_gradient(tower_platform.image, GOLDENROD, DARK_GOLDENROD, None, False, False)

tower_size = tower_width, tower_height = [20, 350]