コード例 #1
0
class SentimentResultScreen(Screen):
    def __init__(self, keyword, attitude, result, poketer, return_screen):
        self.return_screen = return_screen
        self.poketer = poketer
        self.keyword = keyword
        self.attitude = attitude.lower()
        self.result = result
        if self.attitude == self.result:
            self.result_text = f"That was correct! {self.keyword} has mostly {self.result} content on Twitter. " \
                               f"You get a 10 p increase in attack strength as an award."
            self.poketer.attack += 10
        elif self.result == "too_few_results":
            self.result_text = f"Found too few tweets containing {keyword}. One tip is to search for something " \
                               f"that is more relevant in the public debate. "
        elif self.result == "connection_error":
            self.result_text = f"It is not possible to connect to Twitter right now. Try again later!"
        else:
            self.result_text = f"That was incorrect! {self.keyword} has mostly {self.result} content on Twitter. " \
                               f"You get a 10 p decrease in attack strength as a penalty."
            self.poketer.attack -= 10

        self.text = TextBox((0.5, 0.1),
                            22,
                            False,
                            WHITE,
                            self.result_text,
                            line_width=65)
        self.continue_button = Button(
            (0.5, 0.9), (0.2, 0.1), QUIZ_TRANSP_GREEN_HIGHL,
            QUIZ_TRANSP_GREEN_LIGHT, 20, WHITE, "CONTINUE")

        self.poketer_image = pygame.image.load(
            "media/images/Green_monster_resized.png").convert_alpha()
        self.poketer_image = pygame.transform.smoothscale(
            self.poketer_image, (207, 207))

    def handle_mouse_button(self, button):
        mx, my = pygame.mouse.get_pos()
        quit_button_rect = pygame.Rect(650, 30, 140, 40)
        if button == 1:
            if quit_button_rect.collidepoint((mx, my)):
                sys.exit()
            if self.continue_button.handle_mouse_button(button):
                if self.result == "too_few_results":
                    return SentimentAnalysisScreen(
                        self.poketer, return_screen=self.return_screen)
                return self.return_screen
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(background, (0, 0))
        self.text.render(screen)
        self.continue_button.render(screen)

        x_off, y_off = periodic_movement(1, 5)
        pixel_pos = rel_to_pix((0.5, 0.55))
        poketer_image_rect = self.poketer_image.get_rect()
        poketer_image_rect.center = pixel_pos[0], pixel_pos[1] + y_off
        screen.blit(self.poketer_image, poketer_image_rect)
コード例 #2
0
class SentimentGraphScreen(Screen):
    def __init__(self, keyword, attitude, poketer, return_screen):
        self.return_screen = return_screen
        self.poketer = poketer
        self.keyword = keyword
        self.attitude = attitude.lower()
        self.result = sentiment_analysis(keyword=self.keyword,
                                         language='english',
                                         file_name="",
                                         live=True)
        self.continue_button = Button(
            (0.5, 0.9), (0.2, 0.1), QUIZ_TRANSP_GREEN_HIGHL,
            QUIZ_TRANSP_GREEN_LIGHT, 20, WHITE, "CONTINUE")

        res = pygame.image.load("./twitter/sentiment_analysis.png")
        self.graph = pygame.transform.smoothscale(res, (800, 480))

    def handle_mouse_button(self, button):
        mx, my = pygame.mouse.get_pos()
        quit_button_rect = pygame.Rect(650, 30, 140, 40)
        if button == 1:
            if quit_button_rect.collidepoint((mx, my)):
                sys.exit()

            if self.continue_button.handle_mouse_button(button):
                self.continue_button.color = QUIZ_DARKGREEN
                return SentimentResultScreen(keyword=self.keyword,
                                             attitude=self.attitude,
                                             result=self.result,
                                             poketer=self.poketer,
                                             return_screen=self.return_screen)
        return self

    def handle_timer(self):
        if self.result == "too_few_results":
            return SentimentResultScreen(keyword=self.keyword,
                                         attitude=self.attitude,
                                         result=self.result,
                                         poketer=self.poketer,
                                         return_screen=self.return_screen)
        elif self.result == "connection_error":
            SentimentResultScreen(keyword=self.keyword,
                                  attitude=self.attitude,
                                  result=self.result,
                                  poketer=self.poketer,
                                  return_screen=self.return_screen)
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(self.graph, (0, 0))
        self.continue_button.render(screen)
