示例#1
0
    def __init__(self, controller, difficulty):
        super().__init__(controller)
        self.clock = 900000
        self.clock_text = Text(self.get_clock_str(), self._font, (20, 20, 20))
        self.clock_text.rect.center = (400, 50)
        if difficulty == "Easy":
            self.tile_count = (10, 10)
            self.tile_offset = (220, 150)
        elif difficulty == "Medium":
            self.tile_count = (14, 14)
            self.tile_offset = (150, 100)
        elif difficulty == "Hard":
            self.tile_count = (20, 14)
            self.tile_offset = (40, 100)
        self.unrevealed = self.tile_count[0] * self.tile_count[1]
        back_rect = pygame.Rect(self.tile_offset,
                                (self.tile_count[0] * Tile.TILE_SIZE[0] + 1,
                                 self.tile_count[1] * Tile.TILE_SIZE[1] + 1))
        self.backdrop = GameObject(self.game_objects, back_rect)
        self.mine_count = self.unrevealed // 8
        self.original_mine_count = self.mine_count
        self.unmarked = Text("x" + str(self.mine_count), self._small_font)
        self.unmarked.rect.center = (600, 50)

        mine_icon = pygame.image.load(os.path.join('spritesheet', f'mine.png'))
        mine_icon = pygame_utils.aspect_scale(mine_icon, (25, 25))
        mine_icon = GameObject(self.game_objects, mine_icon.get_rect(),
                               mine_icon)
        mine_icon.rect.center = (550, 50)
        self.tiles = self.make_tiles()
        self.place_tiles()
        self.game_objects.add(self.backdrop, *self.tiles, self.clock_text,
                              self.unmarked, mine_icon)
        self.win_sound = pygame.mixer.Sound("sounds/ta da.wav")
        self.lose_sound = pygame.mixer.Sound("sounds/bomb.wav")
示例#2
0
    def __init__(self, controller, last_frame, win=False):
        super().__init__(controller)
        last_frame = GameObject(self.game_objects, last_frame.get_rect(),
                                last_frame)
        self.background.blit(last_frame)
        background_color = (240, 240, 240)
        padding = (5, 5, 5, 5)
        if win:
            title_str = "Congratulations!"
            title_color = (
                40,
                255,
                40,
            )
        else:
            title_str = "GAME OVER"
            title_color = (255, 40, 40)

        title = Text(title_str,
                     self._font,
                     title_color,
                     border=3,
                     background_color=background_color,
                     padding=padding)

        sub_str = "press ESC to quit"
        sub_str2 = "press any other key to try again..."

        sub1 = Text(sub_str,
                    self._small_font, (20, 20, 20),
                    border=3,
                    background_color=background_color,
                    padding=padding)
        sub2 = Text(sub_str2,
                    self._small_font, (20, 20, 20),
                    border=3,
                    background_color=background_color,
                    padding=padding)

        title.rect.center = (400, 200)
        sub1.rect.center = (400, 400)
        sub2.rect.center = (400, 500)
        self.title = title
        self.game_objects.add(title, sub1, sub2)