[Echecs] Séparation plateau/canvas et frontend/fenêtre
This commit is contained in:
parent
abfd04e7fc
commit
83b956e632
|
@ -1,4 +1,5 @@
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
|
from logique import LogiqueEchecs
|
||||||
|
|
||||||
class PlateauTk:
|
class PlateauTk:
|
||||||
|
|
||||||
|
@ -9,10 +10,11 @@ class PlateauTk:
|
||||||
TEMPS_ANIM = 200
|
TEMPS_ANIM = 200
|
||||||
INTER_ANIM = 10
|
INTER_ANIM = 10
|
||||||
|
|
||||||
def __init__(self, logique):
|
def __init__(self, fen, can, statut, logique):
|
||||||
|
|
||||||
self.fen = None
|
self.can = can
|
||||||
self.can = None
|
self.fen = fen
|
||||||
|
self.statut = statut
|
||||||
self.chaine = None
|
self.chaine = None
|
||||||
self.grilleDamier = []
|
self.grilleDamier = []
|
||||||
self.imagesOriginales = {}
|
self.imagesOriginales = {}
|
||||||
|
@ -29,7 +31,8 @@ class PlateauTk:
|
||||||
self.mvtsPossibles = []
|
self.mvtsPossibles = []
|
||||||
self.logique = logique
|
self.logique = logique
|
||||||
|
|
||||||
self.creerFen()
|
self.redimCan()
|
||||||
|
self.can.bind('<Button-1>', self.clic)
|
||||||
self.importerImages()
|
self.importerImages()
|
||||||
self.redimImages()
|
self.redimImages()
|
||||||
|
|
||||||
|
@ -37,26 +40,10 @@ class PlateauTk:
|
||||||
self.cGrille()
|
self.cGrille()
|
||||||
self.remplirGrille(self.logique.grille)
|
self.remplirGrille(self.logique.grille)
|
||||||
|
|
||||||
self.fen.mainloop()
|
self.statutPrendre()
|
||||||
|
|
||||||
def creerFen(self):
|
def redimCan(self):
|
||||||
self.fen = Tk()
|
self.can.config(width=self.COTE_CASE * self.logique.CASES_COTE, height=self.COTE_CASE * self.logique.CASES_COTE)
|
||||||
self.fen.title("Jeu d'Échecs")
|
|
||||||
self.can = Canvas(self.fen, width=PlateauTk.COTE_CASE * self.logique.CASES_COTE,
|
|
||||||
height=PlateauTk.COTE_CASE * self.logique.CASES_COTE, bg="ivory")
|
|
||||||
self.can.grid(row=0, column=1, columnspan=3)
|
|
||||||
self.can.bind('<Button-1>', self.clic)
|
|
||||||
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)
|
|
||||||
Button(self.fen, text="Quitter", command=self.fen.destroy).grid(row=2,
|
|
||||||
column=3, padx=3, pady=3)
|
|
||||||
|
|
||||||
|
|
||||||
def statut(self, texte, delai=0):
|
|
||||||
self.chaine.config(text=texte)
|
|
||||||
# TODO Timeout effacer si parametre / Liste
|
|
||||||
|
|
||||||
def nomPiece(self, piece):
|
def nomPiece(self, piece):
|
||||||
tPiece = self.logique.tPiece(piece)
|
tPiece = self.logique.tPiece(piece)
|
||||||
|
@ -132,8 +119,7 @@ class PlateauTk:
|
||||||
|
|
||||||
def cPion(self, x, y, piece):
|
def cPion(self, x, y, piece):
|
||||||
if piece > 0:
|
if piece > 0:
|
||||||
self.grillePions[x][y] = self.can.create_image((x + .5) * PlateauTk.COTE_CASE,
|
self.grillePions[x][y] = self.can.create_image((x + .5) * PlateauTk.COTE_CASE, (y + .5) * PlateauTk.COTE_CASE, image=self.imagesRedim[piece])
|
||||||
(y + .5) * PlateauTk.COTE_CASE, image=self.imagesRedim[piece])
|
|
||||||
else:
|
else:
|
||||||
self.grillePions[x][y] = False
|
self.grillePions[x][y] = False
|
||||||
|
|
||||||
|
@ -152,9 +138,9 @@ class PlateauTk:
|
||||||
|
|
||||||
# Interaction
|
# Interaction
|
||||||
def nomJoueur(self, joueur, pluriel=True):
|
def nomJoueur(self, joueur, pluriel=True):
|
||||||
if joueur == self.logique.BLANCS:
|
if joueur == self.logique.BLANC:
|
||||||
nom = 'blanc'
|
nom = 'blanc'
|
||||||
elif joueur == self.logique.NOIRS:
|
elif joueur == self.logique.NOIR:
|
||||||
nom = 'noir'
|
nom = 'noir'
|
||||||
else:
|
else:
|
||||||
nom = 'inconnu'
|
nom = 'inconnu'
|
||||||
|
@ -305,8 +291,40 @@ class PlateauTk:
|
||||||
self.animerC(self.dx2, self.dy2)
|
self.animerC(self.dx2, self.dy2)
|
||||||
|
|
||||||
def clic(self, event):
|
def clic(self, event):
|
||||||
x = event.x // PlateauTk.COTE_CASE
|
x = event.x // self.COTE_CASE
|
||||||
y = event.y // PlateauTk.COTE_CASE
|
y = event.y // self.COTE_CASE
|
||||||
self.dClic(x, y)
|
self.dClic(x, y)
|
||||||
|
|
||||||
# TODO Un jeu (canvas) et un frontend (fenetre)
|
|
||||||
|
class fenetreTk:
|
||||||
|
|
||||||
|
PLACEHOLDER_DIMENSIONS = 300
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
self.fen = None
|
||||||
|
self.can = None
|
||||||
|
self.chaine = ''
|
||||||
|
|
||||||
|
self.plateau = None
|
||||||
|
|
||||||
|
self.creerFen()
|
||||||
|
self.fen.mainloop()
|
||||||
|
|
||||||
|
def creerFen(self):
|
||||||
|
self.fen = Tk()
|
||||||
|
self.fen.title("Jeu de plateau")
|
||||||
|
self.can = Canvas(self.fen, width=self.PLACEHOLDER_DIMENSIONS, height=self.PLACEHOLDER_DIMENSIONS, bg="ivory")
|
||||||
|
self.can.grid(row=0, column=1, columnspan=3)
|
||||||
|
self.chaine = Label(self.fen, text="Bienvenue !")
|
||||||
|
self.chaine.grid(row=2, column=2, padx=3, pady=3)
|
||||||
|
Button(self.fen, text="Nv. Partie", command=self.nvPartie).grid(row=2, column=1, padx=3, pady=3)
|
||||||
|
Button(self.fen, text="Quitter", command=self.fen.destroy).grid(row=2, column=3, padx=3, pady=3)
|
||||||
|
|
||||||
|
def statut(self, texte, delai=0):
|
||||||
|
self.chaine.config(text=texte)
|
||||||
|
# TODO Timeout effacer si parametre / Liste
|
||||||
|
|
||||||
|
def nvPartie(self):
|
||||||
|
self.plateau = PlateauTk(self.fen, self.can, self.statut, LogiqueEchecs())
|
||||||
|
|
||||||
|
|
Reference in a new issue