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
| from tkinter import*
import sys
from random import *
import tkinter as tk
import programmeConsole
jeu = True
while jeu:
y = 25
canvas = None
entre = None
motComplete = []
motBase = None
positionLettresMalPlacees = []
bienPlacee = []
essaie = 0
counter = 9
mot=""
erreur = []
x0 = 0
y0 = 50
x1 = 50
y1 = 100
timer_id = None
count = 8
root = Tk()
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------RESTART---------------------------------# Thomas
def recommencer():
root150.destroy()
def fin():
root150.destroy()
sys.exit(0)
def restart_good():
root.destroy()
root150= Tk()
global root150
root150.title("Bien Joué !")
Victoire = tk.Label(root150,bg='green',text="VOUS AVEZ GAGNÉ EN", font=('Arial', '50'),fg='white')
Victoire.grid(row=5,column=0)
textnbessai = Label(root150, text = str(essaie+1), font = "Arial 50" ).grid(row = 5, column = 4)
print(textnbessai, end = '')
textessai = Label(root150, text = 'ESSAI(S)', font = "Arial 50" ).grid(row = 5, column = 5)
Continuer = Button(root150,bg='white',text="RECOMMENCER ?", font=('Arial', '50'), command=recommencer)
Continuer.grid(row=7,column=0)
Stop = Button(root150,bg='white',text="ARRETER ?", font=('Arial', '50'), command=fin)
Stop.grid(row=20,column=0)
root150.mainloop()
def restart_bad():
root.destroy()
root150= Tk()
global root150
root150.title("C'est perdu !")
Defaite = tk.Label(root150,bg='red',text="GAME OVER", font=('Arial', '50'),fg='white')
Defaite.grid(row=5,column=0)
Continuer = Button(root150,bg='white',text="CONTINUER ?", font=('Arial', '50'), command=recommencer)
Continuer.grid(row=7,column=0)
Stop = Button(root150,bg='white',text="ARRETER ?", font=('Arial', '50'), command=fin)
Stop.grid(row=20,column=0)
root150.mainloop()
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#Enzo
def quitter():
root.destroy()
sys.exit(0)
quitter = Button(root, text="QUITTER", command=quitter)
quitter.grid(column=4)
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------Chronomètre---------------------------------# Ilies
def start_timer(): #Fonction de lancement du Chrono
global timer_id, count #Globalise les variables pour qu'elles ne soient pas dépendante seulement de la fonction
if count > 0: #Si le chronomètre est supérieur à 0
label ['text'] = count #Affichage du texte, qui est ici le chrono
count -= 1 #On peut l'écrire de cette manière : count = count - 1 (enlève une seconde 'n' fois)
timer_id = root.after(1000, start_timer) #after(delai_ms, fonc=None, *args) Demande à Tkinter dappeller la fonction de rappel fonc avec les arguments args après lécoulement du délai delai_ms donné en millisecondes. Votre fonction de rappel ne peut pas être appelée avant ce délai (même si son appel effectif peut le dépasser) et elle ne sera appelée quune fois.
else: #Sinon
rootchr = Tk() #Ouverture d'une autre fenêtre indépendante de la fenetre principale
rootchr.title("FIN CHRONO") #Nom de la fenêtre
bouton = Button(rootchr, text="Ok", command=rootchr.destroy) #Création d'un Bouton 'Ok' nous permettons de fermer la fenêtre
bouton.grid() #Construction (placement) du Bouton
reset_timer() #Remet le compteur à son état initial '8 secondes'/ Remet le chrono à son état initial
tempsfini = Label(rootchr, text="Le temps imparti est dépassé.. ", font=('Times', '18'),fg='red').grid()#Affichage du message de la fin du chrono, quand count < 0:
timer_id = None #Objet Vide
def reset_timer(): #Réinitialisation du Chrono
global timer_id, count #Rend ces variables utilisablent pour tout le programme
if timer_id: #Objet vide, soit il reste tout le temps vide
root.after_cancel(timer_id) #after_cancel(id) Annule la demande dappel dune fonction après un certain délai définie par la méthode after. Largument id est lidentifiant numérique retourné par la méthode after.
timer_id = None
count = 8 #Affectation de la variable de départ, la valeur de départ
label ['text'] = count
#--------------------------------------------------------#
label = Label(root, text=count, bg = "coral1", fg = "white", font = "Arial 20") # Couleur etc.. de count
label.grid(column = 3 )
Button(root, text='start', command=start_timer).grid(column = 3) #Bouton servant au lancement de la fonction reset_timer
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------Bienvenue---------------------------------# Ilies
def Bienvenue():
root4 = Tk()
root4.title("Bienvenue")
frame = Frame(root4)
frame.grid()
button = Button(frame, text="| Rentrer dans le JEU |", command=root4.destroy)
button.grid()
label = Label(root4,text="Bienvenue sur le JEU MOTUS : Réalisé par Enzo - Ilies et Thomas",font=("Arial Black", 20)).grid()
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------Affichage mot Utilisateur --------------------------# Enzo
def afficherMotChosis(mot):
global y #Une variable globale au programme (la fonction global à découverte par Ilies)
global canvas
liste = programmeConsole.mini_en_Maj(mot)
#print(liste)
x = 25
x0 = 0
x1 = 50
for loop in range(len(liste)): #Affichage
rectangle = canvas.create_text( x,y,text=liste[loop],font=("Arial Black", 25), fill = 'white')
x=x+50
y = y + 50
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------Affichage mot Complete --------------------------# Enzo
def afficherMotComplete(mot,motChoisi,x0,x1):
global y
global y0
global y1
global canvas
global motComplete
liste = programmeConsole.mini_en_Maj(mot)
#print(liste)
x = 25
for loop in range(len(liste)): #Mot bien placé et mal placé + MotComplete
if liste[loop] == motChoisi[loop]:
rectangle = canvas.create_rectangle(x0, y0, x1, y1, fill = "red")
canvas.tag_lower(rectangle)
motComplete[loop] = motChoisi[loop]
elif liste[loop] in motChoisi:
cercle = canvas.create_oval(x0+1, y0+1, x1-2, y1-2,fill = "gold")
canvas.tag_lower(cercle)
x0 = x0 + 50
x1 = x1 + 50
y0 = y0 + 100
y1 = y1 + 100
for loop in range(len(motComplete)): #Affichage
canvas.create_text( x,y,text=motComplete[loop],font=("Arial Black", 25),fill = 'white',)
reset_timer()
start_timer()
x=x+50
y = y + 50
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#----------------------INTERFACE --------------------------# Enzo + Ilies
def creationInterface(nbLettre,motChoisi):
#-----------------------------Initialisation------------------------------------#Enzo
global canvas
global entre
global motBase
#-------------------------------------------------------------------------------#Ilies
root.title("MOTUS")
root.configure(background = 'coral1')
#-------------------------------------------------------------------------------#
#----------"MOTUS" AFFICHAGE----------------# Enzo
label_one = Label(root, text = '|MOTUS|',font=("Arial", 40), fg = "white",bg = "coral1" )
label_one.grid(row = 0)
#-------------------------------------------------------------------------------#
#----------Label Veuillez entrer un mot---------#Ilies
Label(root, text = "Veuillez entrer un mot", bg="cyan",fg="tomato",font="none 12 bold").grid(row=1,column=0)
#-------------------------------------------------------------------------------#
#----------------Boite d'entrée---------------#Ilies
entre = Entry(root)
entre.grid(row=2,column=0)
#-------------------------------------------------------------------------------#
#--------------Creation des lignes--------------# Enzo
y = 25
canvas_width = nbLettre * 50
canvas_height = 600
canvas = Canvas(root, width=canvas_width,height=canvas_height, bg="deep sky blue")
x0,y0,x1,y1= 0,0,nbLettre*50,0 #Lignes
for loop in range(12):
canvas.create_line(x0,y0,x1,y1,width = 2, fill="white")
y0= y0 + 50
y1= y1 + 50
x0,y0,x1,y1= 0,0,0,nbLettre*100 #Colones
for loop in range(nbLettre+1):
canvas.create_line(x0,y0,x1,y1,width = 2,fill="white")
#476042
x0= x0 + 50
x1= x1 + 50
canvas.grid(row =5)
#-------------------------------------------------------------------------------#
#----------------Bouton---------------# Ilies
bouton = Button(root, text="ENTREE", command=boutonClic)
bouton.grid(row=3,column=0)
#----------------------Mot Complete Initialisation------------------------------# Enzo
motComplete.append(motChoisi[0])
erreur.append(".")
for loop in range (len(motChoisi) - 1):
motComplete.append(".")
erreur.append(".")
afficherMotChosis(motComplete)
motBase = list(motChoisi)
root.mainloop()
return canvas
#--------------------------------------------------------------# Enzo
def boutonClic():
global essaie
mot = entre.get()
if mot.isalpha() == True:
mot = str(mot)
mot = list(mot)
mot = programmeConsole.mini_en_Maj(mot)
if motBase != mot and essaie < 6:
if len(mot) == len(motBase):
if programmeConsole.validiteMot(mot) == False :
#------------------------------------------#Ilies
root7 = Tk()
frame = Frame(root7, bg ="white")
button = Button(frame)
button['text'] ="| Ok |"
button['command'] = root7.destroy
root7.title("! Langue !")
fautelangue = Label(root7, text="Ecrire un mot qui existe dans la langue Française, Merci !", font=('Times', '18'),fg='red').grid()
frame.grid()
button.grid()
#------------------------------------------#
#------------------------------------------#Enzo
else:
afficherMotChosis(mot)
afficherMotComplete(mot,motBase,x0,x1)
entre.delete(0, 'end')
essaie = essaie + 1
else:
mot = erreur
afficherMotChosis(mot)
afficherMotComplete(mot,motBase,x0,x1)
#------------------------------------------#
#------------------------------------------#Ilies
root5 = Tk()
root5.title("Oupsss..")
frame = Frame(root5)
button = Button(frame)
button['text'] ="| Ok |"
button['command'] = root5.destroy
label = tk.Label(root5, text="Ton mot n'est pas de bonne longueur, tu as perdu un essaie", font=('Times', '18')).grid()
reset_timer()
frame.grid()
button.grid()
#------------------------------------------#
#------------------------------------------#Enzo
essaie = essaie +1
elif motBase == mot and essaie < 6:
#------------------------------------------#Ilies
restart_good()
#------------------------------------------#Enzo
elif motBase != mot and essaie == 6:
#------------------------------------------#Ilies
root6 = Tk()
frame = Frame(root6)
button = Button(frame)
button['text'] ="| Ok |"
button['command'] = root6.destroy
root6.title("Dommage..")
textlose = Label(root6, text = 'Vous avez perdu.. donc voici le mot : ', bg = "red",fg = "white",font = "Arial 10" ).grid(row = 1, column = 4)
bonmot = Label(root6, text = motChoisi, bg = "red",fg = "white",font = "Arial 10" ).grid(row = 1, column = 5)
print(textlose, bonmot)
frame.grid(column = 4)
button.grid()
reset_timer()
restart_bad()
else:
root2 = Tk()
frame = Frame(root2)
button = Button(frame)
button['text'] ="| Ok |"
button['command'] = root2.destroy
root2.title("Erreur")
label = tk.Label(root2, text='Ne rentrez que des lettres !', font=('Times', '18'),fg='red').grid()
frame.grid()
button.grid()
#------------------------------------------#
#--------------------------------------------------------------------------------------------------------------------------------------------------------------#
#---------------MAIN----------------------# Enzo
def main():
global canvas
motChoisi = programmeConsole.choixDuMot()
canvas = creationInterface(len(motChoisi),motChoisi)
Bienvenue() #Renvoie une fenetre de bienvenue
main() #Lancement du Jeu |
Partager