示例#1
0
    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))
示例#2
0
    def __init__(self, poketer, cpu_poketer):
        self.poketer = poketer
        self.cpu_poketer = cpu_poketer
        self.text = """Twitter-mood score! Your Poketer has a certain mood. You now have the opportunity to increase your Poketer's health
by searching for a city in Sweden where you think the inhabitants are in the same mood as your Poketer.
The residents' mood is based on what they tweet. The more emotional they are, the more they increase
your Poketer's health. Good luck!"""
        self.title = TextBox((0.5, 0.08),
                             20,
                             False,
                             WHITE,
                             self.text,
                             line_width=68)
        self.button_positions = [(0.3, 0.5), (0.7, 0.5), (0.3, 0.65),
                                 (0.7, 0.65), (0.3, 0.8), (0.7, 0.8)]
        self.city_buttons = []

        self.attitude_options = geocodes  # 8 st
        self.cities = list(self.attitude_options.keys())
        self.cities = self.cities[:-1]
        self.button_colors = [
            PASTEL_1, PASTEL_2, PASTEL_3, PASTEL_4, PASTEL_5, PASTEL_6,
            PASTEL_1
        ]
        for idx in range(len(self.button_positions)):
            self.city_button = Button(self.button_positions[idx], (0.3, 0.12),
                                      self.button_colors[idx],
                                      PASTEL_7,
                                      27,
                                      WHITE,
                                      self.cities[idx].capitalize(),
                                      frame=self.button_colors[idx + 1])
            self.city_buttons.append(self.city_button)

        self.cpu_city = random.choice(self.cities)
示例#3
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)
示例#4
0
class ChooseCityScreen(Screen):
    def __init__(self, poketer, cpu_poketer):
        self.poketer = poketer
        self.cpu_poketer = cpu_poketer
        self.text = """Twitter-mood score! Your Poketer has a certain mood. You now have the opportunity to increase your Poketer's health
by searching for a city in Sweden where you think the inhabitants are in the same mood as your Poketer.
The residents' mood is based on what they tweet. The more emotional they are, the more they increase
your Poketer's health. Good luck!"""
        self.title = TextBox((0.5, 0.08),
                             20,
                             False,
                             WHITE,
                             self.text,
                             line_width=68)
        self.button_positions = [(0.3, 0.5), (0.7, 0.5), (0.3, 0.65),
                                 (0.7, 0.65), (0.3, 0.8), (0.7, 0.8)]
        self.city_buttons = []

        self.attitude_options = geocodes  # 8 st
        self.cities = list(self.attitude_options.keys())
        self.cities = self.cities[:-1]
        self.button_colors = [
            PASTEL_1, PASTEL_2, PASTEL_3, PASTEL_4, PASTEL_5, PASTEL_6,
            PASTEL_1
        ]
        for idx in range(len(self.button_positions)):
            self.city_button = Button(self.button_positions[idx], (0.3, 0.12),
                                      self.button_colors[idx],
                                      PASTEL_7,
                                      27,
                                      WHITE,
                                      self.cities[idx].capitalize(),
                                      frame=self.button_colors[idx + 1])
            self.city_buttons.append(self.city_button)

        self.cpu_city = random.choice(self.cities)

    def handle_mouse_button(self, button):
        if button == 1:
            for idx, city_button in enumerate(self.city_buttons):
                if city_button.handle_mouse_button(button):
                    return MoodScoreScreen(self.cities[idx], self.poketer,
                                           self.cpu_city, self.cpu_poketer)
        return self

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

        for button in self.city_buttons:
            button.render(screen)
示例#5
0
    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")
