Example #1
0
    def draw_scores(self):
        # joueur 1
        if self.scores[1] > self.scores[2]:
            color = (125, 227, 61)
        else:
            color = (227, 81, 61)
        text(f"Score : {self.scores[1]}",
             self.big_font_2,
             self.surface, (80, self.surface_size[1] // 2 - 20),
             color=color,
             shadow=True,
             center_type="left")

        # joueur 2
        if self.scores[2] > self.scores[1]:
            color = (125, 227, 61)
        else:
            color = (227, 81, 61)

        text(f"Score : {self.scores[2]}",
             self.big_font_2,
             self.surface,
             (self.surface_size[0] - 80, self.surface_size[1] // 2 - 20),
             color=color,
             shadow=True,
             center_type="right")
Example #2
0
    def players_categorie_selection(
            self, player_nb, adj_num
    ):  # rendre fonctionnel l'écran des sélections de caractères
        text(f"Le {adj_num} joueur peut choisir son type de personnage.",
             self.medium_font_2,
             self.surface, (self.surface_size[0] // 2, 80),
             shadow=True,
             shadow_offset=2)
        buttons_size = (220, 70)
        button_y_pos = reset_button_y_pos = 200  # où sera le premier bouton (en y)
        button_x_pos = self.surface_size[0] // 2 - buttons_size[0] // 2 - 25
        for button_number in range(len(self.characters_categorie)):
            if button_number == (len(self.characters_categorie) + 1) // 2:
                button_y_pos = reset_button_y_pos
                button_x_pos = self.surface_size[0] // 2 + buttons_size[
                    0] // 2 + 25

            button_out = button(self.characters_categorie[button_number],
                                self.big_font,
                                self.surface,
                                pos=(button_x_pos, button_y_pos),
                                size=buttons_size,
                                user_click=self.user_click)

            # vérifier si l'utilisateur appuie sur le bouton
            if button_out[0] is not False:
                self.players_categorie[player_nb] = button_out[1]
                self.characters_categorie.remove(button_out[1])
                break
            # changer la position y
            button_y_pos += buttons_size[1] + 50
Example #3
0
 def make_wrong_guess(
         self):  # afficher un message et diminuer le score du joueur
     if self.timer["wrong"] > time.time():
         text("Faux! Essaye à nouveau",
              self.big_font_2,
              self.surface, (self.surface_size[0] // 2, 255),
              color=(209, 69, 59),
              shadow=True)
Example #4
0
    def draw_words(self):  # dessiner tous les mots triés par catégorie
        buttons_size = (262, 32)
        space = 10  # espace entre les boutons
        button_x_pos = buttons_size[0] // 2 + space
        button_y_pos = reset_button_y_pos = 350  # où sera le premier bouton (en y)

        to_return = None, None

        for words_group in ("Sujet", "Verbe", "Complément", "Liaison"):
            text(words_group,
                 self.medium_font_2,
                 self.surface, (button_x_pos, button_y_pos - 40),
                 color=(164, 61, 227),
                 shadow=True,
                 shadow_offset=2)  # dessiner le nom de la catégorie
            for word in self.sentences["all"][words_group]:
                if len(word) > 24:
                    split_number = 2
                else:
                    split_number = 1

                button_out = button(word,
                                    self.small_font,
                                    self.surface,
                                    pos=(button_x_pos, button_y_pos),
                                    size=buttons_size,
                                    user_click=self.user_click,
                                    split=split_number)

                if button_out[
                        0] is not False:  # lorsque l'utilisateur clique sur un bouton
                    to_return = (
                        words_group, button_out[1]
                    )  # renverra le groupe de mots et le texte du bouton

                button_y_pos += buttons_size[1] + space
            button_x_pos += buttons_size[0] + space
            button_y_pos = reset_button_y_pos

        return to_return
Example #5
0
    def draw_players_current_sentences(self):
        # joueur 1
        text_str = " ".join(self.sentences[1]["current"])
        text(f"{text_str}",
             self.small_font_2,
             self.surface, (248, 80),
             color=(244, 244, 244),
             center_type="left",
             split=self.surface_size[0] // 2,
             shadow=True,
             shadow_color=(22, 22, 22),
             shadow_offset=1)

        # joueur 2
        text_str = " ".join(self.sentences[2]["current"])
        text(f"{text_str}",
             self.small_font_2,
             self.surface, (self.surface_size[0] // 2 + 44, 80),
             color=(244, 244, 244),
             center_type="left",
             split=self.surface_size[0] // 2,
             shadow=True,
             shadow_color=(22, 22, 22),
             shadow_offset=1)
Example #6
0
start = [(0, 0) for x in range(10)]
state = [False for x in range(10)]
position = [(0,0) for x in range(10)]

while True:
    for touch in ts.poll():
        position[touch.slot] = (touch.x, touch.y)
        if state[touch.slot] != touch.valid:
            if touch.valid:
                print("{} pressed!".format(touch.slot))
                start[touch.slot] = (touch.x, touch.y)
            else:
                print("{} released!".format(touch.slot))
            state[touch.slot] = touch.valid

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()

    for x in range(10):
        if state[x]:
            pygame.draw.line(screen, col[x], start[x], position[x])
            start[x] = position[x]

    text(screen, "Hit ESC to exit!", (400, 460), 30, (255, 0, 0))  

    pygame.display.flip()

    time.sleep(0.001)
        x, y = touch.position

        if x < touch_zone:
            player_one.paddle(y)
        elif x > width - touch_zone:
            player_two.paddle(y)

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()

    screen.fill((0, 0, 0))

    text(screen, "Hit ESC to exit!", (400, 460), 30, (255, 0, 0))

    pygame.draw.rect(screen, (64, 64, 64),
                     (((width / 2) - 2, 40), (4, height - 80)), 0)

    text(screen, "{0:02d}".format(player_one.score), (50, 50), 30,
         (255, 255, 255))
    text(screen, "{0:02d}".format(player_two.score), (width - 50, 50), 30,
         (255, 255, 255))

    player_one.update()
    player_two.update()
    ball.update(time_delta, player_one, player_two)

    ball.render(screen)
    player_one.render(screen)
Example #8
0
def test_title(s, x=30, y=10, w=6, h=2):
    title = ''
    for i in range(1, 8):
        title += str(i)
        gui.text(s, x, y - 1 + (h + 1) * (i - 1), color='black')
        gui.textbox('', x, y + (h + 1) * (i - 1), w, h, title=title)
Example #9
0
        x, y = touch.position

        if x < touch_zone:
            player_one.paddle(y)
        elif x > width - touch_zone:
            player_two.paddle(y)

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()

    screen.fill((0, 0, 0))

    text(screen, "Hit ESC to exit!", (400, 460), 30, (255, 0, 0))

    pygame.draw.rect(screen, (64, 64, 64), (((width / 2) - 2, 40), (4, height - 80)), 0)

    text(screen, "{0:02d}".format(player_one.score), (50, 50), 30, (255, 255, 255))
    text(screen, "{0:02d}".format(player_two.score), (width - 50, 50), 30, (255, 255, 255))

    player_one.update()
    player_two.update()
    ball.update(time_delta, player_one, player_two)

    ball.render(screen)
    player_one.render(screen)
    player_two.render(screen)

    pygame.display.flip()
Example #10
0
state = [False for x in range(10)]
position = [(0, 0) for x in range(10)]

while True:
    for touch in ts.poll():
        position[touch.slot] = (touch.x, touch.y)
        if state[touch.slot] != touch.valid:
            if touch.valid:
                print("{} pressed!".format(touch.slot))
                start[touch.slot] = (touch.x, touch.y)
            else:
                print("{} released!".format(touch.slot))
            state[touch.slot] = touch.valid

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()

    screen.fill((0, 0, 0))

    for x in range(10):
        if state[x]:
            pygame.draw.line(screen, (0, 0, 255), start[x], position[x])

    text(screen, "Hit ESC to exit!", (400, 460), 30, (255, 0, 0))

    pygame.display.flip()

    time.sleep(0.001)