Ejemplo n.º 1
0
 def __init__(self, game):
     super().__init__(game=game, background_color=Palette.COLOR_9)
     title = Text(screen=self.game.screen, position=((self.x_middle),(40)), text='Criação do grafo', font_size=38, font_color=Palette.BLACK)
     back_button = Button(screen=self.game.screen, position=((self.game.WIDTH-120), (50)), on_press=lambda:game.change_screen(Menu), text='Voltar para o menu', color=Palette.RED)
     new_graph = Button(screen=self.game.screen, position=((self.x_middle-120), (self.game.HEIGHT-80)), on_press=self.create_new, text='Inserir novo grafo', color=Palette.BLUE)
     continue_button = Button(screen=self.game.screen, position=((self.x_middle+120), (self.game.HEIGHT-80)), on_press=self.play, text='Jogar Nível', color=Palette.RED)
     self.graph = Graph(game=self.game, graph=graph.Graph(self.graph_tam), editable=True, on_press=self.select_node)    
     self.line = Line(screen=self.game.screen, mouse_guide=True, visible=False)
     self.put_asset(title)
     self.put_asset(self.line)
     self.put_asset(back_button)
     self.put_asset(self.graph)
     self.put_asset(new_graph)
     self.put_asset(continue_button)
Ejemplo n.º 2
0
 def __init__(self, game):
     super().__init__(game=game, background_color=Palette.COLOR_1)
     #Assets
     info_icon = pygame.image.load('info.png')
     play_button = Button(screen=game.screen, position=((self.x_middle), (game.HEIGHT-200)),  on_press=self.game.start_game , text='Níveis padrões', width=300)
     info_button = Button(screen=game.screen, position=((70), (40)),  on_press=lambda:game.change_screen(Info), icon=info_icon, text='Info', width=120, color=Palette.COLOR_1)
     create_button = Button(screen=game.screen, position=((self.x_middle), (game.HEIGHT-100)),  on_press=lambda:game.change_screen(SelectTam), text='Níveis customizados', width=300, color=Palette.GREEN)
     title = Text(screen=self.game.screen, position=((self.x_middle),(100)), text=self.game.GAME_NAME, font_size=60)
     sub_title = Text(screen=self.game.screen, position=((self.x_middle),(180)), text=self.game.INTRO_TEXT, font_size=34, font_color=Palette.COLOR_5)
     self.put_asset(play_button)
     self.put_asset(info_button)
     self.put_asset(create_button)
     self.put_asset(title)
     self.put_asset(sub_title)
Ejemplo n.º 3
0
    def __init__(self, game):
        super().__init__(game=game, background_color=Palette.COLOR_9)

        title = Text(screen=self.game.screen,
                     position=((self.x_middle), (100)),
                     text='O jogo acabou',
                     font_size=60,
                     font_color=Palette.BLACK)
        sub_title = Text(screen=self.game.screen,
                         position=((self.x_middle), (180)),
                         text='Sua pontuação foi: ',
                         font_size=42,
                         font_color=Palette.BLACK)
        back_button = Button(
            screen=self.game.screen,
            position=((self.x_middle), (self.game.HEIGHT - 80)),
            on_press=lambda: self.game.change_screen(MenuScreen),
            text='Voltar para o menu',
            color=Palette.BLUE)

        self.correct_ans = Text(screen=self.game.screen,
                                position=((self.x_middle),
                                          (self.y_middle - 30)),
                                font_size=42,
                                font_color=Palette.GREEN)
        self.wrong_ans = Text(screen=self.game.screen,
                              position=((self.x_middle), (self.y_middle + 30)),
                              font_size=42,
                              font_color=Palette.RED)
        self.put_asset(title)
        self.put_asset(back_button)
        self.put_asset(sub_title)
        self.put_asset(self.correct_ans)
        self.put_asset(self.wrong_ans)
