2014-11-20 18:59:50 +01:00
|
|
|
CASES_COTE = 8
|
2014-11-21 10:00:27 +01:00
|
|
|
|
2014-12-06 23:28:21 +01:00
|
|
|
MVT_INCONNU = 'Cause inconnue'
|
2014-12-06 23:28:12 +01:00
|
|
|
MVT_OK = 'Valide'
|
|
|
|
MVT_ROQUE = 'Roque'
|
|
|
|
MVT_SELECTION = 'Mauvais tour'
|
|
|
|
MVT_SUR_PLACE = 'Immobile'
|
|
|
|
MVT_SAUT_AMI = 'Saut ami'
|
|
|
|
MVT_PION_INC = 'Pion inconnu'
|
|
|
|
MVT_N_AUTORISE = 'Non-autorisé'
|
|
|
|
MVT_OBSTRUCTION = 'Pion en chemin'
|
2014-11-21 10:00:27 +01:00
|
|
|
|
2014-11-20 18:59:50 +01:00
|
|
|
class LogiqueEchecs:
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def __init__(self):
|
2014-11-20 18:59:50 +01:00
|
|
|
self.grille = []
|
|
|
|
self.cGrille()
|
|
|
|
self.remplirGrille()
|
|
|
|
self.joueur = True
|
|
|
|
self.nvPartie()
|
|
|
|
|
|
|
|
@staticmethod
|
2014-12-06 23:29:55 +01:00
|
|
|
def eNoir(xD, yD):
|
|
|
|
return xD % 2 != yD % 2
|
2014-11-20 18:59:50 +01:00
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def cGrille(self):
|
2014-11-20 18:59:50 +01:00
|
|
|
for x in range(CASES_COTE):
|
|
|
|
colonne = []
|
|
|
|
for y in range(CASES_COTE):
|
|
|
|
colonne.append(0)
|
|
|
|
self.grille.append(colonne)
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def remplirGrille(self):
|
2014-11-20 18:59:50 +01:00
|
|
|
speciales = [2, 3, 4, 6, 5, 4, 3, 2]
|
|
|
|
for i in range(0, 8):
|
|
|
|
self.grille[i][0] = speciales[i] + 10
|
|
|
|
self.grille[i][1] = 11
|
|
|
|
self.grille[i][6] = 1
|
|
|
|
self.grille[i][7] = speciales[i]
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def nvPartie(self):
|
2014-11-20 18:59:50 +01:00
|
|
|
self.cGrille()
|
|
|
|
self.remplirGrille()
|
|
|
|
self.joueur = True
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def cPion(self, x, y, piece):
|
2014-11-20 18:59:50 +01:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.grille[x][y] = piece
|
|
|
|
return True
|
|
|
|
|
2014-12-06 21:52:56 +01:00
|
|
|
@staticmethod
|
|
|
|
def ePionBlanc(pion):
|
|
|
|
return pion in range(1, 7)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def ePionNoir(pion):
|
|
|
|
return pion in range(11, 17)
|
|
|
|
|
|
|
|
|
|
|
|
def aSonTour(self, pion):
|
|
|
|
return (self.ePionNoir(pion) and self.joueur == False) or \
|
|
|
|
(self.ePionBlanc(pion) and self.joueur == True)
|
|
|
|
|
2014-12-06 23:19:27 +01:00
|
|
|
def mvtPossiblePion(self, x1, y1, x2, y2):
|
|
|
|
if x1 == x2 and self.grille[x2][y2] <= 0: # Avance
|
|
|
|
if self.joueur:
|
|
|
|
if y2 == y1 - 1:
|
2014-12-06 23:28:12 +01:00
|
|
|
return MVT_OK
|
2014-12-06 23:19:27 +01:00
|
|
|
elif y1 == 6 and y2 == 4 and self.grille[x1][5] == 0:
|
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
else:
|
|
|
|
if y2 == y1 + 1:
|
2014-12-06 23:28:12 +01:00
|
|
|
return MVT_OK
|
2014-12-06 23:19:27 +01:00
|
|
|
elif y1 == 1 and y2 == 3 and self.grille[x1][2] == 0:
|
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
elif abs(x1-x2) == 1: # Saut
|
|
|
|
if self.joueur:
|
|
|
|
if y2 == y1 - 1 and \
|
|
|
|
self.ePionNoir(self.grille[x2][y2]):
|
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
else:
|
|
|
|
if y2 == y1 + 1 and \
|
|
|
|
self.ePionBlanc(self.grille[x2][y2]):
|
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
|
|
|
|
def mvtPossibleTour(self, x1, y1, x2, y2):
|
|
|
|
if y1 == y2:
|
|
|
|
sens = (x2-x1)//abs(x2-x1)
|
|
|
|
for x in range(x1+sens, x2, sens):
|
|
|
|
if self.grille[x][y1] > 0:
|
|
|
|
return MVT_OBSTRUCTION
|
|
|
|
elif x1 == x2:
|
|
|
|
sens = (y2-y1)//abs(y2-y1)
|
|
|
|
for y in range(y1+sens, y2, sens):
|
|
|
|
if self.grille[x1][y] > 0:
|
|
|
|
return MVT_OBSTRUCTION
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
return MVT_OK
|
|
|
|
|
|
|
|
def mvtPossibleFou(self, x1, y1, x2, y2):
|
|
|
|
if abs(x2-x1) == abs(y2-y1):
|
|
|
|
sensX = (x2-x1)//abs(x2-x1)
|
|
|
|
sensY = (y2-y1)//abs(y2-y1)
|
|
|
|
x = x1
|
|
|
|
y = y1
|
|
|
|
dist = 0
|
|
|
|
distTot = abs(x2-x1)
|
|
|
|
while dist < distTot:
|
|
|
|
dist += 1
|
|
|
|
x += sensX
|
|
|
|
y += sensY
|
|
|
|
if self.grille[x][y] > 0:
|
|
|
|
if dist == distTot:
|
|
|
|
return MVT_OK # Saut
|
|
|
|
else:
|
|
|
|
return MVT_OBSTRUCTION
|
|
|
|
return MVT_OK # Vide
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
|
|
|
|
|
|
|
def mvtPossibleCavalier(self, x1, y1, x2, y2):
|
2014-12-07 12:49:33 +01:00
|
|
|
if (abs(x2-x1) == 2 and abs(y2-y1) == 1) or (abs(y2-y1) == 2 and abs(x2-x1) == 1):
|
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
2014-12-06 23:19:27 +01:00
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def mvtPossible(self, x1, y1, x2, y2):
|
2014-11-20 18:59:50 +01:00
|
|
|
pion = self.grille[x1][y1]
|
2014-12-06 21:52:56 +01:00
|
|
|
if self.aSonTour(pion):
|
2014-12-06 22:37:58 +01:00
|
|
|
if (x1 != x2 or y1 != y2):
|
|
|
|
if not self.aSonTour(self.grille[x2][y2]):
|
|
|
|
tPion = pion % 10
|
|
|
|
if tPion == 1: # Pion
|
2014-12-06 23:19:27 +01:00
|
|
|
return self.mvtPossiblePion(x1, y1, x2, y2)
|
|
|
|
elif tPion == 2: # Tour
|
|
|
|
return self.mvtPossibleTour(x1, y1, x2, y2)
|
|
|
|
elif tPion == 3: # Cavalier
|
|
|
|
return self.mvtPossibleCavalier(x1, y1, x2, y2)
|
|
|
|
elif tPion == 4: # Fou
|
|
|
|
return self.mvtPossibleFou(x1, y1, x2, y2)
|
|
|
|
elif tPion == 5: # Dame
|
|
|
|
tour = self.mvtPossibleTour(x1, y1, x2, y2)
|
|
|
|
fou = self.mvtPossibleFou(x1, y1, x2, y2)
|
|
|
|
if tour == MVT_OK or fou == MVT_OK:
|
|
|
|
return MVT_OK
|
|
|
|
elif tour == MVT_OBSTRUCTION or fou == MVT_OBSTRUCTION:
|
|
|
|
return MVT_OBSTRUCTION
|
2014-12-06 21:52:56 +01:00
|
|
|
else:
|
2014-12-06 23:19:27 +01:00
|
|
|
return MVT_N_AUTORISE
|
2014-12-06 22:37:58 +01:00
|
|
|
elif tPion == 6: # Roi
|
2014-12-06 23:19:27 +01:00
|
|
|
if abs(x2-x1) <= 1 and abs(y2-y1) <= 1:
|
2014-12-06 22:37:58 +01:00
|
|
|
return MVT_OK
|
|
|
|
else:
|
|
|
|
return MVT_N_AUTORISE
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
2014-12-06 22:37:58 +01:00
|
|
|
return MVT_PION_INC
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
2014-12-06 22:37:58 +01:00
|
|
|
return MVT_SAUT_AMI
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
2014-12-06 22:37:58 +01:00
|
|
|
return MVT_SUR_PLACE
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
2014-12-06 22:37:58 +01:00
|
|
|
return MVT_SELECTION
|
|
|
|
return MVT_INCONNU
|
2014-11-20 18:59:50 +01:00
|
|
|
|
2014-12-06 21:52:56 +01:00
|
|
|
def mvtsPossibles(self, x1, y1):
|
|
|
|
tableau = []
|
|
|
|
for x2 in range(0, CASES_COTE):
|
|
|
|
for y2 in range(0, CASES_COTE):
|
2014-12-06 22:37:58 +01:00
|
|
|
if self.mvtPossible(x1, y1, x2, y2) == MVT_OK:
|
2014-12-06 21:52:56 +01:00
|
|
|
tableau.append([x2, y2])
|
|
|
|
return tableau
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
def dPion(self, x1, y1, x2, y2):
|
2014-11-20 18:59:50 +01:00
|
|
|
test = self.mvtPossible(x1, y1, x2, y2)
|
2014-12-07 13:04:06 +01:00
|
|
|
retour = {
|
|
|
|
'valide': False,
|
|
|
|
'message': test,
|
|
|
|
'deplacer': [], # Pions à déplacer
|
|
|
|
'supprimer': [], # Pions à supprimer
|
|
|
|
}
|
2014-12-06 22:37:58 +01:00
|
|
|
if test == MVT_OK:
|
2014-12-07 13:04:06 +01:00
|
|
|
retour['valide'] = True
|
|
|
|
if self.grille[x2][y2] > 0:
|
|
|
|
retour['supprimer'].append([x2, y2])
|
|
|
|
retour['deplacer'].append([x1, y1, x2, y2])
|
2014-12-06 22:37:58 +01:00
|
|
|
self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1]
|
2014-12-06 23:28:12 +01:00
|
|
|
self.joueur = not self.joueur
|
2014-12-07 13:04:06 +01:00
|
|
|
return retour
|
2014-11-20 18:59:50 +01:00
|
|
|
|
|
|
|
# GUI
|
|
|
|
|
|
|
|
from tkinter import *
|
|
|
|
|
|
|
|
DECX = 0
|
|
|
|
DECY = 0
|
|
|
|
COTE_CASE = 50
|
|
|
|
MARGE_PIONS = 5
|
|
|
|
TEMPS_ANIM = 200
|
|
|
|
INTER_ANIM = 10
|
|
|
|
|
|
|
|
class PlateauTk:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.fen = None
|
|
|
|
self.can = None
|
|
|
|
self.chaine = None
|
2014-11-21 10:00:27 +01:00
|
|
|
self.grilleDamier = []
|
|
|
|
self.imagesOriginales = []
|
|
|
|
self.imagesRedim = []
|
|
|
|
self.photos = []
|
|
|
|
self.grillePions = []
|
|
|
|
self.animations = []
|
|
|
|
|
|
|
|
self.dEtape = True
|
|
|
|
self.dx1 = -1
|
|
|
|
self.dy1 = -1
|
|
|
|
self.dx2 = -1
|
|
|
|
self.dy2 = -1
|
2014-12-06 21:52:56 +01:00
|
|
|
self.mvtsPossibles = []
|
2014-11-21 10:00:27 +01:00
|
|
|
self.logique = LogiqueEchecs()
|
2014-11-20 18:59:50 +01:00
|
|
|
|
|
|
|
self.creerFen()
|
|
|
|
self.importerImages()
|
|
|
|
self.redimImages()
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
self.cDamier()
|
|
|
|
self.cGrille()
|
|
|
|
self.remplirGrille(self.logique.grille)
|
|
|
|
|
2014-11-20 18:59:50 +01:00
|
|
|
def creerFen(self):
|
|
|
|
self.fen = Tk()
|
|
|
|
self.fen.title("Jeu d'Échecs")
|
2014-11-21 10:00:27 +01:00
|
|
|
self.can = Canvas(self.fen, width=COTE_CASE * CASES_COTE,
|
|
|
|
height=COTE_CASE * CASES_COTE, bg="ivory")
|
2014-11-20 18:59:50 +01:00
|
|
|
self.can.grid(row=0, column=1, columnspan=3)
|
2014-11-21 10:00:27 +01:00
|
|
|
self.can.bind('<Button-1>', self.clic)
|
2014-11-20 18:59:50 +01:00
|
|
|
self.chaine = Label(self.fen, text="Aux blancs")
|
|
|
|
self.chaine.grid(row=2, column=2, padx=3, pady=3)
|
|
|
|
# Button(self.fen, text="Nv. Partie", command=f_nvPartie).grid(row=2, \
|
|
|
|
# column=1, padx=3, pady=3)
|
2014-11-21 10:00:27 +01:00
|
|
|
Button(self.fen, text="Quitter", command=self.fen.destroy).grid(row=2,
|
|
|
|
column=3, padx=3, pady=3)
|
2014-11-20 18:59:50 +01:00
|
|
|
|
|
|
|
def statut(self, texte, delai=0):
|
|
|
|
self.chaine.config(text=texte)
|
|
|
|
# TODO Timeout effacer si parametre / Liste
|
|
|
|
|
|
|
|
def importerImages(self):
|
|
|
|
for piece in range(0, 21):
|
|
|
|
nom = 'sprites/'
|
2014-11-21 10:00:27 +01:00
|
|
|
if piece % 10 == 1:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'pion'
|
2014-11-21 10:00:27 +01:00
|
|
|
elif piece % 10 == 2:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'tour'
|
2014-11-21 10:00:27 +01:00
|
|
|
elif piece % 10 == 3:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'cavalier'
|
2014-11-21 10:00:27 +01:00
|
|
|
elif piece % 10 == 4:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'fou'
|
2014-11-21 10:00:27 +01:00
|
|
|
elif piece % 10 == 5:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'dame'
|
2014-11-21 10:00:27 +01:00
|
|
|
elif piece % 10 == 6:
|
2014-11-20 18:59:50 +01:00
|
|
|
nom += 'roi'
|
|
|
|
else:
|
|
|
|
self.imagesOriginales.append('')
|
|
|
|
continue
|
|
|
|
if piece < 10:
|
|
|
|
nom += 'B'
|
|
|
|
else:
|
|
|
|
nom += 'N'
|
|
|
|
nom += '.gif'
|
|
|
|
self.imagesOriginales.append(PhotoImage(file=nom))
|
|
|
|
|
|
|
|
def redimImages(self):
|
2014-11-21 10:00:27 +01:00
|
|
|
sample = int(504 / (COTE_CASE - MARGE_PIONS))
|
2014-11-20 18:59:50 +01:00
|
|
|
for piece in range(0, 21):
|
|
|
|
if self.imagesOriginales[piece] != '':
|
2014-11-21 10:00:27 +01:00
|
|
|
self.imagesRedim.append(self.imagesOriginales[piece].
|
|
|
|
subsample(sample))
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
|
|
|
self.imagesRedim.append('')
|
|
|
|
|
2014-11-21 10:00:27 +01:00
|
|
|
# Dessin
|
2014-12-06 21:52:56 +01:00
|
|
|
@staticmethod
|
|
|
|
def caseCouleur(blanc, contexte):
|
|
|
|
if contexte == 1: # Sélectionné
|
|
|
|
return '#a0cefe' if blanc else '#478bd1'
|
|
|
|
elif contexte == 2: # Possible
|
|
|
|
return '#bafea0' if blanc else '#6ed147'
|
|
|
|
elif contexte == 3: # Impossible
|
|
|
|
return '#fea0ab' if blanc else '#d14758'
|
|
|
|
else: # Normal
|
|
|
|
return '#ffce9e' if blanc else '#d18b47'
|
|
|
|
|
2014-11-20 18:59:50 +01:00
|
|
|
def cCase(self, x, y):
|
2014-12-06 21:52:56 +01:00
|
|
|
couleur = self.caseCouleur(not LogiqueEchecs.eNoir(x, y), 0)
|
|
|
|
return self.can.create_rectangle(x * COTE_CASE, y * COTE_CASE, (x + 1) * COTE_CASE, (y + 1) * COTE_CASE)
|
|
|
|
|
|
|
|
def coulCase(self, x, y, contexte):
|
|
|
|
couleur = self.caseCouleur(not self.logique.eNoir(x, y), contexte)
|
|
|
|
self.can.itemconfig(self.grilleDamier[x][y], fill=couleur, outline=couleur)
|
|
|
|
|
|
|
|
def coulDamier(self):
|
|
|
|
for x in range(0, CASES_COTE):
|
|
|
|
for y in range(0, CASES_COTE):
|
|
|
|
self.coulCase(x, y, 0)
|
2014-11-20 18:59:50 +01:00
|
|
|
|
|
|
|
def cDamier(self):
|
|
|
|
self.grilleDamier = []
|
|
|
|
for x in range(0, CASES_COTE):
|
|
|
|
colonne = []
|
|
|
|
for y in range(0, CASES_COTE):
|
|
|
|
colonne.append(self.cCase(x + DECX, y + DECY))
|
|
|
|
self.grilleDamier.append(colonne)
|
2014-12-06 21:52:56 +01:00
|
|
|
self.coulDamier()
|
2014-11-20 18:59:50 +01:00
|
|
|
|
|
|
|
def cPion(self, x, y, piece):
|
|
|
|
if piece > 0:
|
2014-11-21 10:00:27 +01:00
|
|
|
self.grillePions[x][y] = self.can.create_image((x + .5) * COTE_CASE,
|
|
|
|
(y + .5) * COTE_CASE, image=self.imagesRedim[piece])
|
2014-11-20 18:59:50 +01:00
|
|
|
else:
|
|
|
|
self.grillePions[x][y] = False
|
|
|
|
|
|
|
|
def cGrille(self):
|
|
|
|
self.grillePions = []
|
2014-11-21 10:00:27 +01:00
|
|
|
for x in range(0, CASES_COTE): # Crée self.grillePions
|
2014-11-20 18:59:50 +01:00
|
|
|
colonne = []
|
|
|
|
for y in range(0, CASES_COTE):
|
|
|
|
colonne.append(False)
|
|
|
|
self.grillePions.append(colonne)
|
|
|
|
|
|
|
|
def remplirGrille(self, j_grilleF):
|
2014-11-21 10:00:27 +01:00
|
|
|
for x in range(0, CASES_COTE): # Remplis self.grillePions
|
2014-11-20 18:59:50 +01:00
|
|
|
for y in range(0, CASES_COTE):
|
2014-11-21 10:00:27 +01:00
|
|
|
self.cPion(x, y, j_grilleF[x][y])
|
|
|
|
|
|
|
|
# Interaction
|
|
|
|
def statutPrendre(self):
|
|
|
|
if self.logique.joueur:
|
|
|
|
joueur = 'blancs'
|
|
|
|
else:
|
|
|
|
joueur = 'noirs'
|
|
|
|
self.statut('Prendre (' + joueur + ')')
|
|
|
|
|
|
|
|
@staticmethod
|
2014-12-06 21:52:56 +01:00
|
|
|
def animationDCoords(i):
|
2014-11-21 10:00:27 +01:00
|
|
|
x = i['x1'] + (i['x2']-i['x1']) * (i['avancement']/i['total'])
|
|
|
|
y = i['y1'] + (i['y2']-i['y1']) * (i['avancement']/i['total'])
|
|
|
|
return [x, y]
|
|
|
|
|
2014-12-06 21:52:56 +01:00
|
|
|
def animation(self):
|
2014-11-21 10:00:27 +01:00
|
|
|
animationsNv = []
|
|
|
|
for i in self.animations:
|
|
|
|
if i['avancement'] < i['total']:
|
2014-12-06 21:52:56 +01:00
|
|
|
if i['type'] == 'd':
|
|
|
|
coords = self.animationDCoords(i)
|
|
|
|
self.can.coords(i['pion'], coords[0], coords[1])
|
|
|
|
# elif i['type'] == 'f':
|
|
|
|
# TODO Opacité de i['pion']
|
|
|
|
# elif i['type'] == 'c':
|
|
|
|
# TODO Opacité de case
|
2014-11-21 10:00:27 +01:00
|
|
|
i['avancement'] += INTER_ANIM
|
|
|
|
animationsNv.append(i)
|
|
|
|
else:
|
2014-12-06 21:52:56 +01:00
|
|
|
if i['type'] == 'd':
|
|
|
|
self.can.coords(i['pion'], i['x2'], i['y2'])
|
|
|
|
elif i['type'] == 'f':
|
|
|
|
self.can.delete(i['pion'])
|
|
|
|
elif i['type'] == 'c':
|
|
|
|
self.coulCase(i['x'], i['y'], 0)
|
2014-11-21 10:00:27 +01:00
|
|
|
self.animations = animationsNv
|
|
|
|
if len(animationsNv):
|
2014-12-06 21:52:56 +01:00
|
|
|
self.fen.after(INTER_ANIM, self.animation)
|
2014-11-21 10:00:27 +01:00
|
|
|
|
2014-12-06 21:52:56 +01:00
|
|
|
def animer(self, animation):
|
|
|
|
etaitVide = len(self.animations) < 1
|
|
|
|
self.animations.append(animation)
|
|
|
|
if etaitVide:
|
|
|
|
self.animation()
|
2014-11-21 10:00:27 +01:00
|
|
|
|
2014-12-06 21:52:56 +01:00
|
|
|
def animerD(self, x1, y1, x2, y2, pion):
|
|
|
|
if len(self.animations):
|
2014-11-21 10:00:27 +01:00
|
|
|
for i in self.animations:
|
|
|
|
if i['pion'] == pion: # Si une animation pour ce pion existe
|
|
|
|
# déjà, on la reprend et on la modifie
|
2014-12-06 21:52:56 +01:00
|
|
|
coords = self.animationDCoords(i)
|
2014-11-21 10:00:27 +01:00
|
|
|
i['x1'] = coords[0]
|
|
|
|
i['y1'] = coords[1]
|
|
|
|
i['x2'] = x2
|
|
|
|
i['y2'] = y2
|
|
|
|
# i['total'] = i['total'] - i['avancement']
|
|
|
|
i['total'] = TEMPS_ANIM
|
|
|
|
i['avancement'] = 0
|
|
|
|
return
|
2014-12-06 21:52:56 +01:00
|
|
|
|
|
|
|
animation = {
|
|
|
|
'x1': x1,
|
|
|
|
'y1': y1,
|
|
|
|
'x2': x2,
|
|
|
|
'y2': y2,
|
|
|
|
'pion': pion,
|
|
|
|
'type': 'd',
|
|
|
|
'total': TEMPS_ANIM,
|
|
|
|
'avancement': 0
|
|
|
|
}
|
|
|
|
self.can.tag_raise(pion) # Mise au premier plan
|
|
|
|
self.animer(animation)
|
|
|
|
|
|
|
|
def animerF(self, pion): # Pion fade-out
|
|
|
|
animation = {
|
|
|
|
'pion': pion,
|
|
|
|
'type': 'f',
|
|
|
|
'total': TEMPS_ANIM,
|
|
|
|
'avancement': 0
|
|
|
|
}
|
|
|
|
self.animer(animation)
|
|
|
|
|
|
|
|
def animerC(self, x ,y):
|
|
|
|
animation = {
|
|
|
|
'type': 'c',
|
|
|
|
'x': x,
|
|
|
|
'y': y,
|
|
|
|
'total': TEMPS_ANIM,
|
|
|
|
'avancement': 0
|
|
|
|
}
|
|
|
|
self.animer(animation)
|
2014-11-21 10:00:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
def dPion(self, x1, y1, x2, y2):
|
|
|
|
test = self.logique.dPion(x1, y1, x2, y2)
|
2014-12-07 13:04:06 +01:00
|
|
|
if test['valide'] == True: # Si déplacement possible
|
|
|
|
for s in test['supprimer']:
|
|
|
|
self.animerF(self.grillePions[s[0]][s[1]])
|
|
|
|
for d in test['deplacer']:
|
|
|
|
self.grillePions[d[2]][d[3]], self.grillePions[d[0]][d[1]] = \
|
|
|
|
self.grillePions[d[0]][d[1]], False
|
|
|
|
self.animerD((d[0] + .5) * COTE_CASE, (d[1] + .5) * COTE_CASE, \
|
|
|
|
(d[2] + .5) * COTE_CASE, (d[3] + .5) * COTE_CASE, \
|
|
|
|
self.grillePions[d[2]][d[3]])
|
2014-11-21 10:00:27 +01:00
|
|
|
else:
|
2014-12-07 13:04:06 +01:00
|
|
|
self.statut('Déplacment impossible ! (' + test['message'] + ')')
|
|
|
|
return test['valide']
|
2014-11-21 10:00:27 +01:00
|
|
|
|
|
|
|
def dClic(self, x, y):
|
|
|
|
# if not len(self.animations):
|
2014-12-06 21:52:56 +01:00
|
|
|
if self.dEtape: # Prendre
|
2014-11-21 10:00:27 +01:00
|
|
|
self.dx1, self.dy1 = x, y
|
2014-12-06 21:52:56 +01:00
|
|
|
self.coulDamier() # Effacement des surbrillances
|
|
|
|
if self.logique.aSonTour(self.logique.grille[self.dx1][self.dy1]): # Si possible jouer
|
|
|
|
self.coulCase(self.dx1, self.dy1, 1)
|
|
|
|
self.mvtPossibles = self.logique.mvtsPossibles(self.dx1, self.dy1) # Surbrillance bleue
|
|
|
|
for i in self.mvtPossibles: # Surbrillances vertes
|
|
|
|
self.coulCase(i[0], i[1], 2)
|
|
|
|
self.statut('Poser')
|
|
|
|
self.dEtape = not self.dEtape
|
|
|
|
else: # Si pas pssible jouer
|
|
|
|
self.coulCase(self.dx1, self.dy1, 3)
|
|
|
|
self.animerC(self.dx1, self.dy1)
|
|
|
|
|
|
|
|
else: # Poser
|
2014-11-21 10:00:27 +01:00
|
|
|
self.dx2, self.dy2 = x, y
|
2014-12-06 21:52:56 +01:00
|
|
|
if self.dPion(self.dx1, self.dy1, self.dx2, self.dy2) or (self.dx1 == self.dx2 and self.dy1 == self.dy2): # Si déplacement fait / Annule dépalcement
|
|
|
|
self.coulDamier() # Effacer Surbrillance
|
|
|
|
self.dEtape = not self.dEtape
|
|
|
|
self.statutPrendre()
|
|
|
|
else: # Si mauvais déplacement
|
|
|
|
self.coulCase(self.dx2, self.dy2, 3)
|
|
|
|
self.animerC(self.dx2, self.dy2)
|
2014-11-21 10:00:27 +01:00
|
|
|
|
|
|
|
def clic(self, event):
|
|
|
|
x = event.x // COTE_CASE
|
|
|
|
y = event.y // COTE_CASE
|
|
|
|
self.dClic(x, y)
|
|
|
|
|
|
|
|
p = PlateauTk()
|
|
|
|
|
|
|
|
# TODO Un jeu (canvas) et un frontend (fenetre)
|