affichage des best score

This commit is contained in:
Raphaël 2024-01-06 19:02:47 +01:00
parent 4cbccef1f8
commit 8c6e5c55fa
3 changed files with 25 additions and 8 deletions

View file

@ -36,6 +36,13 @@ def __update(world: World):
entity[Text] = writing.base_text entity[Text] = writing.base_text
if key.startswith("["): # pavé numerique if key.startswith("["): # pavé numerique
key = key[1] key = key[1]
match key:
case "6":
key = "-"
case "8":
key = "_"
case _:
pass
if key in writing.accepted_chars and ( if key in writing.accepted_chars and (
entity[Text] == writing.base_text entity[Text] == writing.base_text
or len(entity[Text]) < writing.max_chars or len(entity[Text]) < writing.max_chars

View file

@ -18,12 +18,12 @@ import requests as rq
IP = "pong.cocosol.fr" IP = "pong.cocosol.fr"
def get_scores(): def get_scores() -> list[tuple[int, str]]:
try: try:
return rq.get(f"https://{IP}/data").json() return rq.get(f"https://{IP}/data").json()
except: except:
print("Error with the serveur") print("Error with the serveur")
return ["", 1] return [(1, "")]
def __create_button(world: World, i: int, name: str): 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( world.new_entity().set(
SpriteBundle( SpriteBundle(
f"button_{name}.png", f"button_{name}.png",
position=Vec2(450 + 540 * i, render.HEIGHT / 2), position=Vec2(450 + 540 * i, 11 * render.HEIGHT / 16),
order=1, order=1,
origin=Vec2(0.5), origin=Vec2(0.5),
), ),
@ -79,12 +79,22 @@ def __spawn_score(world: World):
""" """
Ajoute le score dans le monde. 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( world.new_entity().set(
TextBundle( TextBundle(
score[1] + " : " + str(score[0]), f"{name}",
position=Vec2(render.WIDTH / 2, 350 + 50 * i), position=Vec2(render.WIDTH / 2 - 350, 325 + 50 * i),
origin=Vec2(0.5), 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, order=1,
) )
) )

View file

@ -63,7 +63,7 @@ def __spawn_elements(world: World):
), ),
Writing( Writing(
"azertyuiopqsdfghjklmwxcvbn0123456789_-/", "azertyuiopqsdfghjklmwxcvbn0123456789_-/",
10, 16,
"...", "...",
), ),
) )