示例#6
0
    def __init__(self, number_of_quiz_questions, quiz_categories,
                 return_screen_, poketer):
        self.poketer = poketer

        global return_screen
        return_screen = return_screen_
        music("media/music/quizz_music.mp3", 0.0)
        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="It's quiz time!")

        quiz_start_text = f"""You will now get to try your luck with {number_of_quiz_questions} tricky questions. If you get at least
{number_of_quiz_questions - 1} correct answers you win a health bonus. Which category do you choose?"""

        self.info_text = TextBox(rel_pos=(0.5, 0.25),
                                 font_name=FONT_ROBOTO,
                                 font_size=25,
                                 font_bold=False,
                                 color=WHITE,
                                 text=quiz_start_text,
                                 line_width=55)
        self.category_buttons = []
        self.button_positions = [(0.3, 0.6), (0.7, 0.6), (0.3, 0.8),
                                 (0.7, 0.8)]

        self.categories = list(quiz_categories.keys())
        for idx, category in enumerate(self.categories):
            quiz_button = Button(rel_pos=self.button_positions[idx],
                                 rel_size=(0.4, 0.2),
                                 color=QUIZ_TRANSP_GREEN,
                                 highlight=QUIZ_TRANSP_GREEN_HIGHL,
                                 font_size=22,
                                 font_color=WHITE,
                                 text=category)
            self.category_buttons.append(quiz_button)
示例#7
0
    def set_question(self):
        self.next_question_timeout = 0
        self.current_question += 1

        if self.current_question == self.number_of_quiz_questions + 1:
            return QuizFinishedScreen(self.num_of_correct_ans,
                                      self.number_of_quiz_questions,
                                      self.poketer)

        self.correct_answer_idx = self.answer_options[
            self.current_question - 1].index(
                self.correct_answers[self.current_question - 1])

        self.title = TextBox(
            rel_pos=(0.5, 0.1),
            font_name=FONT_ROBOTO,
            font_size=25,
            font_bold=False,
            color=WHITE,
            text=f"{self.category} - Question {self.current_question}")

        self.question_text = TextBox(
            rel_pos=(0.5, 0.25),
            font_name=FONT_ROBOTO,
            font_size=25,
            font_bold=False,
            color=WHITE,
            text=self.questions[self.current_question - 1],
            line_width=55)
        self.quiz_answer_buttons = []
        for idx, answer_option in enumerate(
                self.answer_options[self.current_question - 1]):
            quiz_button = Button(rel_pos=self.button_positions[idx],
                                 rel_size=(0.4, 0.2),
                                 color=QUIZ_TRANSP_GREEN,
                                 highlight=QUIZ_TRANSP_GREEN_HIGHL,
                                 font_size=22,
                                 font_color=WHITE,
                                 text=answer_option)
            self.quiz_answer_buttons.append(quiz_button)
        return self
示例#8
0
    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}")
示例#9
0
    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 = ""
示例#10
0
    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)