コード例 #3
0
ファイル: intro_screens.py プロジェクト: stinisson/Poke-mood
class InstructionsScreen(Screen):
    def __init__(self):
        instructions_frame = pygame.image.load(
            "media/images/Frame_background.PNG")
        self.instructions_frame = pygame.transform.smoothscale(
            instructions_frame, (650, 450))
        self.back_button = Button((0.15, 0.92), (0.25, 0.1),
                                  PASTEL_3,
                                  PASTEL_6,
                                  27,
                                  WHITE,
                                  "Return",
                                  frame=PASTEL_4)

        self.quit_button = Button((0.85, 0.08), (0.25, 0.1),
                                  PASTEL_3,
                                  PASTEL_6,
                                  27,
                                  WHITE,
                                  "Quit",
                                  frame=PASTEL_4)

    def handle_mouse_button(self, button):
        if button == 1:
            if self.back_button.handle_mouse_button(button):
                return MenuScreen()
            if self.quit_button.handle_mouse_button(button):
                print("The End! :)")
                sys.exit()

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(start_background, (0, 0))
        screen.blit(self.instructions_frame, (75, 75))
        self.back_button.render(screen)
        self.quit_button.render(screen)
コード例 #4
0
ファイル: intro_screens.py プロジェクト: stinisson/Poke-mood
class FirstScreen(Screen):
    def __init__(self):
        music("media/music/intro_song_1.mp3", 0.0)
        self.gunnar = Poketer(
            "Happy Hasse",
            'happy',
            'yellow',
            100,
            50,
            catchword="#YOLO",
            img_name="media/images/Green_monster_resized.png")
        self.gunnar.image = pygame.transform.smoothscale(
            self.gunnar.image, (220, 220))

        self.ada = Poketer("Aggressive Ada",
                           'angry',
                           'red',
                           100,
                           50,
                           catchword="#FTW",
                           img_name="media/images/Pink_dragon_01.png")
        self.ada.image = pygame.transform.flip(self.ada.image, True, False)

        self.ada.image = pygame.transform.flip(self.ada.image, True, False)
        self.ada.image = pygame.transform.smoothscale(self.ada.image,
                                                      (225, 218))

        self.start_button = Button((0.5, 0.8), (0.3, 0.12),
                                   PASTEL_3,
                                   PASTEL_6,
                                   27,
                                   WHITE,
                                   "Let's begin!",
                                   frame=PASTEL_4)

    def handle_mouse_button(self, button):
        if button == 1:
            if self.start_button.handle_mouse_button(button):
                return MenuScreen()

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(start_background, (0, 0))
        screen.blit(logo, (215, -55))
        screen.blit(self.gunnar.image, (0, 200))
        screen.blit(self.ada.image, (580, 200))
        self.start_button.render(screen)
コード例 #5
0
ファイル: quiz.py プロジェクト: stinisson/Poke-mood
class QuizFinishedScreen(Screen):
    def __init__(self, num_of_correct_ans, number_of_quiz_questions, poketer):
        self.poketer = poketer
        pygame.mixer.music.stop()
        if num_of_correct_ans >= number_of_quiz_questions - 1:
            info_text = "WOW you're awesome! You get 10 health points as an award! "
            sound("media/music/kids_cheering.mp3")
            self.poketer.add_health(10)
        else:
            info_text = f"You need at least {number_of_quiz_questions - 1} correct answers to get a bonus. " \
                        f"Better luck next time!"
            sound("media/music/booing_crowd.mp3")

        background_image_raw = pygame.image.load(
            "media/images/Background_forest.jpg").convert()
        self.background_image = pygame.transform.scale(background_image_raw,
                                                       SCREEN_SIZE)

        self.title = TextBox(
            rel_pos=(0.5, 0.1),
            font_name=FONT_ROBOTO,
            font_size=30,
            font_bold=False,
            color=WHITE,
            text=
            f"You answered {num_of_correct_ans} out of {number_of_quiz_questions} questions correctly."
        )

        self.info_text = TextBox(rel_pos=(0.5, 0.25),
                                 font_name=FONT_ROBOTO,
                                 font_size=25,
                                 font_bold=False,
                                 color=WHITE,
                                 text=info_text,
                                 line_width=60)

        self.poketer_image = pygame.transform.smoothscale(
            self.poketer.image, (207, 207))

        self.quiz_finished_button = Button(rel_pos=(0.5, 0.85),
                                           rel_size=(0.3, 0.15),
                                           color=QUIZ_TRANSP_GREEN,
                                           highlight=QUIZ_TRANSP_GREEN_HIGHL,
                                           font_size=22,
                                           font_color=WHITE,
                                           text="CONTINUE")

    def handle_mouse_button(self, mouse_button):
        if self.quiz_finished_button.handle_mouse_button(mouse_button):
            music("media/music/battle_time_1.mp3", 0.0)
            return return_screen
        return self

    def render(self, screen):
        screen.fill(BLACK)
        screen.blit(self.background_image, (0, 0))
        self.title.render(screen)
        self.info_text.render(screen)

        x_off, y_off = periodic_movement(1, 5)
        pixel_pos = rel_to_pix((0.5, 0.55))
        poketer_image_rect = self.poketer_image.get_rect()
        poketer_image_rect.center = pixel_pos[0], pixel_pos[1] + y_off
        screen.blit(self.poketer_image, poketer_image_rect)
        self.quiz_finished_button.render(screen)