Ejemplo n.º 4
0
    def __init__(self, game):
        super().__init__(game=game, background_color=Palette.COLOR_9)

        # Assets
        back_button = Button(screen=self.game.screen,
                             position=((79), (40)),
                             on_press=lambda: game.change_screen(MenuScreen),
                             text='Voltar',
                             width=120)
        title = Text(screen=self.game.screen,
                     position=((self.x_middle), (40)),
                     text='A definir',
                     font_size=38,
                     font_color=Palette.BLACK)

        definition_text = open('definition.txt').read()
        definition = Text(screen=self.game.screen,
                          position=((self.x_middle), (self.y_middle)),
                          text=definition_text,
                          font_size=24,
                          font_type='robotoslab',
                          font_color=Palette.BLACK)

        self.put_asset(back_button)
        self.put_asset(title)
        self.put_asset(definition)
Ejemplo n.º 5
0
    def __init__(self, game):
        super().__init__(game=game, background_color=Palette.COLOR_9)

        #Assets
        quit_button = Button(screen=self.game.screen, position=((self.game.WIDTH-120), (50)), on_press=lambda:game.change_screen(Menu), text='Voltar para o menu', color=Palette.RED)
        next_button = Button(screen=self.game.screen, position=((self.x_middle), (self.game.HEIGHT-80)), on_press=self.game.next_question, text='Próxima pergunta', color=Palette.BLUE)
        self.correct_ans = Text(screen=self.game.screen, position=((220),(40)), font_size=28, font_color=Palette.GREEN)
        self.wrong_ans = Text(screen=self.game.screen, position=((220),(60)), font_size=28, font_color=Palette.RED)
        self.answer = Text(screen=self.game.screen, position=((self.x_middle),(60)), font_size=42)
        self.graph = Graph(game=self.game, reveal=True)

        self.put_asset(quit_button)
        self.put_asset(next_button)
        self.put_asset(self.correct_ans)
        self.put_asset(self.wrong_ans)
        self.put_asset(self.answer)
        self.put_asset(self.graph)
Ejemplo n.º 6
0
    def __init__(self, game):
        super().__init__(game=game, background_color=Palette.COLOR_1)
        # Assets
        title = Text(screen=self.game.screen,
                     position=((self.x_middle), (100)),
                     text=self.game.GAME_NAME,
                     font_size=60)
        sub_title = Text(screen=self.game.screen,
                         position=((self.x_middle), (180)),
                         text=self.game.INTRO_TEXT,
                         font_size=34,
                         font_color=Palette.COLOR_5)

        info_icon = pygame.image.load('info.png')
        info_button = Button(screen=self.game.screen,
                             position=((70), (40)),
                             on_press=lambda: game.change_screen(InfoScreen),
                             icon=info_icon,
                             text="Info",
                             width=120,
                             color=Palette.COLOR_1)

        play_button = Button(screen=game.screen,
                             position=((self.x_middle), (game.HEIGHT - 100)),
                             on_press=self.game.start_game,
                             text='Jogar',
                             width=300)
        self.img = Image(screen=game.screen,
                         height=game.HEIGHT,
                         width=game.WIDTH,
                         src='assets/back.jpg')
        self.put_asset(self.img)

        definition_text = open('definition.txt').read()
        definition = Text(screen=self.game.screen,
                          position=((self.x_middle), (self.y_middle - 150)),
                          text=definition_text,
                          font_size=24,
                          font_type='robotoslab',
                          font_color=Palette.WHITE)
        self.put_asset(definition)

        self.put_asset(title)
        self.put_asset(sub_title)
        #self.put_asset(info_button)
        self.put_asset(play_button)
