diff --git a/src/scenes/send_to_server.py b/src/scenes/send_to_server.py index 088fe73..baf5eb3 100644 --- a/src/scenes/send_to_server.py +++ b/src/scenes/send_to_server.py @@ -1,3 +1,4 @@ +import os from plugins import writing from engine import CurrentScene, Plugin from engine.ecs import Entity, World @@ -21,6 +22,8 @@ def new_score(world: World, e: Entity): try: post = {"name": name[Text], "score": world[game.Player1Score]} rq.post(f"https://{IP}/new_score", post) + with open("username.txt", "w") as f: + f.write(name[Text]) world.set(CurrentScene(thanks.THANKS)) except Exception as error: print("Error with the serveur:", error) @@ -38,6 +41,14 @@ def __spawn_elements(world: World): Ajoute les éléments du menu dans le monde. """ + if os.path.exists("username.txt"): + with open("username.txt", "r") as f: + name = f.read() + post = {"name": name, "score": world[game.Player1Score]} + rq.post(f"https://{IP}/new_score", post) + world.set(CurrentScene(thanks.THANKS)) + return + world.new_entity().set(SpriteBundle("background.png", -5)) world.new_entity().set( TextBundle(