From af6d46200d370d6649239955a20a15dd8c72bda5 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sun, 29 Oct 2023 18:27:58 +0100 Subject: [PATCH] end game --- src/scenes/classique.py | 92 ++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/src/scenes/classique.py b/src/scenes/classique.py index 610bd46..d8bf0ba 100644 --- a/src/scenes/classique.py +++ b/src/scenes/classique.py @@ -7,6 +7,7 @@ from plugins import typing from engine import ( Centered, Clickable, + Color, Display, Game, HoveredTexture, @@ -45,12 +46,26 @@ class NombreEssaiText: """ +class IsRunning: + """ + Le component qui indique si le jeu est en cours + """ + + def __initialize_world(world: World): """ Initialise le monde du menu. """ + + # Fond d'ecran world.create_entity( - Position(Display.WIDTH / 2, 964), + Position(), + Order(0), + Texture("classique/background.png"), + ) + + world.create_entity( + Position(Display.WIDTH / 2, 900), Order(1), Centered(), Texture("classique/valider.png"), @@ -64,6 +79,7 @@ def __initialize_world(world: World): Centered(), typing.Typing("1234567890"), Text(""), + Color(61, 22, 58), TextSize(150), ) @@ -74,20 +90,31 @@ def __initialize_world(world: World): Centered(), TextDialogue(), TextSize(150), + Color(61, 22, 58), Text("Devine le nombre..."), ) # Text qui affiche le nombre d'essai world.create_entity( - Position(10, 10), + Position(Display.WIDTH - 700, 100), Order(4), TextSize(100), NombreEssaiText(), + Color(61, 22, 58), Text("il reste : 7 essais"), ) + world.create_entity( + Order(11), + Position(100, 100), + Texture("classique/arrow.png"), + Clickable(lambda world, _: world[Game].change_scene("menu")), + HoveredTexture("classique/arrow_hover.png"), + ) + world[NombreEssai] = NombreEssai(7) world[RandomNumber] = RandomNumber(random.randint(0, 99)) + world[IsRunning] = IsRunning() def check_number(world: World): @@ -95,25 +122,30 @@ def check_number(world: World): Verifie si le nombre donné est le meme que celui que l'on a choisi. """ + # si le jeu s'est arrete, on empeche de continuer. + if IsRunning not in world: + world[Game].change_scene("classique") + for entity in world.query(typing.Typing, Text): + # One efface le nombre. + number: str = entity[Text] + entity[Text] = Text("") + for entity_text in world.query(TextDialogue): - if world[NombreEssai] == 1: - entity_text[Text] = Text("Lose!") - create_end_buton(world, "lose") - return - number: str = entity[Text] if number == "": entity_text[Text] = Text("tu doit entrer un nombre !") - break + return if world[RandomNumber] == int(number): - create_end_buton(world, "win") + end_game(world, "Gagné") + return + elif world[NombreEssai] <= 1: + end_game(world, "Perdu") + print("Perdu") + return elif world[RandomNumber] > int(number): - entity_text[Text] = Text("Trop petit") + entity_text[Text] = Text("Plus grand...") else: - entity_text[Text] = Text("Trop grand") - - # One efface le nombre. - entity[Text] = Text("") + entity_text[Text] = Text("Plus petit...") # on update l'affichage du nombre d'essai. world[NombreEssai] = NombreEssai(world[NombreEssai] - 1) @@ -123,23 +155,33 @@ def check_number(world: World): ) -def create_end_buton(world: World, state: str): +def end_game(world: World, state: str): """ Create the end buton """ + del world[IsRunning] - # sup toutes les entitées - for entity in world.query(): - del entity + for entity_text in world.query(TextDialogue): + entity_text[Text] = Text(f"{state} !") - world.create_entity( - Order(3), - Texture(f"classique/{state}.png"), - Clickable(lambda world, _: world[Game].change_scene("menu")), - ) + # On empeche de pourvoir continuer le jeu. + for entity in world.query(typing.Typing, Text): + del entity[typing.Typing] + + if state == "Gagné": + for entity in world.query(NombreEssaiText): + entity[Text] = Text("") + else: + for entity in world.query(NombreEssaiText): + entity[Text] = Text(" plus d'essais") + + # on change la texture du button submit. + for entity in world.query(Clickable, Centered): + entity[Texture] = Texture("classique/play_again.png") + entity[HoveredTexture] = HoveredTexture("classique/play_again_hover.png") -def __check_return(world: World): +def _check_return(world: World): """ Verifie si la touche return est appuyée. """ @@ -151,7 +193,7 @@ def __check_return(world: World): SCENE = ( Scene( [__initialize_world], - [__check_return], + [_check_return], [], ) + typing.PLUGIN