Ejemplo n.º 7
0
 def __init__(self, game):
     super().__init__(game=game, background_color=Palette.COLOR_9)
     # Assets
     self.timer = Timer(surface=self.game.screen, color=Palette.GREEN , rect=(20, 20, 60, 60) , start_angle=0 , stop_angle=2*math.pi, width=30, on_finished=lambda:self.game.no_answer_question())
     yes_button = Button(screen=self.game.screen, position=((self.x_middle-120), (self.game.HEIGHT-80)), on_press=lambda:self.game.answer_question(True), text='Sim', color=Palette.BLUE)
     no_button = Button(screen=self.game.screen, position=((self.x_middle+120), (self.game.HEIGHT-80)), on_press=lambda:self.game.answer_question(False), text='Não', color=Palette.RED)
     question = Text(screen=self.game.screen, text='Esse grafo é bipartido?' ,position=((self.x_middle),(60)), font_size=30, font_color=Palette.COLOR_10)
     self.question_number = Text(screen=self.game.screen, position=((self.x_middle),(30)), font_size=30, font_color=Palette.COLOR_10)
     self.correct_ans = Text(screen=self.game.screen, position=((220),(40)), font_size=28, font_color=Palette.GREEN)
     self.wrong_ans = Text(screen=self.game.screen, position=((220),(60)), font_size=28, font_color=Palette.RED)
     self.graph = Graph(game=self.game, reveal=False)
     self.put_asset(self.timer)
     self.put_asset(yes_button)
     self.put_asset(no_button)
     self.put_asset(question)
     self.put_asset(self.question_number)
     self.put_asset(self.correct_ans)
     self.put_asset(self.wrong_ans)
     self.put_asset(self.graph)
Ejemplo n.º 8
0
 def __init__(self, game):
     super().__init__(game=game, background_color=Palette.COLOR_9)
     title = Text(screen=self.game.screen, position=((self.x_middle),(40)), text='Selecione o tamanho do grafo', font_size=38, font_color=Palette.BLACK)
     back_button = Button(screen=self.game.screen, position=((self.game.WIDTH-120), (50)), on_press=lambda:game.change_screen(Menu), text='Voltar para o menu', color=Palette.RED)
     b_1 = Button(screen=self.game.screen, position=((self.x_middle-150), (200)), on_press=lambda:self.select(1), text='1', color=Palette.BLUE)
     b_2 = Button(screen=self.game.screen, position=((self.x_middle-150), (300)), on_press=lambda:self.select(2), text='2', color=Palette.BLUE)
     b_3 = Button(screen=self.game.screen, position=((self.x_middle-150), (400)), on_press=lambda:self.select(3), text='3', color=Palette.BLUE)
     b_4 = Button(screen=self.game.screen, position=((self.x_middle-150), (500)), on_press=lambda:self.select(4), text='4', color=Palette.BLUE)
     b_5 = Button(screen=self.game.screen, position=((self.x_middle-150), (600)), on_press=lambda:self.select(5), text='5', color=Palette.BLUE)
     b_6 = Button(screen=self.game.screen, position=((self.x_middle+150), (200)), on_press=lambda:self.select(6), text='6', color=Palette.BLUE)
     b_7 = Button(screen=self.game.screen, position=((self.x_middle+150), (300)), on_press=lambda:self.select(7), text='7', color=Palette.BLUE)
     b_8 = Button(screen=self.game.screen, position=((self.x_middle+150), (400)), on_press=lambda:self.select(8), text='8', color=Palette.BLUE)
     b_9 = Button(screen=self.game.screen, position=((self.x_middle+150), (500)), on_press=lambda:self.select(9), text='9', color=Palette.BLUE)
     b_10 = Button(screen=self.game.screen, position=((self.x_middle+150), (600)), on_press=lambda:self.select(10), text='10', color=Palette.BLUE)
     self.put_asset(title)
     self.put_asset(back_button)
     self.put_asset(b_1)
     self.put_asset(b_2)
     self.put_asset(b_3)
     self.put_asset(b_4)
     self.put_asset(b_5)
     self.put_asset(b_6)
     self.put_asset(b_7)
     self.put_asset(b_8)
     self.put_asset(b_9)
     self.put_asset(b_10)
