From a232379ad4fee6ba090db2ac81c5a280a05becc9 Mon Sep 17 00:00:00 2001 From: "philippot.m" <> Date: Mon, 14 Jul 2025 23:25:07 +0200 Subject: [PATCH] =?UTF-8?q?Ia=20fonctionnement=20chang=C3=A9=20ajout=20des?= =?UTF-8?q?=20lettres=20quand=20elles=20sont=20dans=20le=20mot=20et=20reti?= =?UTF-8?q?re=20si=20non=20bug=20pour=20l'ajout=20et=20commentaire=20?= =?UTF-8?q?=C3=A0=20ajouter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pendue_que_j_ai_du_refaire_car_je_suis_con.py | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/Pendue_que_j_ai_du_refaire_car_je_suis_con.py b/Pendue_que_j_ai_du_refaire_car_je_suis_con.py index fc19901..c5b84bb 100644 --- a/Pendue_que_j_ai_du_refaire_car_je_suis_con.py +++ b/Pendue_que_j_ai_du_refaire_car_je_suis_con.py @@ -1,5 +1,6 @@ from tkinter import * from random import randint +import time nb_raté=0 moment_mort=2 list_l_pendue=[] @@ -56,9 +57,9 @@ def pendue_jeux(lettre_choisie): global nb_raté global lettre_à_supp lettre_trouvé=[] - #recherche si la lettre est dans le mot + #recherche si la lettre est dans le mot ou est passé for i_lettre in range(len(list_l_pendue)): - if lettre_choisie==list_l_pendue[i_lettre].lower(): + if lettre_choisie==list_l_pendue[i_lettre].lower() and not(lettre_choisie in lettre_à_supp): lettre_à_supp.append(list_l_pendue[i_lettre]) lettre_trouvé.append(list_l_pendue[i_lettre]) @@ -66,7 +67,7 @@ def pendue_jeux(lettre_choisie): if lettre_choisie==list_mot_pendue[i_changement].lower(): mot_tiret[i_changement]=list_mot_pendue[i_changement] #créer l'échaffaud - if len(lettre_trouvé) ==0: + if len(lettre_trouvé) ==0 : moment_mort=moment_mort-1 if difficulté==1: créer_échaffaud(1+nb_raté) @@ -145,8 +146,9 @@ def choix_niveau(): def aleatoire(): global mot_aleatoire global lst_mot - lst_mot=["chou","Nouveaux","Pologne","vortex","Emmanuel","Nicolas","mot","pet","chat","chate","zebre","arbre","Donald","canard","bonjour","cote", - "Mexique","France","pomme","Solene","Alabama","anticonstitutionnelement","alcool","jumeau","jumelle","bourré","intergouvernementalisation","Creuse","Elise","abricot","beau","desert","Alaska","jolie","Henry","marche"] + lst_mot=[#"chou","Nouveaux","Pologne","vortex","Emmanuel","Nicolas","mot","pet","chat","chate","zebre","arbre","Donald","canard","bonjour","cote", + #"Mexique","France","pomme","Solene","Alabama","anticonstitutionnelement","alcool","jumeau","jumelle","bourré", + "intergouvernementalisation"]#,"Creuse","Elise","abricot","beau","desert","Alaska","jolie","Henry","marche"] mot_aleatoire=lst_mot[randint(0,len(lst_mot)-1)] mot_choisie() @@ -155,41 +157,47 @@ def aleatoire(): def ai_pendue(): global moment_mort global difficulté + global lettre_à_supp lst_lettre=["azertyuiopqsdfghjklmwxcvbn"]*26 - while True: + i=0 + while i==0: moment_mort=8 difficulté=2 i=0 aleatoire() lst_lettre_tire=[] - + lettre_à_supp=[] while not(sorted(list_l_pendue)==sorted(lettre_à_supp) or moment_mort==0): lettre_choisie=lst_lettre[i][randint(0,len(lst_lettre[i])-1)] pendue_jeux(lettre_choisie) lst_lettre_tire.append(lettre_choisie) + for i_lettre in range(i+1): + print(lettre_choisie==list_l_pendue[i_lettre].lower() ,not(lettre_choisie in lettre_à_supp) ,lettre_choisie,lettre_à_supp) + if lettre_choisie==list_l_pendue[i_lettre].lower() and not(lettre_choisie in lettre_à_supp): + print("a") + lst_lettre[i]=lst_lettre[i] + lettre_choisie + break + elif not(lettre_choisie in lettre_à_supp)==True: + nb_l_reajouter=-1 + for i_lettre in range(0,len(lst_lettre[i])): + if lst_lettre[i][i_lettre] ==lettre_choisie: + nb_l_reajouter=nb_l_reajouter+1 + lst_lettre[i]=lst_lettre[i].replace(lst_lettre_tire[i],"") +lettre_choisie*nb_l_reajouter + if len(lst_lettre[i])==0: + lst_lettre[i]="azertyuiopqsdfghjklmwxcvbn" + break i=i+1 + + #print(lst_lettre) if sorted(list_l_pendue)==sorted(lettre_à_supp): - print("gg") - for i in range(0,len(lst_lettre_tire)): - lst_lettre[i]=lst_lettre[i] + lst_lettre_tire[i] + print("victoir",mot_aleatoire) - else: - for i_lst in range(0,len(lst_lettre_tire)): - - for i_lettre in range(0,len(lst_lettre[i_lst])): - nb_l_reajouter=-1 - if lst_lettre[i_lst][i_lettre] ==lst_lettre_tire[i_lst]: - nb_l_reajouter=nb_l_reajouter+1 - lst_lettre[i_lst]=lst_lettre[i_lst].replace(lst_lettre_tire[i_lst],"") +lst_lettre_tire[i_lst]*nb_l_reajouter - if len(lst_lettre[i_lst])==0: - lst_lettre[i_lst]="azertyuiopqsdfghjklmwxcvbn" - print(lst_lettre) ##prog principal ## ############################################### pendue= Tk() c = Canvas(width=1000,height=900,bg="white") c.grid(row=1,column=2,rowspan=8,columnspan=2) -pendue.title("""pendue""") +pendue.title("""Pendue""") ##lettre## ############################################### lettre = StringVar()