1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
| from tkinter import *
import random, sys
import tkinter as tk
from tkinter import messagebox
#programme de fin
def fin():
global msg1, msg2, msg3, msg4, bouton1, saisie, vies, can, listeIMG
msg1.destroy()
msg2.destroy()
msg3.destroy()
if vies>0:
victoire = "\nVous avez gagne !\n\n Le mot est "+mot+" !\n"
msg4.configure(text = victoire, fg = "green", width = 50)
else:
msg4.configure(text = "\nVous avez perdu !\n", fg = "red", width = 50)
bouton1.destroy()
saisie.destroy()
msg.configure(text = "\nRejouer ?\n")
#programme proposition et insertion des lettres
def test():
global f, can, listeIMG, saisie, mot, motcache, msg2, vies, msg4, ListeLettres, dessin
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
lettre = saisie.get()
if not lettre:
msg4.configure(text = "Vous n'avez rien saisi !\n\nVeuillez saisir une lettre !\n")
return None
if len(lettre)!= 1 or lettre not in alphabet:
msg4.configure(text = "Saisie incorrecte !\n\nRecommencez !\n")
saisie.delete(0, END)
return None
lettre = lettre.upper()
saisie.delete(0, END)
if lettre not in ListeLettres: #lettre non presente dans le mot
ListeLettres.append(lettre)
else:
vies -=1
return None
lose = "La lettre "+lettre+" n'est pas dans le mot !\n\nIl ne vous reste que "+str(vies)+" vies !\n"
temp = ""
for i in range(len(mot)):
if mot[i] == lettre:
temp += lettre
elif motcache[i] != "*":
temp += motcache[i]
else:
temp += "*"
if temp == mot:
fin()
return None
if motcache == temp:
vies -= 1
lose = "La lettre "+lettre+" n'est pas dans le mot !\n\nIl ne vous reste que "+str(vies)+" vies !\n"
if vies == 0:
fin()
return None
print = "vous avez perdu"
#affichage message lors insertion lettre
lose = "La lettre "+lettre+" n'est pas dans le mot !\n\nIl ne vous reste que "+str(vies)+" vies !\n"
msg4.configure(text = lose)
else:
win = "La lettre "+lettre+" est dans le mot, felicitations !\n\nIl vous reste "+str(vies)+" vies !\n"
msg4.configure(text = win)
motcache = temp
msg2.config(text = motcache)
#programme mettre les lettres
def clavier(event):
touche = event.keysym
if touche == "Return":
test()
#liste de mot facile
def randomWord1():
randomListe = ["AGE", "COQ", "LAC", "PAR", "MOT", "RAT", "SUD", "BEAU", "CHIEN", "CLOU", "CUIR", "DOUX", "GANT", "LAIT", "ROUX"]
n = len(randomListe)
p = random.randint(0,n-1)
return randomListe[p]
#programme avec les mots faciles
def facile():
global f, can, listeIMG, dessin, saisie, mot, motcache, msg1, msg2, msg3, msg4, vies, ListeLettres, bouton1
vies = 10
msg.configure(text = "")
msg4.configure(text = "", font = ("Helvetica", "16"), fg = "black")
ListeLettres = []
mot = randomWord1()
motcache = "*" * len(mot)
msg1 = Label(f, text = "Mot a trouver : ")
msg1.grid(row = 2, column = 0)
msg2 = Label(f, text = motcache, font=("Helvetica",16))
msg2.grid(row = 2, column = 1)
msg3 = Label(f, text = "Veuillez entrer une lettre : ")
msg3.grid(row = 4, column = 0)
msg4.configure(text = "Bonne chance !\n\nVous avez 10 vies !\n")
saisie = Entry(f)
saisie.focus_set()
saisie.bind("<Key>", clavier)
saisie.grid(row = 4, column = 1)
bouton1 = Button(f, text = "Valider", command = test)
bouton1.grid(row = 4, columnspan = 2)
bouton2 = Button(f, text = "Quitter", command = f.destroy)
bouton2.grid(row = 5, columnspan = 1)
#minuteur
def minuteurF(i, label):
if i > 0:
i -= 1
label.set(i)
rootMF.after(1000, lambda: minuteurF(i, label))
else:
messagebox.showwarning("Hop hop hop !", "Le temps s'est ecoule, la partie est aÃâÃÂ* present terminee...")
fermer()
def fermer():
rootMF.destroy()
rootMF = tk.Tk()
rootMF.title("Minuteur / Facile")
rootMF.iconbitmap('favicon.ico')
compteF = 120
button_label = tk.StringVar()
button_label.set(compteF)
tk.Button(rootMF, textvariable=button_label,command=fermer).pack(pady=10)
minuteurF(compteF, button_label)
rootMF.mainloop()
#image pendu/vie
#can = Canvas(f, height=100, width=350)
#v0 = PhotoImage(file="0.gif")
#v1 = PhotoImage(file="1.gif")
#v2 = PhotoImage(file="2.gif")
#v3 = PhotoImage(file="3.gif")
#listeIMG = [v0]
#dessin = can.create_image(150, 150, image = v0)
#can.grid(row = 7, columnspan = 2)
#f.mainloop()
#liste de mot moyen
def randomWord2():
randomListe = ["BLANC", "CALME", "FORET", "LAPIN", "ROMAN", "FLEUVE", "NIVEAU", "PAUVRE", "SAVANE", "VISION", "BASIQUE", "CONSOLE", "DOUBLER", "ELEVEUR", "FROMAGE"]
n = len(randomListe)
p = random.randint(0,n-1)
return randomListe[p]
#programme avec les mots moyen
def moyen():
global f, can, listeIMG, dessin, saisie, mot, motcache, msg1, msg2, msg3, msg4, vies, ListeLettres, bouton1
vies = 10
msg.configure(text = "")
msg4.configure(text = "", font = ("Helvetica", "16"), fg = "black")
ListeLettres = []
mot = randomWord2()
motcache = "*"*len(mot)
msg1 = Label(f, text = "Mot a trouver : ")
msg1.grid(row = 2, column = 0)
msg2 = Label(f, text = motcache, font=("Helvetica",16))
msg2.grid(row = 2, column = 1)
msg3 = Label(f, text = "Veuillez entrer une lettre : ")
msg3.grid(row = 4, column = 0)
msg4.configure(text = "Bonne chance !\n\nVous avez 10 vies !\n")
saisie = Entry(f)
saisie.focus_set()
saisie.bind("<Key>", clavier)
saisie.grid(row = 4, column = 1)
bouton1 = Button(f, text = "Valider", command = test)
bouton1.grid(row = 4, columnspan = 2)
bouton2 = Button(f, text = "Quitter", command = f.destroy)
bouton2.grid(row = 5, columnspan = 1)
#minuteur
def minuteurF(i, label):
if i > 0:
i -= 1
label.set(i)
rootMF.after(1000, lambda: minuteurF(i, label))
else:
messagebox.showwarning("Hop hop hop !", "Le temps s'est ecoule, la partie est aÃÂ* present terminee...")
fermer()
def fermer():
rootMF.destroy()
rootMF = tk.Tk()
rootMF.title("Minuteur / Facile")
rootMF.iconbitmap('favicon.ico')
compteF = 90
button_label = tk.StringVar()
button_label.set(compteF)
tk.Button(rootMF, textvariable=button_label,command=fermer).pack(pady=10)
minuteurF(compteF, button_label)
rootMF.mainloop()
#image pendu/vie
can = Canvas(f, height=100, width=350)
v0 = PhotoImage(file="0.gif")
v1 = PhotoImage(file="1.gif")
v2 = PhotoImage(file="2.gif")
v3 = PhotoImage(file="3.gif")
listeIMG = [v0,v1,v2,v3]
dessin = can.create_image(150,50, image = listeIMG[3])
can.grid(row = 7, columnspan = 2)
f.mainloop()
#liste de mot difficile
def randomWord3():
randomListe = ["BOWLINGS", "COQUILLAGE", "OXYDABLE", "VAPORISEZ", "ZODIAQUES"]
n = len(randomListe)
p = random.randint(0,n-1)
return randomListe[p]
#programme avec les mots difficiles
def difficile():
global f, can, listeIMG, dessin, saisie, mot, motcache, msg1, msg2, msg3, msg4, vies, ListeLettres, bouton1
vies = 10
msg.configure(text = "")
msg4.configure(text = "", font = ("Helvetica", "16"), fg = "black")
ListeLettres = []
mot = randomWord3()
motcache = "*"*len(mot)
msg1 = Label(f, text = "Mot a trouver : ")
msg1.grid(row = 2, column = 0)
msg2 = Label(f, text = motcache, font=("Helvetica",16))
msg2.grid(row = 2, column = 1)
msg3 = Label(f, text = "Veuillez entrer une lettre : ")
msg3.grid(row = 4, column = 0)
msg4.configure(text = "Bonne chance !\n\nVous avez 10 vies !\n")
saisie = Entry(f)
saisie.focus_set()
saisie.bind("<Key>", clavier)
saisie.grid(row = 4, column = 1)
bouton1 = Button(f, text = "Valider", command = test)
bouton1.grid(row = 4, columnspan = 2)
bouton2 = Button(f, text = "Quitter", command = f.destroy)
bouton2.grid(row = 5, columnspan = 1)
#minuteur
def minuteurF(i, label):
if i > 0:
i -= 1
label.set(i)
rootMF.after(1000, lambda: minuteurF(i, label))
else:
messagebox.showwarning("Hop hop hop !", "Le temps s'est ecoule, la partie est a present terminee...")
fermer()
def fermer():
rootMF.destroy()
rootMF = tk.Tk()
rootMF.title("Minuteur / Facile")
rootMF.iconbitmap('favicon.ico')
compteF = 40
button_label = tk.StringVar()
button_label.set(compteF)
tk.Button(rootMF, textvariable=button_label,command=fermer).pack(pady=10)
minuteurF(compteF, button_label)
rootMF.mainloop()
#image pendu/vie
#can = Canvas(f, height=100, width=350)
#v0 = PhotoImage(file="0.gif")
#v1 = PhotoImage(file="1.gif")
#v2 = PhotoImage(file="2.gif")
#v3 = PhotoImage(file="3.gif")
listeIMG = [v0,v1,v2,v3]
dessin = can.create_image(150,50, image = listeIMG[3])
can.grid(row = 7, columnspan = 2)
f.mainloop()
#menu des difficultes
def menu2() :
global f,msg,msg4, dessin
f = Tk()
msg = Label(f, text = "\nVeuillez choisir une difficulte.\n")
msg.grid(row = 0, columnspan = 3)
msg4 = Label(f, text = "", width = 50)
msg4.grid(row = 7, columnspan = 3)
bouton0 = Button(f, text = "Facile",command = facile)
bouton0.grid(row = 1, column = 0)
bouton1 = Button(f, text = "Moyen", command = moyen)
bouton1.grid(row = 1, column = 1)
bouton2 = Button(f, text = "Difficile", command = difficile)
bouton2.grid(row = 1, column = 2)
f.title("Jeu du Pendu")
f.iconbitmap('favicon.ico')
f.mainloop()
#menu de presentation regle/nouvelle partie
def menu():
global f,msg,msg4, dessin
f = Tk()
msg = Label(f, text = "\n Bienvenue dans notre jeu \n \nVous vous appretez a jouer au pendu, vous avez 10 essais possibles. \n \nApres ces 10 essais vous avez perdu.\n \nCes erreurs sont symbolisees par un dessin de pendaison.\n \nChaque lettre dites sera affichees et les accents ne sont pas pris en compte, il est possible de proposer plusieurs fois la meme lettre.\n \nSi la lettre est fausse et deja dite cela comptera pour 1 erreur supplementaire.\n \nLorsque vous avez trouve le mot, il faut ecrire une a une chaque lettre du mot auquel vous pensez.\n")
msg.grid(row = 0, columnspan = 2)
msg4 = Label(f, text = "", width = 50)
msg4.grid(row = 6, columnspan = 2)
bouton0 = Button(f, text = "Nouvelle partie",command = menu2)
bouton0.grid(row = 1, column = 0)
bouton1 = Button(f, text = "Quitter", command = f.destroy)
bouton1.grid(row = 1, column = 1)
f.title("Jeu du Pendu")
f.iconbitmap('favicon.ico')
f.mainloop()
menu() |
Partager