Exemple #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)
Exemple #2
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))
Exemple #3
0
    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)
Exemple #4
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)
Exemple #5
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}")
Exemple #6
0
    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))
Exemple #7
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)
Exemple #8
0
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)
Exemple #9
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")
Exemple #10
0
    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
Exemple #11
0
    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 __init__(self, center=[460, 550], size=[800, 800]):
     self.center = np.array(center)
     self.size = np.array(size)
     self.cities = np.array([[-180, -200], [200, 50], [-200, 50], [0, 300],
                             [150, -150]])
     self.clicked_city = -1
     self.screen_update = False
     self.simulate = False
     self.simulation_speed_obj = [1]
     self.buttons = {
         "AddCity":
         Button(self.center + self.size / 2 * [-1, 1] + [100, 50],
                size=(200, 100),
                color=colors['Blue'],
                clicked_color=colors['DarkBlue'],
                text="Dodaj grad",
                action=self.addCity),
         "RemoveCity":
         Button(self.center + self.size / 2 * [-1, 1] + [300, 50],
                size=(200, 100),
                color=colors['Purple'],
                clicked_color=colors['DarkPurple'],
                text="Skloni grad",
                action=self.removeCity),
         "StartSimulation":
         ToggleButton(self.center + self.size / 2 + [-150, 50],
                      size=(300, 100),
                      color=colors['Green'],
                      clicked_color=colors['DarkRed'],
                      text="Simuliraj",
                      action=self.toggleSimulation,
                      action_arg=True,
                      alt_text="Zaustavi Simulaciju",
                      alt_action=self.toggleSimulation,
                      alt_action_arg=False),
         "SimSpeedSlider":
         Slider(self.simulation_speed_obj, (1, 10), (1500, 400),
                "Brzina simulacije")
     }
Exemple #13
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 = ""
Exemple #14
0
 def __init__(self):
     music("media/music/intro_song_1.mp3", 0.0)
     self.button_positions = [(0.5, 0.35), (0.5, 0.5), (0.5, 0.65),
                              (0.5, 0.8)]
     self.option_buttons = []
     self.attitude_options = [
         "Start game", "How to play", "Settings", "Quit"
     ]
     self.button_colors = [PASTEL_1, PASTEL_2, PASTEL_3, PASTEL_4, PASTEL_5]
     for idx in range(len(self.button_positions)):
         self.option_button = Button(self.button_positions[idx],
                                     (0.3, 0.12),
                                     self.button_colors[idx],
                                     PASTEL_6,
                                     27,
                                     WHITE,
                                     self.attitude_options[idx],
                                     frame=self.button_colors[idx + 1])
         self.option_buttons.append(self.option_button)
Exemple #15
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)
Exemple #16
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
Exemple #17
0
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)
Exemple #18
0
    'NNExplanation': {},
    'NNSim': {},
    'AntOptExplanation': {},
    'AntOptSim': {},
    'AntColOptExplanation': {},
    'AntColOptSim': {},
}

window_dim = np.array(window.get_size())

# Permanent Objects
perma_obj = {
    'QuitButton':
    Button(window_dim * [1, 0] + [-85, 50],
           size=(150, 80),
           text="Ugasi",
           text_size=40,
           action=quitProgram),
}
for screen in screens:
    screens[screen]['ObjectDict'] = perma_obj.copy()

# ----------------------------------------------------------------------------------------------------------------------
# Main Menu
screens['MainMenu']['ObjectDict'].update({
    'IntroductionButton':
    Button(window_dim / 2 + [-400, +200], (300, 100),
           color=colors['Yellow'],
           clicked_color=colors['DarkYellow'],
           text="Uvod",
           action=changeState,
Exemple #19
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)
Exemple #20
0
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)
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)
    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
Exemple #23
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)
Exemple #24
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)