[Echecs] Communication déplacement GUI ↔ Logique refaite
This commit is contained in:
parent
c47b2fad69
commit
39ba53fcb8
|
@ -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):
|
||||
|
|
Reference in a new issue