Ejemplo n.º 9
0
def end_screen(score):
    """ Display end screen including final score and high scores. """

    # Read in high scores from JSON
    try:
        with open((DIR_PATH / "scores" / "high_scores.json"), "r") as in_file:
            score_list = json.loads(in_file.read())

        # Add line for current game
        cur_date = datetime.date.today()
        cur_date_fmt = f"{cur_date.month}/{cur_date.day}/{cur_date.year}"
        score_list.append({
            "score": score,
            "difficulty": DIFFICULTY,
            "date": cur_date_fmt
        })

        # Update high scores JSON
        with open((DIR_PATH / "scores" / "high_scores.json"), "w") as out_file:
            json.dump(score_list, out_file, indent=4)

    # If error encountered, reset high scores file and try again
    except json.decoder.JSONDecodeError:
        with open((DIR_PATH / "scores" / "high_scores.json"), "w") as out_file:
            out_file.write("[]")
        end_screen(score)

    play_button = Button(mod(1300),
                         mod(20),
                         mod(425),
                         mod(80),
                         FONT_3,
                         "Play again",
                         callback_=intro_screen)

    # Show final score
    SCREEN.fill(BACKGROUND_BLUE)
    final_score_text = FONT_3.render(("Final Score: " + score), True,
                                     (0, 0, 0))
    SCREEN.blit(final_score_text, mod(100, 20))

    # Sort high scores
    score_list = sorted(score_list, key=lambda x: x["score"], reverse=True)

    # Show high scores
    for i, line in enumerate(score_list[:10]):
        core_text = FONT_3.render(line["score"], True, (0, 0, 0))
        diff_text = FONT_3.render(line["difficulty"], True, (0, 0, 0))
        date_text = FONT_3.render(line["date"], True, (0, 0, 0))
        SCREEN.blit(core_text, mod(100, 150 + (i * 80)))
        SCREEN.blit(diff_text, mod(700, 150 + (i * 80)))
        SCREEN.blit(date_text, mod(1300, 150 + (i * 80)))

    # End page loop
    while True:
        for event in pg.event.get():
            exit_check(event)

            play_button.handle_event(event, DIFFICULTY)

        play_button.draw(SCREEN)
        pg.display.flip()
Ejemplo n.º 10
0
def intro_screen():
    """ Show introduciton screen and acquire difficulty setting. """

    # Set up intro screen background
    into_bg = pg.image.load(str(DIR_PATH / "images" /
                                "start_screen_basic.png")).convert()
    into_bg = pg.transform.scale(into_bg, (WIDTH, HEIGHT))
    SCREEN.blit(into_bg, (0, 0))

    # Set up title
    title = FONT_1.render(GAMETITLE, True, GRAY)
    SCREEN.blit(title, mod(40, 21))

    pg.display.update()

    # Initalize buttons
    play_button = Button(mod(1580),
                         mod(150),
                         mod(250),
                         mod(105),
                         FONT_3,
                         "Play",
                         callback_=game_loop)
    easy_button = Button(mod(1250),
                         mod(70),
                         mod(180),
                         mod(60),
                         FONT_4,
                         "Easy",
                         toggle_=True)
    med_button = Button(mod(1450),
                        mod(70),
                        mod(180),
                        mod(60),
                        FONT_4,
                        "Medium",
                        toggle_=True)
    hard_button = Button(mod(1650),
                         mod(70),
                         mod(180),
                         mod(60),
                         FONT_4,
                         "Hard",
                         toggle_=True)
    buttons = [play_button, easy_button, med_button, hard_button]

    # Initalize difficulty
    global DIFFICULTY
    DIFFICULTY = "Medium"
    med_button.active = True

    # Intro page loop
    intro = True
    while intro:
        for event in pg.event.get():
            exit_check(event)

            # Allow quick play with return key
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    game_loop()

            # Check for difficulty change
            for button in buttons:
                glob_diff_ori = DIFFICULTY
                DIFFICULTY = button.handle_event(event, DIFFICULTY)
                if DIFFICULTY != glob_diff_ori:
                    inactivate_buttons([easy_button, med_button, hard_button])

        for button in buttons:
            button.draw(SCREEN)

        pg.display.flip()