コード例 #6
0
ファイル: end_screens.py プロジェクト: stinisson/Poke-mood
class WinnerScreen(Screen):
    def __init__(self, gunnar, won):
        background_win = pygame.image.load("media/images/winning_pic.jpg")
        self.background_win = pygame.transform.smoothscale(
            background_win, SCREEN_SIZE)
        if won:
            music("media/music/vinnar_låt_utkast.mp3", 0.0)
        else:
            music("media/music/lose_game_melody.mp3", 0.0)

        self.quit_button = Button((0.85, 0.9), (0.2, 0.1),
                                  LIGHT_GREEN,
                                  LIGHT_PINK,
                                  22,
                                  WHITE,
                                  "QUIT",
                                  frame=YELLOW_LIGHT)
        self.gunnar = gunnar
        self.won = won

    def handle_mouse_button(self, button):
        if button == 1:
            if self.quit_button.handle_mouse_button(button):
                print("The End! :)")
                sys.exit()
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(self.background_win, (0, 0))

        if self.won:
            x_off, y_off = periodic_movement(1, 5)
            gunnar_bigger = pygame.transform.scale(self.gunnar.image,
                                                   (350, 350))
            screen.blit(gunnar_bigger, (220, 235 + y_off))
            winning_crown_hasse_moving(screen)
            pink_dragon_sad = pygame.image.load(
                "media/images/Pink_dragon_05.png")
            pink_dragon_sad = pygame.transform.scale(pink_dragon_sad,
                                                     (204, 235))
            screen.blit(pink_dragon_sad, (25, 340))
            tear_drop = pygame.image.load("media/images/tear-png-20.png")
            tear_drop = pygame.transform.scale(tear_drop, (25, 25))
            screen.blit(tear_drop, (120, 410))
            game_won = TextBox((0.5, 0.2), 35, False, YELLOW_LIGHT,
                               f"Congratulations, {self.gunnar.name} won!")
            game_won.render(screen)
        else:
            ada_win_pic = pygame.image.load("media/images/Pink_dragon_08.png")
            ada_win_pic = pygame.transform.scale(ada_win_pic, (350, 350))
            screen.blit(ada_win_pic, (205, 285))
            winning_crown_ada_moving(screen)
            gunnar_lose = pygame.transform.scale(self.gunnar.image, (200, 200))
            screen.blit(gunnar_lose, (25, 355))
            tear_drop = pygame.image.load("media/images/tear-png-20.png")
            tear_drop = pygame.transform.scale(tear_drop, (25, 25))
            screen.blit(tear_drop, (90, 430))
            game_lost = TextBox((0.5, 0.2), 35, False, PINK,
                                "Better luck next time!")
            game_lost.render(screen)

        screen.blit(logo, (213, -55))
        self.quit_button.render(screen)
