示例#1
0
    def end_screen(self, won=False):
        kitty_panel = Panel(region=(12, 5, 36, 5), fgcolor='white', bgcolor='gray', border=True, shadow=True)
        kitty_panel.text = "You won!" if won else "You lost!"
        kitty_panel.text += ' Play again?'

        buttons = []

        yes_button = ContinueButton(self, region=(18, 8, 6, 1), fgcolor=pygame.Color(0, 100, 0), bgcolor='white')
        yes_button.text = ' yes'
        buttons.append(yes_button)

        no_button = ExitButton(self, region=(28, 8, 6, 1), fgcolor=pygame.Color(100, 0, 0), bgcolor='white')
        no_button.text = '  no'
        buttons.append(no_button)

        tweet_button = TweetButton(self, region=(38, 8, 6, 1), fgcolor=pygame.Color(0, 0, 255), bgcolor='white')
        tweet_button.text = 'tweet'
        if won:
            twitter_text = u"I didn't find the kitty [{0}]!".format(self.kitty.character)
        else:
            twitter_text = u"I found the kitty [{0}]!".format(self.kitty.character)
        twitter_text += " {sex} was {adjective}.".format(
            sex=self.kitty.sex.capitalize(),
            adjective=self.kitty.adjective,
        )
        twitter_intent_url = 'https://twitter.com/intent/tweet?text={text}&hashtags={hashtags}&url={url}'.format(
            text=urllib.quote(twitter_text.encode('utf8')),
            hashtags='dontfindthekitty',
            url='http://jameydeorio.com',
        )
        tweet_button.intent_url = twitter_intent_url
        buttons.append(tweet_button)

        while not self.exit_game_loop:
            self.clock.tick(Constants.FPS)

            self.window.setscreencolors(None, 'black', clear=True)
            self.window.fill(bgcolor=Constants.ZOO_BG_COLOR, region=(1, 1, Constants.ZOO_WIDTH - 2, Constants.ZOO_HEIGHT - 2))

            for event in pygame.event.get():
                if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_q):
                    sys.exit(0)

                if event.type == pygame.MOUSEBUTTONDOWN:
                    xpos, ypos = self.window.getcoordinatesatpixel(event.pos)
                    if 0 < xpos < Constants.ZOO_WIDTH and 0 < ypos < Constants.ZOO_HEIGHT:
                        for button in buttons:
                            if button.contains(xpos, ypos):
                                button.click()

            self.zoo_map.draw(self.window)
            self.message_panel.write_captures(self)

            kitty_panel.draw(self.window)

            for button in buttons:
                button.draw(self.window)

            self.zookeeper.draw(self.window, pygame.mouse.get_pos())
            self.window.update()
    def add_capture(self, game, creature):
        self.captures.insert(0, creature)

        tweet_button = TweetButton(
            game=game,
            intent_url=creature.get_twitter_intent_url(),
            region=(Constants.ZOO_WIDTH - 4, 0, 3, 1),  # ypos is calculated in write_captures
            fgcolor=pygame.Color(0, 150, 235),
            bgcolor=pygame.Color(225, 225, 225)
        )
        tweet_button.text = ' T'
        tweet_button.intent_url = creature.get_twitter_intent_url()
        self.buttons.insert(0, tweet_button)

        if len(self.captures) > Constants.MESSAGE_PANEL_HEIGHT:
            self.captures.pop()
            self.buttons.pop()