|
@ -1,5 +1,6 @@ |
|
|
from tkinter import Tk, Label, Button, StringVar |
|
|
from tkinter import Tk, Label, Button, IntVar, StringVar, Entry, Radiobutton |
|
|
from PIL import Image, ImageTk |
|
|
from PIL import Image, ImageTk |
|
|
|
|
|
#from util.bataille import Carte |
|
|
|
|
|
|
|
|
class Window(Tk): |
|
|
class Window(Tk): |
|
|
|
|
|
|
|
@ -12,24 +13,66 @@ class Window(Tk): |
|
|
self.geometry("1300x600") |
|
|
self.geometry("1300x600") |
|
|
self.config(background="green") |
|
|
self.config(background="green") |
|
|
|
|
|
|
|
|
self.build_window() |
|
|
|
|
|
self.p1 = p1 |
|
|
self.p1 = p1 |
|
|
self.p2 = p2 |
|
|
self.p2 = p2 |
|
|
self.c1 = None |
|
|
self.c1 = None |
|
|
self.c2 = None |
|
|
self.c2 = None |
|
|
|
|
|
self.build_pregame() |
|
|
|
|
|
|
|
|
def build_window(self): |
|
|
def build_pregame(self): |
|
|
|
|
|
self.name_var = StringVar() |
|
|
|
|
|
self.name_entry = Entry(self, textvariable=self.name_var) |
|
|
|
|
|
self.name_entry.grid(row=0, column=5) |
|
|
|
|
|
|
|
|
|
|
|
self.cards_var = IntVar() |
|
|
|
|
|
self.cards_var.set(52) |
|
|
|
|
|
self.cards_radio1 = Radiobutton(self, variable=self.cards_var, text="52 cartes", value=52) |
|
|
|
|
|
self.cards_radio2 = Radiobutton(self, variable=self.cards_var, text="32 cartes", value=32) |
|
|
|
|
|
self.cards_radio1.grid(row=1, column=4) |
|
|
|
|
|
self.cards_radio2.grid(row=1, column=6) |
|
|
|
|
|
|
|
|
|
|
|
self.confirm = Button(self, text="Lancer la partie", command=self.start_game) |
|
|
|
|
|
self.confirm.grid(row=2, column=5) |
|
|
|
|
|
|
|
|
|
|
|
def destroy_pregame(self): |
|
|
|
|
|
try: |
|
|
|
|
|
self.name_entry.destroy() |
|
|
|
|
|
self.cards_radio1.destroy() |
|
|
|
|
|
self.cards_radio2.destroy() |
|
|
|
|
|
self.confirm.destroy() |
|
|
|
|
|
except Exception: |
|
|
|
|
|
print("menu pregame pas init") |
|
|
|
|
|
|
|
|
|
|
|
def start_game(self): |
|
|
|
|
|
self.destroy_pregame() |
|
|
|
|
|
self.build_game() |
|
|
|
|
|
|
|
|
|
|
|
def build_game(self): |
|
|
"""Ajoute les composants de base à la fenêtre""" |
|
|
"""Ajoute les composants de base à la fenêtre""" |
|
|
self.title = Label(text="Bataille", font=("Courrier", 32)) |
|
|
self.title = Label(text="Bataille", font=("Courrier", 32)) |
|
|
self.title.grid(row=1, column=1) |
|
|
self.title.grid(row=1, column=1) |
|
|
|
|
|
|
|
|
|
|
|
self.name1 = Label(text=self.name_var.get(), font=("Courrier", 16)) |
|
|
|
|
|
self.name1.grid(row=2, column=0) |
|
|
|
|
|
self.name2 = Label(text="Ordinateur", font=("Courrier", 16)) |
|
|
|
|
|
self.name2.grid(row=2, column=2) |
|
|
|
|
|
|
|
|
|
|
|
self.taille_paquet1 = IntVar() |
|
|
|
|
|
self.taille_paquet2 = IntVar() |
|
|
|
|
|
self.taille_paquet1.set(self.p1.paquet.taille()) |
|
|
|
|
|
self.taille_paquet2.set(self.p2.paquet.taille()) |
|
|
|
|
|
self.count1 = Label(textvariable=self.taille_paquet1) |
|
|
|
|
|
self.count1.grid(row=3, column=0) |
|
|
|
|
|
self.count2 = Label(textvariable=self.taille_paquet2) |
|
|
|
|
|
self.count2.grid(row=3, column=2) |
|
|
|
|
|
|
|
|
self.button = Button(self, text="Jouer", command=self.show_cards) |
|
|
self.button = Button(self, text="Jouer", command=self.show_cards) |
|
|
self.button.grid(row=4, column=1) |
|
|
self.button.grid(row=6, column=1) |
|
|
|
|
|
|
|
|
#.set() pour changer le texte |
|
|
#.set() pour changer le texte |
|
|
self.text_content = StringVar() |
|
|
self.text_content = StringVar() |
|
|
self.text = Label(self, textvariable=self.text_content) |
|
|
self.text = Label(self, textvariable=self.text_content) |
|
|
self.text.grid(row=3, column=1) |
|
|
self.text.grid(row=5, column=1) |
|
|
|
|
|
|
|
|
def show_cards(self): |
|
|
def show_cards(self): |
|
|
"""Affiche les dernières cartes jouées par les deux joueurs""" |
|
|
"""Affiche les dernières cartes jouées par les deux joueurs""" |
|
@ -38,6 +81,11 @@ class Window(Tk): |
|
|
if self.c2 is not None: |
|
|
if self.c2 is not None: |
|
|
self.c2.destroy() |
|
|
self.c2.destroy() |
|
|
|
|
|
|
|
|
|
|
|
#self.p1.paquet.enfiler(Carte(1,0)) |
|
|
|
|
|
#self.taille_paquet1.set(self.p1.paquet.taille()) |
|
|
|
|
|
#self.taille_paquet2.set(self.p2.paquet.taille()) |
|
|
|
|
|
#self.text_content.set("a "+ str(self.p1.paquet.taille())) |
|
|
|
|
|
|
|
|
img1 = ImageTk.PhotoImage(card_to_image(self.p1.derniere_carte)) |
|
|
img1 = ImageTk.PhotoImage(card_to_image(self.p1.derniere_carte)) |
|
|
self.c1 = Label(self, image=img1) |
|
|
self.c1 = Label(self, image=img1) |
|
|
self.c1.photo = img1 |
|
|
self.c1.photo = img1 |
|
@ -46,8 +94,8 @@ class Window(Tk): |
|
|
self.c2 = Label(image=img2) |
|
|
self.c2 = Label(image=img2) |
|
|
self.c2.photo = img2 |
|
|
self.c2.photo = img2 |
|
|
|
|
|
|
|
|
self.c1.grid(row=2, column=0) |
|
|
self.c1.grid(row=4, column=0) |
|
|
self.c2.grid(row=2, column=2) |
|
|
self.c2.grid(row=4, column=2) |
|
|
|
|
|
|
|
|
def card_to_image(card): |
|
|
def card_to_image(card): |
|
|
"""Lie la valeur et couleur de la carte à son image""" |
|
|
"""Lie la valeur et couleur de la carte à son image""" |
|
|