can.delete("all")
dessinePlateau()
if not(humainJoue):
machineJoue()
def about():
"""
Affiche la fenêtre "A propos"
"""
showinfo(
"A propos\n\n",
"*** Programme écrit par ***\n"
" EL MASAOUDI Raymân \n"
"1èreE NSI - Lycée Louis Armand - Mulhouse \n"
)
return()
def reglesJeu():
"""
Affiche les règles du jeu dans une boîte d'information
"""
showinfo(
"Règles du jeu\n\n",
"Premièrement : Le but du jeu est d'aligner avant son adversaire 3 symboles identiques horizontalement, verticalement ou en diagonale. \n"
"Deuxièmement : Attention, le joueur qui débute est toujours avantagé pour gagner. Pensez donc à alterner pour équilibré le combat ! \n"
)
return()
def dessinePlateau():
"""
Dessin du plateau de jeu
"""
# Exemple avec un plateau de Tic Tac Toe
areteCase = (coteCanevas - 2*marge)/3
x = 0
y = 0
for i in range(4): # Tracé des lignes horizontales
can.create_line(marge, y + marge, coteCanevas - marge, y + marge, width=4, fill="black")
y += areteCase
x = 0
y = 0
for i in range(4): # Tracé des lignes verticales
can.create_line(x + marge, marge, x + marge, coteCanevas - marge, width=4, fill="black")
x += areteCase
can.create_ovale(x1, y1, x2, y2, width = 5, fill ='Green')
can.create_ovale(x2, y1, x1, y2, width = 5, fill ='Green')
return
def machineJoue():
global humainJoue
caseVide = False
while not caseVide:
i = randrange(0,3)
j = randrange(0,3)
if etatJeu[i][j] == 0:
CaseVide = True
if humainCommence:
etatJeu[i][j] = -1
else:
etatJeu[i][j] = 1
if etatJeu[i][j] == 1:
dessineCroix(i,j)
else:
dessineCercle(i,j)
verifiePlateau()
humainJoue = True
return
def verifiePlateau():
global humainCommence,humainJoue
if randrange(2) == 0:
humainCommence = False
humainJoue = False
else:
humainJoue = False
if not machineJoue():
humainJoue
def convertitClick(x, y):
if (x >= marge) and (x < coteCanevas - marge) and (y >= marge) and (y < coteCanevas - marge):
i = int((y - marge)//areteCase)
j = int((x - marge)//areteCase)
else:
i = -1
j = -1
return (i,j)
def clickSouris(event):
"""
Fonction appelée lors d'un click du bouton gauche
de la souris/trackpad
"""
global nombreCoups, humainJoue
print("Clic au point", (event.x, event.y))
if not(partieFinie) and humainJoue:
(i,j) = convertitClick(event.x, event.y)
#print(i,j)
if (i,j) != (-1,-1):
if etatJeu[i][j] == 0: # Case vide ?
if humainCommence: # humain a les croix
dessineCroix(i,j)
etatJeu[i][j] = 1
else:
dessineCercle(i,j)
etatJeu[i][j] = -1
nombreCoups += 1
verifiePlateau()
if not(partieFinie):
humainJoue = False
machineJoue()
# Main
fen = Tk()
fen.title("Jeu de ...")
fen.config(bg = "bisque") # Couleur du fond de la fenêtre
fen.resizable(width=False, height=False) # Interdit le redimensionnement de la fenêtre