From 39ba53fcb8cc3179443369e42a7b74cd22e9b413 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 7 Dec 2014 13:04:06 +0100 Subject: [PATCH] =?UTF-8?q?[Echecs]=20Communication=20d=C3=A9placement=20G?= =?UTF-8?q?UI=20=E2=86=94=20Logique=20refaite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- S1/Echecs/echecs.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/S1/Echecs/echecs.py b/S1/Echecs/echecs.py index c388873..aad067a 100755 --- a/S1/Echecs/echecs.py +++ b/S1/Echecs/echecs.py @@ -184,10 +184,20 @@ class LogiqueEchecs: def dPion(self, 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: + 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.joueur = not self.joueur - return test + return retour # GUI @@ -430,18 +440,18 @@ class PlateauTk: def dPion(self, x1, y1, x2, y2): test = self.logique.dPion(x1, y1, x2, y2) - if test == MVT_OK: # Si déplacement possible - if self.grillePions[x2][y2]: # Si saut → Animation effacement - self.animerF(self.grillePions[x2][y2]) - self.grillePions[x2][y2], self.grillePions[x1][y1] = \ - self.grillePions[x1][y1], False - self.animerD((x1 + .5) * COTE_CASE, (y1 + .5) * COTE_CASE, \ - (x2 + .5) * COTE_CASE, (y2 + .5) * COTE_CASE, \ - self.grillePions[x2][y2]) - return True + 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]]) else: - self.statut('Déplacment impossible ! (' + str(test) + ')') - return False + self.statut('Déplacment impossible ! (' + test['message'] + ')') + return test['valide'] def dClic(self, x, y): # if not len(self.animations):