From 8c6e5c55fa993ab8f52cd8d72faec37999b7c6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 6 Jan 2024 19:02:47 +0100 Subject: [PATCH] affichage des best score --- src/plugins/writing.py | 7 +++++++ src/scenes/menu.py | 24 +++++++++++++++++------- src/scenes/send_to_server.py | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/plugins/writing.py b/src/plugins/writing.py index 982193a..0be2540 100644 --- a/src/plugins/writing.py +++ b/src/plugins/writing.py @@ -36,6 +36,13 @@ def __update(world: World): entity[Text] = writing.base_text if key.startswith("["): # pavé numerique key = key[1] + match key: + case "6": + key = "-" + case "8": + key = "_" + case _: + pass if key in writing.accepted_chars and ( entity[Text] == writing.base_text or len(entity[Text]) < writing.max_chars diff --git a/src/scenes/menu.py b/src/scenes/menu.py index 35bfff6..0c88bd3 100644 --- a/src/scenes/menu.py +++ b/src/scenes/menu.py @@ -18,12 +18,12 @@ import requests as rq IP = "pong.cocosol.fr" -def get_scores(): +def get_scores() -> list[tuple[int, str]]: try: return rq.get(f"https://{IP}/data").json() except: print("Error with the serveur") - return ["", 1] + return [(1, "")] def __create_button(world: World, i: int, name: str): @@ -33,7 +33,7 @@ def __create_button(world: World, i: int, name: str): world.new_entity().set( SpriteBundle( f"button_{name}.png", - position=Vec2(450 + 540 * i, render.HEIGHT / 2), + position=Vec2(450 + 540 * i, 11 * render.HEIGHT / 16), order=1, origin=Vec2(0.5), ), @@ -79,12 +79,22 @@ def __spawn_score(world: World): """ Ajoute le score dans le monde. """ - for i, score in enumerate(get_scores()): + print(get_scores()) + for i, (score, name) in enumerate(get_scores()): world.new_entity().set( TextBundle( - score[1] + " : " + str(score[0]), - position=Vec2(render.WIDTH / 2, 350 + 50 * i), - origin=Vec2(0.5), + f"{name}", + position=Vec2(render.WIDTH / 2 - 350, 325 + 50 * i), + origin=Vec2(0), + order=1, + ) + ) + + world.new_entity().set( + TextBundle( + f"{score}", + position=Vec2(render.WIDTH / 2 + 350, 325 + 50 * i), + origin=Vec2(1, 0), order=1, ) ) diff --git a/src/scenes/send_to_server.py b/src/scenes/send_to_server.py index c0868cb..1929537 100644 --- a/src/scenes/send_to_server.py +++ b/src/scenes/send_to_server.py @@ -63,7 +63,7 @@ def __spawn_elements(world: World): ), Writing( "azertyuiopqsdfghjklmwxcvbn0123456789_-/", - 10, + 16, "...", ), )