[Echecs] Communication déplacement GUI ↔ Logique refaite

This commit is contained in:
Geoffrey Frogeye 2014-12-07 13:04:06 +01:00
parent c47b2fad69
commit 39ba53fcb8

View file

@ -184,10 +184,20 @@ class LogiqueEchecs:
def dPion(self, x1, y1, x2, y2): def dPion(self, x1, y1, x2, y2):
test = self.mvtPossible(x1, y1, x2, y2) test = self.mvtPossible(x1, y1, x2, y2)
retour = {
'valide': False,
'message': test,
'deplacer': [], # Pions à déplacer
'supprimer': [], # Pions à supprimer
}
if test == MVT_OK: if test == MVT_OK:
retour['valide'] = True
if self.grille[x2][y2] > 0:
retour['supprimer'].append([x2, y2])
retour['deplacer'].append([x1, y1, x2, y2])
self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1] self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1]
self.joueur = not self.joueur self.joueur = not self.joueur
return test return retour
# GUI # GUI
@ -430,18 +440,18 @@ class PlateauTk:
def dPion(self, x1, y1, x2, y2): def dPion(self, x1, y1, x2, y2):
test = self.logique.dPion(x1, y1, x2, y2) test = self.logique.dPion(x1, y1, x2, y2)
if test == MVT_OK: # Si déplacement possible if test['valide'] == True: # Si déplacement possible
if self.grillePions[x2][y2]: # Si saut → Animation effacement for s in test['supprimer']:
self.animerF(self.grillePions[x2][y2]) self.animerF(self.grillePions[s[0]][s[1]])
self.grillePions[x2][y2], self.grillePions[x1][y1] = \ for d in test['deplacer']:
self.grillePions[x1][y1], False self.grillePions[d[2]][d[3]], self.grillePions[d[0]][d[1]] = \
self.animerD((x1 + .5) * COTE_CASE, (y1 + .5) * COTE_CASE, \ self.grillePions[d[0]][d[1]], False
(x2 + .5) * COTE_CASE, (y2 + .5) * COTE_CASE, \ self.animerD((d[0] + .5) * COTE_CASE, (d[1] + .5) * COTE_CASE, \
self.grillePions[x2][y2]) (d[2] + .5) * COTE_CASE, (d[3] + .5) * COTE_CASE, \
return True self.grillePions[d[2]][d[3]])
else: else:
self.statut('Déplacment impossible ! (' + str(test) + ')') self.statut('Déplacment impossible ! (' + test['message'] + ')')
return False return test['valide']
def dClic(self, x, y): def dClic(self, x, y):
# if not len(self.animations): # if not len(self.animations):