1 changed files with 234 additions and 0 deletions
@ -0,0 +1,234 @@ |
|||||
|
from tkinter import * |
||||
|
from random import randint |
||||
|
nb_raté=0 |
||||
|
moment_mort=2 |
||||
|
list_l_pendue=[] |
||||
|
lettre_à_supp=[] |
||||
|
lst_mot=[] |
||||
|
mot_aleatoire=42 |
||||
|
difficulté=4 |
||||
|
def mot_choisie(): |
||||
|
global list_l_pendue |
||||
|
global mot_tiret |
||||
|
global list_mot_pendue |
||||
|
global mot_affiche |
||||
|
global mot_aleatoire |
||||
|
global lst_mot |
||||
|
|
||||
|
list_mot_pendue=[] |
||||
|
mot_pendue= mot.get() |
||||
|
if len(lst_mot)!=0: |
||||
|
mot_pendue=mot_aleatoire |
||||
|
list_l_pendue=[] |
||||
|
mot_tiret=[] |
||||
|
for lettre_pendue in mot_pendue: |
||||
|
list_l_pendue.append(lettre_pendue) |
||||
|
mot_tiret.append("-") |
||||
|
list_mot_pendue.append(lettre_pendue) |
||||
|
|
||||
|
if len(list_l_pendue)>0: |
||||
|
débutant.config(state=NORMAL) |
||||
|
intermédiaire.config(state=NORMAL) |
||||
|
expert.config(state=NORMAL) |
||||
|
maître.config(state=NORMAL) |
||||
|
bouton_mot.config(state=DISABLED) |
||||
|
choix_mot.config(state=DISABLED,show="*") |
||||
|
mot_affiche=Label(pendue, text=mot_tiret).grid(row=3,column=1) |
||||
|
bouton_mot.config(state=DISABLED) |
||||
|
|
||||
|
def commencé(): |
||||
|
pendue_jeux(lettre.get()) |
||||
|
if sorted(list_l_pendue)==sorted(lettre_à_supp): |
||||
|
mot_affiche=Label(pendue, text="Vous avez gagnez le mot était "+str(mot.get())+mot_aleatoire).grid(row=3,column=1) |
||||
|
lettre_choix.config(state=DISABLED) |
||||
|
bouton_l.config(state=DISABLED) |
||||
|
elif moment_mort==0: |
||||
|
mot_affiche=Label(pendue, text="Vous êtes morts le mot était" +str(mot.get())+mot_aleatoire).grid(row=3,column=1) |
||||
|
lettre_choix.config(state=DISABLED) |
||||
|
bouton_l.config(state=DISABLED) |
||||
|
|
||||
|
def pendue_jeux(lettre_choisie): |
||||
|
global moment_mort |
||||
|
global difficulté |
||||
|
global list_l_pendue |
||||
|
global mot_tiret |
||||
|
global mot_affiche |
||||
|
global nb_raté |
||||
|
global lettre_à_supp |
||||
|
lettre_trouvé=[] |
||||
|
#recherche si la lettre est dans le mot |
||||
|
for i_lettre in range(len(list_l_pendue)): |
||||
|
if lettre_choisie==list_l_pendue[i_lettre].lower(): |
||||
|
lettre_à_supp.append(list_l_pendue[i_lettre]) |
||||
|
lettre_trouvé.append(list_l_pendue[i_lettre]) |
||||
|
|
||||
|
for i_changement in range(len(list_mot_pendue)): |
||||
|
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: |
||||
|
moment_mort=moment_mort-1 |
||||
|
if difficulté==1: |
||||
|
créer_échaffaud(1+nb_raté) |
||||
|
nb_raté=nb_raté+1 |
||||
|
Label(pendue, text="Tu as "+str(choix.get())+" vies").grid(row=8,column=1) |
||||
|
elif difficulté==2: |
||||
|
créer_échaffaud(2+nb_raté) |
||||
|
nb_raté=nb_raté+2 |
||||
|
Label(pendue, text="Tu as "+str(choix.get())+" vies").grid(row=8,column=1) |
||||
|
elif difficulté==3: |
||||
|
créer_échaffaud(4+nb_raté) |
||||
|
nb_raté=nb_raté+4 |
||||
|
bouton_mot =Label(pendue, text="Tu as "+str(choix.get())+" vies").grid(row=8,column=1) |
||||
|
elif difficulté==4: |
||||
|
créer_échaffaud(8+nb_raté) |
||||
|
nb_raté=nb_raté+8 |
||||
|
Label(pendue, text="Tu as "+str(choix.get())+" vies").grid(row=8,column=1) |
||||
|
|
||||
|
mot_affiche=Label(pendue, text=mot_tiret).grid(row=3,column=1) |
||||
|
|
||||
|
def créer_échaffaud(nb_tour): |
||||
|
for tour_fait in range(nb_tour): |
||||
|
if tour_fait==0: |
||||
|
c.create_rectangle(50,700,500+400,700+20,fill="#000000")#base |
||||
|
elif tour_fait==1: |
||||
|
c.create_rectangle(50,700,70,750,fill="#000000")#pied_g |
||||
|
elif tour_fait==2: |
||||
|
c.create_rectangle(880,700,900,750,fill="#000000")#pied_d |
||||
|
elif tour_fait==3: |
||||
|
c.create_rectangle(200,700,200+25,700-600,fill="#000000")#poutre |
||||
|
elif tour_fait==4: |
||||
|
c.create_line(208,200,300,110,fill="#000000", width=25)#pente |
||||
|
elif tour_fait==5: |
||||
|
c.create_rectangle(200,100,200+500,100+20,fill="#000000")#barre_parralèle |
||||
|
elif tour_fait==6: |
||||
|
c.create_rectangle(675,100,200+500,100+200,fill="#000000")#corde |
||||
|
elif tour_fait==7: |
||||
|
c.create_oval(650,300,200+525,375,fill="#ffffff")#tête |
||||
|
elif tour_fait==8: |
||||
|
c.create_rectangle(685,375,690,375+125,fill="#000000")#corps |
||||
|
elif tour_fait==9: |
||||
|
c.create_line(685,380,650,450,fill="#000000", width=5)#bras_g |
||||
|
elif tour_fait==10: |
||||
|
c.create_line(690,380,720,450,fill="#000000", width=5)#bras_d |
||||
|
elif tour_fait==11: |
||||
|
c.create_line(687,495,650,570,fill="#000000", width=5)#j_g |
||||
|
elif tour_fait==12: |
||||
|
c.create_line(687,495,720,570,fill="#000000", width=5)#j_d |
||||
|
elif tour_fait==13: |
||||
|
c.create_oval(655,325,100+580,350,fill="#ffffff")#eye_g |
||||
|
elif tour_fait==14: |
||||
|
c.create_oval(695,325,720,350,fill="#ffffff")#eye_d |
||||
|
elif tour_fait==15: |
||||
|
c.create_oval(675,355,700,360,fill="#ffffff")#bouche |
||||
|
|
||||
|
def choix_niveau(): |
||||
|
global moment_mort |
||||
|
global difficulté |
||||
|
moment_mort=choix.get() |
||||
|
Label(pendue, text="Tu as "+str(choix.get())+" vies").grid(row=8,column=1) |
||||
|
if moment_mort==16: |
||||
|
difficulté=1 |
||||
|
elif moment_mort==8: |
||||
|
difficulté=2 |
||||
|
elif moment_mort==4: |
||||
|
difficulté=3 |
||||
|
elif moment_mort==2: |
||||
|
difficulté=4 |
||||
|
débutant.config(state=DISABLED) |
||||
|
intermédiaire.config(state=DISABLED) |
||||
|
expert.config(state=DISABLED) |
||||
|
maître.config(state=DISABLED) |
||||
|
lettre_choix.config(state=NORMAL) |
||||
|
bouton_l.config(state=NORMAL) |
||||
|
|
||||
|
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"] |
||||
|
mot_aleatoire=lst_mot[randint(0,len(lst_mot)-1)] |
||||
|
mot_choisie() |
||||
|
|
||||
|
|
||||
|
|
||||
|
def ai_pendue(): |
||||
|
global moment_mort |
||||
|
global difficulté |
||||
|
lst_lettre=["azertyuiopqsdfghjklmwxcvbn"]*26 |
||||
|
while True: |
||||
|
moment_mort=8 |
||||
|
difficulté=2 |
||||
|
i=0 |
||||
|
aleatoire() |
||||
|
lst_lettre_tire=[] |
||||
|
|
||||
|
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) |
||||
|
i=i+1 |
||||
|
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] |
||||
|
|
||||
|
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""") |
||||
|
##lettre## |
||||
|
############################################### |
||||
|
lettre = StringVar() |
||||
|
|
||||
|
lettre_choix=Entry(textvariable=lettre, bd = 5, state=DISABLED) |
||||
|
lettre_choix.grid(row=1,column=1) |
||||
|
|
||||
|
bouton_l=Button(text="Confirme ta lettre",command=commencé,state=DISABLED) |
||||
|
bouton_l.grid(row=2,column=1) |
||||
|
|
||||
|
|
||||
|
|
||||
|
##niveau## |
||||
|
############################################### |
||||
|
choix=IntVar() |
||||
|
débutant=Radiobutton(text="Débutant",variable=choix,value=16,command=choix_niveau,state=DISABLED) |
||||
|
débutant.grid(row=4,column=1) |
||||
|
|
||||
|
intermédiaire=Radiobutton(text="Intermédiaire",variable=choix,value=8,command=choix_niveau,state=DISABLED) |
||||
|
intermédiaire.grid(row=5,column=1) |
||||
|
|
||||
|
expert=Radiobutton(text="Expert",variable=choix,value=4,command=choix_niveau,state=DISABLED) |
||||
|
expert.grid(row=6,column=1) |
||||
|
|
||||
|
maître=Radiobutton(text="Maître",variable=choix,value=2,command=choix_niveau,state=DISABLED) |
||||
|
maître.grid(row=7,column=1) |
||||
|
|
||||
|
solo=Button(text="Solo",command=aleatoire) |
||||
|
solo.grid(row=9,column=2) |
||||
|
##Mot## |
||||
|
############################################### |
||||
|
mot=StringVar() |
||||
|
choix_mot=Entry(textvariable=mot,bd=5) |
||||
|
choix_mot.grid(row=9,column=1) |
||||
|
bouton_mot=Button(text="choisi ton mot",command= mot_choisie) |
||||
|
bouton_mot.grid(row=10,column=1) |
||||
|
##Ia## |
||||
|
############################################## |
||||
|
lance_ia=Button(text="Lance l'ia",command= ai_pendue) |
||||
|
lance_ia.grid(row=9,column=3) |
||||
|
############################################## |
||||
|
pendue.mainloop() |
Loading…
Reference in new issue