From 83b956e6328f380eb41e9512e82c5951375c4d41 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 12 Dec 2014 22:03:16 +0100 Subject: [PATCH] =?UTF-8?q?[Echecs]=20S=C3=A9paration=20plateau/canvas=20e?= =?UTF-8?q?t=20frontend/fen=C3=AAtre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- S1/Echecs/guiTk.py | 78 ++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/S1/Echecs/guiTk.py b/S1/Echecs/guiTk.py index 7e34539..3d946fb 100644 --- a/S1/Echecs/guiTk.py +++ b/S1/Echecs/guiTk.py @@ -1,4 +1,5 @@ from tkinter import * +from logique import LogiqueEchecs class PlateauTk: @@ -9,10 +10,11 @@ class PlateauTk: TEMPS_ANIM = 200 INTER_ANIM = 10 - def __init__(self, logique): + def __init__(self, fen, can, statut, logique): - self.fen = None - self.can = None + self.can = can + self.fen = fen + self.statut = statut self.chaine = None self.grilleDamier = [] self.imagesOriginales = {} @@ -29,7 +31,8 @@ class PlateauTk: self.mvtsPossibles = [] self.logique = logique - self.creerFen() + self.redimCan() + self.can.bind('', self.clic) self.importerImages() self.redimImages() @@ -37,26 +40,10 @@ class PlateauTk: self.cGrille() self.remplirGrille(self.logique.grille) - self.fen.mainloop() + self.statutPrendre() - def creerFen(self): - self.fen = Tk() - 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('', 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 redimCan(self): + self.can.config(width=self.COTE_CASE * self.logique.CASES_COTE, height=self.COTE_CASE * self.logique.CASES_COTE) def nomPiece(self, piece): tPiece = self.logique.tPiece(piece) @@ -132,8 +119,7 @@ class PlateauTk: def cPion(self, x, y, piece): if piece > 0: - self.grillePions[x][y] = self.can.create_image((x + .5) * PlateauTk.COTE_CASE, - (y + .5) * PlateauTk.COTE_CASE, image=self.imagesRedim[piece]) + self.grillePions[x][y] = self.can.create_image((x + .5) * PlateauTk.COTE_CASE, (y + .5) * PlateauTk.COTE_CASE, image=self.imagesRedim[piece]) else: self.grillePions[x][y] = False @@ -152,9 +138,9 @@ class PlateauTk: # Interaction def nomJoueur(self, joueur, pluriel=True): - if joueur == self.logique.BLANCS: + if joueur == self.logique.BLANC: nom = 'blanc' - elif joueur == self.logique.NOIRS: + elif joueur == self.logique.NOIR: nom = 'noir' else: nom = 'inconnu' @@ -305,8 +291,40 @@ class PlateauTk: self.animerC(self.dx2, self.dy2) def clic(self, event): - x = event.x // PlateauTk.COTE_CASE - y = event.y // PlateauTk.COTE_CASE + x = event.x // self.COTE_CASE + y = event.y // self.COTE_CASE self.dClic(x, y) -# TODO Un jeu (canvas) et un frontend (fenetre) \ No newline at end of file + +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()) +