Merge pull request 'Mode menteur' (#45) from menteur into main

Reviewed-on: #45
This commit is contained in:
CoCo_Sol 2023-10-30 00:57:19 +00:00 committed by Gitea
commit c4fefba8a9
No known key found for this signature in database
12 changed files with 238 additions and 1 deletions

Binary file not shown.

Binary file not shown.

BIN
assets/krita/menteurbg.kra Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -4,13 +4,14 @@ Example de l'utilisation du moteur de jeu.
from engine import start_game
from scenes import directory_search, menu, classique
from scenes import classique, menteur, menu, directory_search
start_game(
{
"menu": menu.SCENE,
"classique": classique.SCENE,
"menteur": menteur.SCENE,
"histoire": directory_search.SCENE,
},
"menu",

236
src/scenes/menteur.py Normal file
View file

@ -0,0 +1,236 @@
"""
Définis la scène du jeu menteur, sans variante.
"""
from random import randint
from plugins import typing
from engine import (
Centered,
Clickable,
Color,
Display,
Entity,
Game,
HoveredTexture,
Keyboard,
Order,
Position,
Scene,
Sound,
Text,
TextSize,
Texture,
World,
)
class RandomNumber(int):
"""
La ressource qui est le nombre a deviner.
"""
class TextDialogue:
"""
Le component qui declare l'entitee Text qui affiche le plus petit ou le plus grand
"""
class NombreEssai(int):
"""
Le component qui declare le nombre d'essai
"""
class NombreEssaiText:
"""
Le component qui affiche le nombre d'essai
"""
class IsRunning:
"""
Le component qui indique si le jeu est en cours
"""
COLOR_TEXT = Color(59, 162, 0)
def __initialize_world(world: World):
"""
Initialise le monde du menu.
"""
# Fond d'ecran
world.create_entity(
Position(),
Order(0),
Texture("menteur/background.png"),
)
# Bouton valider/rejouer
world.create_entity(
Position(Display.WIDTH / 2, 880),
Order(1),
Centered(),
Texture("menteur/valider.png"),
HoveredTexture("menteur/valider_hover.png"),
Clickable(lambda world, _: _update(world)),
)
# Zone de saisie
world.create_entity(
Position(Display.WIDTH / 2, 750),
Order(2),
Centered(),
typing.Typing("1234567890"),
Text(""),
COLOR_TEXT,
TextSize(150),
)
# Text qui dit si ton nombre et trop grand ou trop petit
world.create_entity(
Position(Display.WIDTH / 2, 500),
Order(3),
Centered(),
TextDialogue(),
TextSize(150),
COLOR_TEXT,
Text("Devine le nombre..."),
)
# Text qui affiche le nombre d'essai
world.create_entity(
Position(Display.WIDTH - 750, 120),
Order(4),
TextSize(100),
NombreEssaiText(),
COLOR_TEXT,
Text("il reste : 15 essais"),
)
# Bouton pour revenir au menu
world.create_entity(
Order(11),
Position(100, 100),
Texture("menteur/arrow.png"),
Clickable(on_menu_button),
HoveredTexture("menteur/arrow_hover.png"),
)
# Les ressources.
world[NombreEssai] = NombreEssai(15)
world[RandomNumber] = RandomNumber(randint(0, 99))
world[IsRunning] = IsRunning()
def on_menu_button(world: World, entity: Entity):
"""
Fonction qui s'execute quand on clique sur un bouton.
"""
world[Game].change_scene("menu")
entity[Sound] = Sound("click")
def _update(world: World):
"""
Verifie si le nombre donné est le meme que celui que l'on a choisi.
Boucle du jeu.
"""
world.create_entity(Sound("menu_click.wav"))
# si le jeu s'est arrete.
if IsRunning not in world:
# on relance le jeu.
world[Game].change_scene("menteur")
for entity in world.query(typing.Typing, Text):
# One efface le nombre.
number: str = entity[Text]
entity[Text] = Text("")
# On gere le l'input de l'utilisateur.
for entity_text in world.query(TextDialogue):
if number == "": # si il a rien evoyé.
entity_text[Text] = Text("tu doit entrer un nombre !")
return
if world[RandomNumber] == int(number): # si il a trouve le nombre.
end_game(world, "Gagné")
return
elif world[NombreEssai] <= 1: # si il n'a plus d'essai.
end_game(world, "Perdu")
return
elif world[RandomNumber] > int(number): # si le nombre est trop petit.
lie = randint(1, 4)
if lie == 4:
entity_text[Text] = Text("Plus petit...")
else:
entity_text[Text] = Text("Plus grand...")
else: # si le nombre est trop grand.
lie = randint(1, 4)
if lie == 4:
entity_text[Text] = Text("Plus grand...")
else:
entity_text[Text] = Text("Plus petit...")
# on update l'affichage du nombre d'essai.
world[NombreEssai] = NombreEssai(world[NombreEssai] - 1)
for entity in world.query(NombreEssaiText):
entity[Text] = Text(
f"il reste : {world[NombreEssai]} essai{'s' if world[NombreEssai] != 1 else ''}"
)
def end_game(world: World, state: str):
"""
fonction applé quand le jeu est fini.
"""
del world[IsRunning] # le jeu est fini.
# On joue le son
if state == "Gagné":
world.create_entity(Sound("win_sound.wav"))
else:
world.create_entity(Sound("lose_sound.wav"))
# On affiche le message de fin.
for entity_text in world.query(TextDialogue):
entity_text[Text] = Text(f"{state} !")
# 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("menteur/play_again.png")
entity[HoveredTexture] = HoveredTexture("menteur/play_again_hover.png")
def _check_return(world: World):
"""
Verifie si la touche entrée est appuyée.
"""
keyboard = world[Keyboard]
if keyboard.is_key_pressed("return") or keyboard.is_key_pressed("enter"):
_update(world)
SCENE = (
Scene(
[__initialize_world],
[_check_return],
[],
)
+ typing.PLUGIN
)