コード例 #7
0
class SentimentAnalysisScreen(Screen):
    def __init__(self, poketer, return_screen):
        self.return_screen = return_screen
        self.poketer = poketer
        health_bonus = 10
        self.info_text = f"""Twitter betting! Do you know what's trending on social media?
Write a phrase you want to search Twitter for. Guess if the latest tweets that contain this phrase are mostly positive,
mostly negative or neutral. If your guess is correct, you will be rewarded with {health_bonus} p in increased health.
If your guess is wrong, you will be punished with {health_bonus} p in reduced health. Good luck!"""
        self.text = TextBox((0.5, 0.1),
                            22,
                            False,
                            WHITE,
                            self.info_text,
                            line_width=65)
        self.text_keyword = TextBox((0.5, 0.52),
                                    20,
                                    False,
                                    WHITE,
                                    "Enter a keyword:",
                                    line_width=65)

        self.input_field_keyword = InputBox((0.5, 0.6), (0.35, 0.1),
                                            QUIZ_TRANSP_GREEN_HIGHL,
                                            QUIZ_TRANSP_GREEN_HIGHL, 20, WHITE)

        self.button_positions = [(0.3, 0.75), (0.5, 0.75), (0.7, 0.75)]
        self.sentiment_buttons = []
        self.attitude_options = ["Positive", "Neutral", "Negative"]
        for idx in range(len(self.button_positions)):
            self.sentiment_button = Button(self.button_positions[idx],
                                           (0.2, 0.1), QUIZ_TRANSP_GREEN_HIGHL,
                                           QUIZ_TRANSP_GREEN_LIGHT, 20, WHITE,
                                           self.attitude_options[idx])
            self.sentiment_buttons.append(self.sentiment_button)
        self.continue_button = Button(
            (0.5, 0.9), (0.2, 0.1), QUIZ_TRANSP_GREEN_HIGHL,
            QUIZ_TRANSP_GREEN_LIGHT, 20, WHITE, "CONTINUE")
        self.chosen_sentiment = ""

    def handle_keydown(self, key):
        self.input_field_keyword.handle_keydown(key)
        return self

    def handle_mouse_button(self, button):
        mx, my = pygame.mouse.get_pos()
        quit_button_rect = pygame.Rect(650, 30, 140, 40)
        self.input_field_keyword.handle_mouse_button(button)
        if button == 1:
            if quit_button_rect.collidepoint((mx, my)):
                sys.exit()

            for idx, sentiment_button in enumerate(self.sentiment_buttons):
                if sentiment_button.handle_mouse_button(button):
                    sentiment_button.color = QUIZ_TRANSP_GREEN_LIGHT
                    self.chosen_sentiment = self.attitude_options[idx]
                    self.input_field_keyword.finished = True

                    # Disable buttons when a choice is made TODO UGLY TEMP FIX, FIX THIS!
                    for sentiment_button in self.sentiment_buttons:
                        sentiment_button.enabled = False

            if self.continue_button.handle_mouse_button(button):
                self.continue_button.color = QUIZ_TRANSP_GREEN_LIGHT
                return SentimentGraphScreen(
                    keyword=self.input_field_keyword.text,
                    attitude=self.chosen_sentiment,
                    poketer=self.poketer,
                    return_screen=self.return_screen)
        return self

    def handle_timer(self):
        self.input_field_keyword.handle_timer()
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(background, (0, 0))
        self.text.render(screen)
        self.text_keyword.render(screen)
        self.input_field_keyword.render(screen)
        for button in self.sentiment_buttons:
            button.render(screen)
        self.continue_button.render(screen)
