ecs #58
|
@ -25,6 +25,8 @@ def __update(world: World):
|
||||||
for entity in world.query(Writing, Text):
|
for entity in world.query(Writing, Text):
|
||||||
text = entity[Text]
|
text = entity[Text]
|
||||||
for key in pressed:
|
for key in pressed:
|
||||||
|
if text.text == "...":
|
||||||
|
text.text = ""
|
||||||
if key == "backspace":
|
if key == "backspace":
|
||||||
text.text = text.text[:-1]
|
text.text = text.text[:-1]
|
||||||
if key.startswith("["): # pavé numerique
|
if key.startswith("["): # pavé numerique
|
||||||
|
|
|
@ -13,6 +13,7 @@ from plugins import render
|
||||||
from plugins import writing
|
from plugins import writing
|
||||||
from plugins.assets import Assets
|
from plugins.assets import Assets
|
||||||
from plugins.hover import HoveredTexture
|
from plugins.hover import HoveredTexture
|
||||||
|
from plugins.inputs import Pressed
|
||||||
from plugins.render import Sprite
|
from plugins.render import Sprite
|
||||||
from plugins.text import Text
|
from plugins.text import Text
|
||||||
from plugins.writing import Writing
|
from plugins.writing import Writing
|
||||||
|
@ -93,6 +94,7 @@ def __initialize_world(world: World):
|
||||||
PlayAgain(),
|
PlayAgain(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Assigne le nombre d'essai et la couleur du texte enf ocntion du mode de jeux
|
||||||
match world[GameMode]:
|
match world[GameMode]:
|
||||||
case GameMode.CLASSIC:
|
case GameMode.CLASSIC:
|
||||||
world.set(RemainingAttempts(7))
|
world.set(RemainingAttempts(7))
|
||||||
|
@ -104,14 +106,6 @@ def __initialize_world(world: World):
|
||||||
world.set(RemainingAttempts(10))
|
world.set(RemainingAttempts(10))
|
||||||
text_color = pygame.Color(133, 51, 25)
|
text_color = pygame.Color(133, 51, 25)
|
||||||
|
|
||||||
match world[GameMode]:
|
|
||||||
case GameMode.CLASSIC:
|
|
||||||
world.set(RemainingAttempts(7))
|
|
||||||
case GameMode.LIAR:
|
|
||||||
world.set(RemainingAttempts(15))
|
|
||||||
case GameMode.CHEATER:
|
|
||||||
world.set(RemainingAttempts(10))
|
|
||||||
|
|
||||||
world.new_entity().set(
|
world.new_entity().set(
|
||||||
Text(
|
Text(
|
||||||
f"Il reste : {world[RemainingAttempts]} essais",
|
f"Il reste : {world[RemainingAttempts]} essais",
|
||||||
|
@ -135,7 +129,7 @@ def __initialize_world(world: World):
|
||||||
|
|
||||||
world.new_entity().set(
|
world.new_entity().set(
|
||||||
Text(
|
Text(
|
||||||
"",
|
"...",
|
||||||
150,
|
150,
|
||||||
text_color,
|
text_color,
|
||||||
Vec2(render.WIDTH / 2, 650),
|
Vec2(render.WIDTH / 2, 650),
|
||||||
|
@ -145,6 +139,13 @@ def __initialize_world(world: World):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def __key_check(world: World):
|
||||||
|
pressed = world[Pressed]
|
||||||
|
for key in pressed:
|
||||||
|
if key == "return" or key == "enter":
|
||||||
|
__update(world)
|
||||||
|
|
||||||
|
|
||||||
def __update(world: World):
|
def __update(world: World):
|
||||||
# Gestion du pluriel pour le nombre d'essais restants
|
# Gestion du pluriel pour le nombre d'essais restants
|
||||||
pluriel = "s"
|
pluriel = "s"
|
||||||
|
@ -153,7 +154,10 @@ def __update(world: World):
|
||||||
else:
|
else:
|
||||||
pluriel = "s"
|
pluriel = "s"
|
||||||
lying = False
|
lying = False
|
||||||
|
|
||||||
|
# On verifie si le mode actuel est le mode tricheur
|
||||||
if world[GameMode] == GameMode.LIAR:
|
if world[GameMode] == GameMode.LIAR:
|
||||||
|
# On verifie si l'ordinateur triche a durant ce tour-ci
|
||||||
lie = random.randint(1, 4)
|
lie = random.randint(1, 4)
|
||||||
if lie == 4:
|
if lie == 4:
|
||||||
lying = True
|
lying = True
|
||||||
|
@ -172,27 +176,37 @@ def __update(world: World):
|
||||||
world.set(CurrentScene(CHEATER))
|
world.set(CurrentScene(CHEATER))
|
||||||
|
|
||||||
for entity in world.query(Text, Writing):
|
for entity in world.query(Text, Writing):
|
||||||
if entity[Text].text != "":
|
# On verifie si l'entrée est vide ou contient le texte par defaut
|
||||||
|
if entity[Text].text != "" and entity[Text].text != "...":
|
||||||
|
# On verifie si l'entrée est égale au nombre choisie
|
||||||
if int(entity[Text].text) == world[Number]:
|
if int(entity[Text].text) == world[Number]:
|
||||||
for response in world.query(Text, Response):
|
for response in world.query(Text, Response):
|
||||||
response[Text].text = "Gagné !"
|
response[Text].text = "Gagné !"
|
||||||
entity[Text].text = ""
|
entity[Text].text = ""
|
||||||
|
# Le jeu est finit et on ne peux plus ecrire
|
||||||
del world[IsRunning]
|
del world[IsRunning]
|
||||||
del entity[Writing]
|
del entity[Writing]
|
||||||
|
|
||||||
|
# On verifie si l'entrée est superieur au nombre choisie
|
||||||
elif int(entity[Text].text) > world[Number]:
|
elif int(entity[Text].text) > world[Number]:
|
||||||
|
# On verifie que l'ordinateur ne ment pas
|
||||||
if world[GameMode] != GameMode.LIAR or not lying:
|
if world[GameMode] != GameMode.LIAR or not lying:
|
||||||
for response in world.query(Text, Response):
|
for response in world.query(Text, Response):
|
||||||
response[Text].text = "Plus petit"
|
response[Text].text = "Plus petit"
|
||||||
|
# Sinon il dit l'invers
|
||||||
else:
|
else:
|
||||||
for response in world.query(Text, Response):
|
for response in world.query(Text, Response):
|
||||||
response[Text].text = "Plus grand"
|
response[Text].text = "Plus grand"
|
||||||
|
|
||||||
|
# Dans tout les cas
|
||||||
world[RemainingAttempts] -= 1
|
world[RemainingAttempts] -= 1
|
||||||
for attempts in world.query(Text, Attempts):
|
for attempts in world.query(Text, Attempts):
|
||||||
attempts[
|
attempts[
|
||||||
Text
|
Text
|
||||||
].text = f"Il reste : {world[RemainingAttempts]} essai{pluriel}"
|
].text = f"Il reste : {world[RemainingAttempts]} essai{pluriel}"
|
||||||
entity[Text].text = ""
|
entity[Text].text = "..."
|
||||||
|
|
||||||
|
# Dans tous les autre cas (quand c'est inferieur)
|
||||||
else:
|
else:
|
||||||
if world[GameMode] != GameMode.LIAR or not lying:
|
if world[GameMode] != GameMode.LIAR or not lying:
|
||||||
for response in world.query(Text, Response):
|
for response in world.query(Text, Response):
|
||||||
|
@ -206,15 +220,20 @@ def __update(world: World):
|
||||||
attempts[
|
attempts[
|
||||||
Text
|
Text
|
||||||
].text = f"Il reste : {world[RemainingAttempts]} essai{pluriel}"
|
].text = f"Il reste : {world[RemainingAttempts]} essai{pluriel}"
|
||||||
entity[Text].text = ""
|
entity[Text].text = "..."
|
||||||
else:
|
|
||||||
for response in world.query(Text, Response):
|
|
||||||
response[Text].text = "Veuillez entrer un nombre."
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Si l'entrée est vide ou avec le texte par defaut
|
||||||
|
for response in world.query(Text, Response):
|
||||||
|
response[Text].text = "Entrez un nombre !"
|
||||||
|
|
||||||
|
# On verifie si le joueur a encore des essais
|
||||||
if world[RemainingAttempts] == 0:
|
if world[RemainingAttempts] == 0:
|
||||||
for response in world.query(Text, Response):
|
for response in world.query(Text, Response):
|
||||||
response[Text].text = "Perdu !"
|
response[Text].text = "Perdu !"
|
||||||
|
# On affiche le nombre
|
||||||
entity[Text].text = f"Le nombre etait {world[Number]}"
|
entity[Text].text = f"Le nombre etait {world[Number]}"
|
||||||
|
# On change la texure du bouton valider en bouton rejouer
|
||||||
for play_again in world.query(PlayAgain):
|
for play_again in world.query(PlayAgain):
|
||||||
play_again[Sprite].texture = world[Assets].get_texture("play_again")
|
play_again[Sprite].texture = world[Assets].get_texture("play_again")
|
||||||
play_again[HoveredTexture].normal = world[Assets].get_texture(
|
play_again[HoveredTexture].normal = world[Assets].get_texture(
|
||||||
|
@ -223,25 +242,29 @@ def __update(world: World):
|
||||||
play_again[HoveredTexture].hovered = world[Assets].get_texture(
|
play_again[HoveredTexture].hovered = world[Assets].get_texture(
|
||||||
"play_again_hover"
|
"play_again_hover"
|
||||||
)
|
)
|
||||||
|
|
||||||
del entity[Writing]
|
del entity[Writing]
|
||||||
del world[IsRunning]
|
del world[IsRunning]
|
||||||
|
|
||||||
|
# On verifie le mode de jeu actuel est le mode trichuer
|
||||||
if world[GameMode] == GameMode.CHEATER:
|
if world[GameMode] == GameMode.CHEATER:
|
||||||
|
# on modifie le nombre en ajoutant un nombre de l'intervalle [-3, 3]
|
||||||
world[Number] += random.randint(-3, 3)
|
world[Number] += random.randint(-3, 3)
|
||||||
|
|
||||||
|
|
||||||
|
# Definit la Scene "par defaut" qui contient l'entireté des 3 modes en fonction de GameMode
|
||||||
__SCENE = (
|
__SCENE = (
|
||||||
Scene(
|
Scene(
|
||||||
[__initialize_world],
|
[__initialize_world],
|
||||||
[],
|
[__key_check],
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
+ writing.PLUGIN
|
+ writing.PLUGIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Crée le scene classique en fonction de la scene par defaut
|
||||||
CLASSIC = assets.loading_scene(
|
CLASSIC = assets.loading_scene(
|
||||||
Plugin(
|
Plugin(
|
||||||
|
# Modifie le GameMode en CLASSIC a l'initialisation de la scene
|
||||||
[lambda world: world.set(GameMode.CLASSIC)],
|
[lambda world: world.set(GameMode.CLASSIC)],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
|
|
|
@ -3,7 +3,7 @@ La scène du menu principal du jeu.
|
||||||
|
|
||||||
Dans cette scène nous pouvons choisir le mode de jeu.
|
Dans cette scène nous pouvons choisir le mode de jeu.
|
||||||
"""
|
"""
|
||||||
import basic_game
|
from scenes import basic_game
|
||||||
from engine import CurrentScene, Scene
|
from engine import CurrentScene, Scene
|
||||||
from engine.ecs import Entity, World
|
from engine.ecs import Entity, World
|
||||||
from engine.math import Vec2
|
from engine.math import Vec2
|
||||||
|
|
Loading…
Reference in a new issue