示例#11
0
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)
示例#12
0
    def __init__(self):

        self.poketer = Poketer(
            "Happy Hasse",
            'happy',
            'yellow',
            100,
            50,
            catchword="#YOLO",
            img_name="media/images/Green_monster_resized.png")
        self.cpu_poketer = Poketer("Aggressive Ada",
                                   'angry',
                                   'red',
                                   100,
                                   50,
                                   catchword="#FTW",
                                   img_name="media/images/Pink_dragon_01.png")
        self.attack_score = 10
        self.text = f"""Mood analysis! Choose a city and guess which mood is most prevalent among the inhabitants.
If you guess correctly, your Poketer will be rewarded with {self.attack_score} attack points. If you guess wrong, 
your Poketer will be punished and lose {self.attack_score} p in attack strength. Good luck!"""
        self.title = TextBox((0.5, 0.08),
                             20,
                             False,
                             WHITE,
                             self.text,
                             line_width=68)

        self.city_button_positions = [(0.2, 0.45), (0.5, 0.45), (0.8, 0.45),
                                      (0.2, 0.6), (0.5, 0.6), (0.8, 0.6)]
        self.city_buttons = []
        self.attitude_options = geocodes  # 8 st
        self.cities = list(self.attitude_options.keys())
        self.cities = self.cities[:-1]

        #self.button_colors = [PASTEL_1, PASTEL_2, PASTEL_3, PASTEL_4, PASTEL_5, PASTEL_6, PASTEL_1]

        self.button_colors = [
            BLUE_1, BLUE_2, BLUE_3, BLUE_4, BLUE_5, BLUE_6, BLUE_7
        ]

        # 254, 109, 115

        for idx in range(len(self.city_button_positions)):
            self.city_button = Button(self.city_button_positions[idx],
                                      (0.25, 0.12), (53, 90, 105, 150),
                                      (127, 180, 192, 200),
                                      27,
                                      WHITE,
                                      self.cities[idx].capitalize(),
                                      frame=(37, 50, 55))
            self.city_buttons.append(self.city_button)

        self.button_colors = [HAPPY, SAD, ANGRY, LOVING]
        self.frame_colors = [HAPPY_F, SAD_F, ANGRY_F, LOVING_F]
        self.mood_button_positions = [(0.146, 0.8), (0.382, 0.8), (0.618, 0.8),
                                      (0.854, 0.8)]
        self.mood_buttons = []
        self.mood_options = ["happy", "sad", "angry", "loving"]
        for idx in range(len(self.mood_button_positions)):
            self.mood_button = Button(self.mood_button_positions[idx],
                                      (0.18, 0.1),
                                      self.button_colors[idx],
                                      (188, 231, 132, 200),
                                      22,
                                      WHITE,
                                      self.mood_options[idx].capitalize(),
                                      frame=self.frame_colors[idx])
            self.mood_buttons.append(self.mood_button)

        self.cpu_city = random.choice(self.cities)
        self.cpu_mood = random.choice(self.mood_options)

        self.chosen_city = ""
        self.chosen_mood = ""
        self.city_is_chosen = False
        self.mood_is_chosen = False
示例#13
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)
示例#14
0
    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)
示例#15
0
class QuizScreen(Screen):
    def __init__(self, quiz_category, poketer):
        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 = None
        self.question_text = None
        self.quiz_answer_buttons = []
        self.current_question = 0

        self.number_of_quiz_questions = 5

        category, questions, correct_answers, answer_options = get_quiz(
            self.number_of_quiz_questions, quiz_category)
        self.category = category
        self.questions = questions
        self.correct_answers = correct_answers
        self.answer_options = answer_options
        self.correct_answer_idx = None
        self.num_of_correct_ans = 0
        self.button_positions = [(0.3, 0.6), (0.7, 0.6), (0.3, 0.8),
                                 (0.7, 0.8)]
        self.set_question()
        self.next_question_timeout = 0
        self.poketer = poketer

    def set_question(self):
        self.next_question_timeout = 0
        self.current_question += 1

        if self.current_question == self.number_of_quiz_questions + 1:
            return QuizFinishedScreen(self.num_of_correct_ans,
                                      self.number_of_quiz_questions,
                                      self.poketer)

        self.correct_answer_idx = self.answer_options[
            self.current_question - 1].index(
                self.correct_answers[self.current_question - 1])

        self.title = TextBox(
            rel_pos=(0.5, 0.1),
            font_name=FONT_ROBOTO,
            font_size=25,
            font_bold=False,
            color=WHITE,
            text=f"{self.category} - Question {self.current_question}")

        self.question_text = TextBox(
            rel_pos=(0.5, 0.25),
            font_name=FONT_ROBOTO,
            font_size=25,
            font_bold=False,
            color=WHITE,
            text=self.questions[self.current_question - 1],
            line_width=55)
        self.quiz_answer_buttons = []
        for idx, answer_option in enumerate(
                self.answer_options[self.current_question - 1]):
            quiz_button = Button(rel_pos=self.button_positions[idx],
                                 rel_size=(0.4, 0.2),
                                 color=QUIZ_TRANSP_GREEN,
                                 highlight=QUIZ_TRANSP_GREEN_HIGHL,
                                 font_size=22,
                                 font_color=WHITE,
                                 text=answer_option)
            self.quiz_answer_buttons.append(quiz_button)
        return self

    def handle_mouse_button(self, mouse_button):
        clicked_button_idx = None
        quiz_button = None
        for quiz_button in self.quiz_answer_buttons:
            if quiz_button.handle_mouse_button(mouse_button):
                clicked_button_idx = self.quiz_answer_buttons.index(
                    quiz_button)
                break

        if clicked_button_idx is not None:
            self.next_question_timeout = pygame.time.get_ticks()

            if clicked_button_idx == self.correct_answer_idx:
                quiz_button.color = QUIZ_TRANSP_GREEN_LIGHT
                self.num_of_correct_ans += 1
                sound("media/music/kids_cheering.mp3")
            else:
                quiz_button.color = QUIZ_TRANSP_RED
                self.quiz_answer_buttons[
                    self.correct_answer_idx].color = QUIZ_TRANSP_GREEN_LIGHT
                sound("media/music/dinosaur_growl.mp3")

            for quiz_button in self.quiz_answer_buttons:
                quiz_button.enabled = False

    def handle_timer(self):
        time_now = pygame.time.get_ticks()
        if time_now - self.next_question_timeout > 2000 and self.next_question_timeout != 0:
            return self.set_question()
        return self

    def render(self, screen):
        screen.fill(BLACK)
        screen.blit(self.background_image, (0, 0))
        self.title.render(screen)
        self.question_text.render(screen)
        for quiz_answer_button in self.quiz_answer_buttons:
            quiz_answer_button.render(screen)