コード例 #8
0
class MoodScoreScreen(Screen):
    def __init__(self, city, poketer, cpu_city, cpu_poketer):
        self.poketer = poketer
        self.cpu_poketer = cpu_poketer
        self.city = city
        self.cpu_city = cpu_city

        self.p1_text = f"... Tweet, tweet! Calculates how {self.poketer.mood} the inhabitants of {self.city.capitalize()} are ..."
        self.row1 = TextBox((0.5, 0.1),
                            28,
                            False,
                            WHITE,
                            self.p1_text,
                            line_width=45)

        # TODO HORRIBLE - FIX THIS!
        self.p1_moodscore = calc_mood_score(self.poketer.mood, self.city, True)
        if self.p1_moodscore is None:
            self.p1_moodscore = calc_mood_score(self.poketer.mood, self.city,
                                                False)
            self.p1_text2 = f"{poketer.name} got {self.p1_moodscore} p in increased health. {poketer.name} now has {poketer.health} in total health."
            self.poketer.add_health(self.p1_moodscore)
            if self.p1_moodscore is None:
                self.poketer.add_health(10)
                self.p1_text2 = f"Something went wrong, but {poketer.name} get 10 extra health points anyway. {poketer.name} now has {poketer.health} in total health."
        else:
            self.poketer.add_health(self.p1_moodscore)
            self.p1_text2 = f"{poketer.name} got {self.p1_moodscore} p in increased health. {poketer.name} now has {poketer.health} p in total health."
        self.row2 = TextBox((0.5, 0.3),
                            25,
                            False,
                            WHITE,
                            self.p1_text2,
                            line_width=45)

        self.line = TextBox((0.5, 0.48),
                            25,
                            False,
                            WHITE,
                            "* " * 35,
                            line_width=70)

        # TODO HORRIBLE - FIX THIS!
        self.p2_moodscore = calc_mood_score(self.cpu_poketer.mood,
                                            self.cpu_city, True)
        if self.p2_moodscore is None:
            self.p2_moodscore = calc_mood_score(self.cpu_poketer.mood,
                                                self.cpu_city, False)
            self.p2_text2 = f"Your opponent chose {cpu_city.capitalize()} and {cpu_poketer.name} got {self.p2_moodscore} p in increased health. {cpu_poketer.name} now has {cpu_poketer.health} p in total health."
            self.cpu_poketer.add_health(self.p2_moodscore)
            if self.p2_moodscore is None:
                self.cpu_poketer.add_health(10)
                self.p2_text2 = f"Something went wrong, but {cpu_poketer.name} get 10 extra health points anyway. {cpu_poketer.name} now has {cpu_poketer.health} p in total health."
        else:
            self.cpu_poketer.add_health(self.p2_moodscore)
            self.p2_text2 = f"Your opponent chose {cpu_city.capitalize()} and {cpu_poketer.name} got {self.p2_moodscore} p in increased health. {cpu_poketer.name} now has {cpu_poketer.health} p in total health."
        self.row3 = TextBox((0.5, 0.57),
                            25,
                            False,
                            WHITE,
                            self.p2_text2,
                            line_width=50)

        self.continue_button = Button((0.5, 0.85), (0.2, 0.1),
                                      PASTEL_3,
                                      PASTEL_6,
                                      22,
                                      WHITE,
                                      "Begin battle!",
                                      frame=PASTEL_4)

    def handle_mouse_button(self, button):
        if button == 1:
            if self.continue_button.handle_mouse_button(button):
                return BattleScreen(self.poketer, self.cpu_poketer)
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(background, (0, 0))
        self.row1.render(screen)
        self.row2.render(screen)
        self.line.render(screen)
        self.row3.render(screen)
        self.continue_button.render(screen)
コード例 #9
0
class PoketerIntroScreen(Screen):
    def __init__(self):
        self.gunnar = Poketer(
            "Happy Hasse",
            'happy',
            'yellow',
            100,
            50,
            catchword="#YOLO",
            img_name="media/images/Green_monster_resized.png")

        self.ada = Poketer("Aggressive Ada",
                           'angry',
                           'red',
                           100,
                           50,
                           catchword="#FTW",
                           img_name="media/images/Pink_dragon_01.png")
        self.ada.image = pygame.transform.flip(self.ada.image, True, False)

        self.continue_button = Button((0.5, 0.5), (0.2, 0.1),
                                      PURPLE_1,
                                      PURPLE_5,
                                      22,
                                      WHITE,
                                      "CONTINUE",
                                      frame=PURPLE_4)
        self.p1_text = "This is your Poketer Happy Hasse. Hasse thrives in merry environments with a lot of laughter and joy. " \
                       "He feeds on peoples' positive energy and cheerfulness. #YOLO"
        self.p2_text = "This is your opponent's Poketer Aggressvive Ada. She feels at home in hostile situations " \
                       "with a lot of swearing and controversy. #FTW"
        self.p1_pres = TextBox((0.35, 0.08),
                               22,
                               False,
                               WHITE,
                               self.p1_text,
                               line_width=35)
        self.p2_pres = TextBox((0.64, 0.62),
                               22,
                               False,
                               WHITE,
                               self.p2_text,
                               line_width=40)

        self.p1_stats = TextBox(
            (0.8, 0.48), 18, False, WHITE,
            f"Attack: {self.gunnar.attack} Health: {self.gunnar.health}")
        self.p2_stats = TextBox(
            (0.22, 0.92), 18, False, WHITE,
            f"Attack: {self.ada.attack} Health: {self.ada.health}")

    def handle_mouse_button(self, button):
        if button == 1:
            if self.continue_button.handle_mouse_button(button):
                self.ada.image = pygame.transform.flip(self.ada.image, True,
                                                       False)
                return ChooseCityScreen(self.gunnar, self.ada)
        return self

    def render(self, screen):
        screen.fill(WHITE)
        screen.blit(background, (0, 0))
        screen.blit(self.gunnar.image, (500, 0))
        screen.blit(self.ada.image, (20, 270))
        self.p1_pres.render(screen)
        self.p2_pres.render(screen)
        self.p1_stats.render(screen)
        self.p2_stats.render(screen)
        self.continue_button.render(screen)