Demande sur une amélioration du programme python (jeu du pendu)
Creeprogramme
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
Je voudrais savoir il est possible de mettre un fonctionnalité dans mon programme python
from tkinter import *
from random import choice
fichier = open("liste_mots.txt", "r")
liste_mots = fichier.readlines()
fichier.close()
def lettre_dans_mot(lettre) :
global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
if partie_en_cours :
nouveau_mot_partiel = ""
lettre_dans_mot = False
i=0
while i<len(mot_choisi):
if mot_choisi[i]==lettre:
nouveau_mot_partiel = nouveau_mot_partiel + lettre
lettre_dans_mot = True
else:
nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
i+=1
mot_partiel = nouveau_mot_partiel
afficher_mot(mot_partiel)
if not lettre_dans_mot :
nb_echecs += 1
nomFichier = "pendu_"+str(nb_echecs)+".gif"
photo=PhotoImage(file=nomFichier)
image_pendu.config(image=photo)
image_pendu.image=photo
if nb_echecs == 7:
partie_en_cours = False
afficher_mot(mot_choisi)
elif mot_partiel == mot_choisi:
partie_en_cours = False
def afficher_mot(mot):
global lettres
mot_large = ""
i=0
while i<len(mot):
mot_large = mot_large + mot[i] + " "
i+=1
canevas.delete(lettres)
lettres = canevas.create_text(320,60,text=mot_large,fill='blue',font='Chiller 30')
def init_jeu():
global mot_choisi, mot_partiel, image_pendu, lettres
global nb_echecs, partie_en_cours, liste_mots
nb_echecs = 0
partie_en_cours = True
mot_choisi = choice(liste_mots).rstrip()
mot_choisi = mot_choisi.upper()
mot_partiel = "-" * len(mot_choisi)
afficher_mot(mot_partiel)
photo=PhotoImage(file="pendu_0.gif")
image_pendu.config(image=photo)
image_pendu.image=photo
fenetre = Tk()
fenetre.title("Le jeu du pendu[sur MC]")
canevas = Canvas(fenetre, bg='white', height=500, width=620)
canevas.pack(side=BOTTOM)
bouton = [0]*26
for i in range(26):
bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
bouton[i].pack(side=LEFT)
bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
bouton2.pack(side=RIGHT)
bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
bouton1.pack(side=RIGHT)
photo=PhotoImage(file="pendu_0.gif")
image_pendu = Label(canevas, image=photo, border=0)
image_pendu.place(x=120, y=140)
lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30')
init_jeu()
fenetre.mainloop()
fenetre.destroy()
fonctionnalité :
-Ajouté le mot quand on meurt
-Afficher les lettres pour savoir qu'elles sont les lettres utilisée
merci d'avance
Je voudrais savoir il est possible de mettre un fonctionnalité dans mon programme python
from tkinter import *
from random import choice
fichier = open("liste_mots.txt", "r")
liste_mots = fichier.readlines()
fichier.close()
def lettre_dans_mot(lettre) :
global partie_en_cours, mot_partiel, mot_choisi, nb_echecs, image_pendu
if partie_en_cours :
nouveau_mot_partiel = ""
lettre_dans_mot = False
i=0
while i<len(mot_choisi):
if mot_choisi[i]==lettre:
nouveau_mot_partiel = nouveau_mot_partiel + lettre
lettre_dans_mot = True
else:
nouveau_mot_partiel = nouveau_mot_partiel + mot_partiel[i]
i+=1
mot_partiel = nouveau_mot_partiel
afficher_mot(mot_partiel)
if not lettre_dans_mot :
nb_echecs += 1
nomFichier = "pendu_"+str(nb_echecs)+".gif"
photo=PhotoImage(file=nomFichier)
image_pendu.config(image=photo)
image_pendu.image=photo
if nb_echecs == 7:
partie_en_cours = False
afficher_mot(mot_choisi)
elif mot_partiel == mot_choisi:
partie_en_cours = False
def afficher_mot(mot):
global lettres
mot_large = ""
i=0
while i<len(mot):
mot_large = mot_large + mot[i] + " "
i+=1
canevas.delete(lettres)
lettres = canevas.create_text(320,60,text=mot_large,fill='blue',font='Chiller 30')
def init_jeu():
global mot_choisi, mot_partiel, image_pendu, lettres
global nb_echecs, partie_en_cours, liste_mots
nb_echecs = 0
partie_en_cours = True
mot_choisi = choice(liste_mots).rstrip()
mot_choisi = mot_choisi.upper()
mot_partiel = "-" * len(mot_choisi)
afficher_mot(mot_partiel)
photo=PhotoImage(file="pendu_0.gif")
image_pendu.config(image=photo)
image_pendu.image=photo
fenetre = Tk()
fenetre.title("Le jeu du pendu[sur MC]")
canevas = Canvas(fenetre, bg='white', height=500, width=620)
canevas.pack(side=BOTTOM)
bouton = [0]*26
for i in range(26):
bouton[i] = Button(fenetre,text=chr(i+65),command=lambda x=i+65:lettre_dans_mot(chr(x)))
bouton[i].pack(side=LEFT)
bouton2 = Button(fenetre,text='Quitter',command=fenetre.quit)
bouton2.pack(side=RIGHT)
bouton1 = Button(fenetre,text='Recommencer',command=init_jeu)
bouton1.pack(side=RIGHT)
photo=PhotoImage(file="pendu_0.gif")
image_pendu = Label(canevas, image=photo, border=0)
image_pendu.place(x=120, y=140)
lettres = canevas.create_text(320,60,text="",fill='black',font='Courrier 30')
init_jeu()
fenetre.mainloop()
fenetre.destroy()
fonctionnalité :
-Ajouté le mot quand on meurt
-Afficher les lettres pour savoir qu'elles sont les lettres utilisée
merci d'avance
A voir également:
- Demande sur une amélioration du programme python (jeu du pendu)
- Jeu du pendu - Télécharger - Vie quotidienne
- 94 jeu - Télécharger - Puzzle & Réflexion
- Citizen code python avis - Accueil - Outils
- Programme demarrage windows - Guide
- 94 degrés jeu - Télécharger - Divers Jeux
1 réponse
Salut,
Modifie ton post pour insérer le code que tu as fourni entre les balises prévues à cet effet.
Dans le menu de modification de message, clique sur la flèche descendante à côté de l'icône <> et choisi Python.
Ensuite, colle ton code entre les deux balises.
Pour ce qui est de ta demande, tu peux essayer de remplacer tes 26 boutons par un champ de saisie (Entry).
Modifie ton post pour insérer le code que tu as fourni entre les balises prévues à cet effet.
Dans le menu de modification de message, clique sur la flèche descendante à côté de l'icône <> et choisi Python.
Ensuite, colle ton code entre les deux balises.
Pour ce qui est de ta demande, tu peux essayer de remplacer tes 26 boutons par un champ de saisie (Entry).