示例#16
0
class QuizStartScreen(Screen):
    def __init__(self, number_of_quiz_questions, quiz_categories,
                 return_screen_, poketer):
        self.poketer = poketer

        global return_screen
        return_screen = return_screen_
        music("media/music/quizz_music.mp3", 0.0)
        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="It's quiz time!")

        quiz_start_text = f"""You will now get to try your luck with {number_of_quiz_questions} tricky questions. If you get at least
{number_of_quiz_questions - 1} correct answers you win a health bonus. Which category do you choose?"""

        self.info_text = TextBox(rel_pos=(0.5, 0.25),
                                 font_name=FONT_ROBOTO,
                                 font_size=25,
                                 font_bold=False,
                                 color=WHITE,
                                 text=quiz_start_text,
                                 line_width=55)
        self.category_buttons = []
        self.button_positions = [(0.3, 0.6), (0.7, 0.6), (0.3, 0.8),
                                 (0.7, 0.8)]

        self.categories = list(quiz_categories.keys())
        for idx, category in enumerate(self.categories):
            quiz_button = Button(rel_pos=self.button_positions[idx],
                                 rel_size=(0.4, 0.2),
                                 color=QUIZ_TRANSP_GREEN,
                                 highlight=QUIZ_TRANSP_GREEN_HIGHL,
                                 font_size=22,
                                 font_color=WHITE,
                                 text=category)
            self.category_buttons.append(quiz_button)

    def handle_mouse_button(self, mouse_button):
        clicked_button_idx = None

        for category_button in self.category_buttons:
            if category_button.handle_mouse_button(mouse_button):
                clicked_button_idx = self.category_buttons.index(
                    category_button)
                sound("media/music/cartoon_cymbal_hit.mp3")
                break

        if clicked_button_idx is not None:
            for category_button in self.category_buttons:
                category_button.enabled = False
            return QuizScreen(self.categories[clicked_button_idx],
                              self.poketer)

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

        for category_button in self.category_buttons:
            category_button.render(screen)
示例#17
0
class MoodAnalysisScreen(Screen):
    def __init__(self, city, mood, poketer, cpu_city, cpu_mood, cpu_poketer):
        self.city = city
        self.mood = mood
        self.poketer = poketer

        self.cpu_city = cpu_city
        self.cpu_mood = cpu_mood
        self.cpu_poketer = cpu_poketer

        self.p1_text = f"... Tweet, tweet! Calculates how {self.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)