|
|
@ -3,6 +3,7 @@ from tkinter import messagebox |
|
|
|
from random import choice, randint |
|
|
|
from test_interaction import Jeux, vider_dans |
|
|
|
from Pile import Pile_chaine as Pile |
|
|
|
from File import File_chaine as File |
|
|
|
|
|
|
|
pique = "🂡🂢🂣🂤🂥🂦🂧🂨🂩🂪🂫🂬🂭🂮" |
|
|
|
coeur = "🂱🂲🂳🂴🂵🂶🂷🂸🂹🂺🂻🂼🂽🂾" |
|
|
@ -34,10 +35,10 @@ class Interface(tk.Frame): |
|
|
|
self.menu = tk.Frame() |
|
|
|
self.menu.grid() |
|
|
|
|
|
|
|
self.C = tk.Canvas(self.menu, bg="black",height=500, width=800, highlightthickness=0) |
|
|
|
self.C = tk.Canvas(self.menu, bg="black",height=500, width=728, highlightthickness=0) |
|
|
|
self.C.grid(row=0) |
|
|
|
for i in range(50): |
|
|
|
self.C.create_text(randint(0,800),randint(0,500),fill="white",font="Times 20",text=choice(cartes)) |
|
|
|
self.C.create_text(randint(0,728),randint(0,500),fill="white",font="Times 20",text=choice(cartes)) |
|
|
|
|
|
|
|
titre = tk.Label(self.menu, text="Bataille",bg="black", fg="white",font=("eufm10", 42),anchor ="n") |
|
|
|
titre.grid(sticky="N", row=0, pady=(100, 0)) |
|
|
@ -55,7 +56,7 @@ class Interface(tk.Frame): |
|
|
|
"""affiche un fond aleatoire different""" |
|
|
|
self.C.delete("all") |
|
|
|
for i in range(50): |
|
|
|
self.C.create_text(randint(0,800),randint(0,500),fill="white",font="Times 20",text=choice(cartes)) |
|
|
|
self.C.create_text(randint(0,728),randint(0,500),fill="white",font="Times 20",text=choice(cartes)) |
|
|
|
|
|
|
|
def jouer(self): |
|
|
|
"""interface de jeu""" |
|
|
@ -64,51 +65,79 @@ class Interface(tk.Frame): |
|
|
|
self.jeu = tk.Frame() |
|
|
|
self.jeu.grid() |
|
|
|
|
|
|
|
jeu = Jeux(6) |
|
|
|
jeu = Jeux(16) |
|
|
|
(self.paquet_joueur, self.paquet_ordi) = jeu.distribue() |
|
|
|
self.mise_joueur = Pile() |
|
|
|
self.mise_ordi = Pile() |
|
|
|
|
|
|
|
self.joueur = tk.Frame(self.jeu, bg='green') |
|
|
|
self.frame_principale = tk.Frame(self.jeu) |
|
|
|
self.frame_principale.grid(row=1) |
|
|
|
|
|
|
|
self.etat = tk.Label(self.jeu, text="",bg="white", fg="black",font=("arial", 20)) |
|
|
|
self.etat.grid(sticky="",row=0,column=0) |
|
|
|
|
|
|
|
self.canvas_joueur = tk.Canvas(self.frame_principale, bg="black",height=463, width=30, highlightthickness=0) |
|
|
|
self.canvas_joueur.grid(row=1,column=0) |
|
|
|
|
|
|
|
|
|
|
|
self.joueur = tk.Frame(self.frame_principale, bg='green') |
|
|
|
self.joueur.grid(row=1,column=1) |
|
|
|
self.vous = tk.Label(self.joueur, text="Vous",bg="green", fg="black",font=("arial", 15)) |
|
|
|
self.vous.grid(row=0, padx=(10, 10)) |
|
|
|
self.carte_joueur = tk.Label(self.joueur, text=" ",bg="white", fg="black",font=("arial", 200)) |
|
|
|
self.carte_joueur = tk.Label(self.joueur, text="🂠",bg="white", fg="black",font=("arial", 180)) |
|
|
|
self.carte_joueur.grid(row=1, column=0, padx=(10, 10),pady=(10, 10)) |
|
|
|
self.nb_carte_joueur = tk.Label(self.joueur, text=str(self.paquet_joueur.taille()),bg="green", fg="black",font=("arial", 60)) |
|
|
|
self.nb_carte_joueur.grid(row=2, padx=(10, 10),pady=(10, 10)) |
|
|
|
self.carte_restantes1 = tk.Label(self.joueur, text="cartes restantes",bg="green", fg="black",font=("arial", 15)) |
|
|
|
self.carte_restantes1.grid(row=3, padx=(10, 10)) |
|
|
|
self.joueur.grid(row=0,column=0) |
|
|
|
|
|
|
|
self.manche_suivante = tk.Button(self.jeu, text ="suivant",fg="white", bg="maroon", command=self.carte_suivante, width=20, height=2, relief="flat") |
|
|
|
self.manche_suivante.grid(row=0,column=1) |
|
|
|
|
|
|
|
self.etat = tk.Label(self.jeu, text="",bg="white", fg="black",font=("eufm10", 10)) |
|
|
|
self.etat.grid(row=0,column=1, pady=(100,0)) |
|
|
|
self.infos = tk.Frame(self.frame_principale) |
|
|
|
self.manche_suivante = tk.Button(self.infos, text ="suivant",fg="white", bg="maroon", command=self.carte_suivante, width=20, height=2, relief="flat") |
|
|
|
self.manche_suivante.grid(row=1,column=1) |
|
|
|
self.goto_menu = tk.Button(self.infos, text ="Aller au menu", bg="lightgray", command=self.afficher_menu, width=20, height=2, relief="flat") |
|
|
|
self.goto_menu.grid(row=1,column=1, pady=(200,0)) |
|
|
|
self.infos.grid(row=1,column=2) |
|
|
|
|
|
|
|
self.goto_menu = tk.Button(self.jeu, text ="Aller au menu", bg="lightgray", command=self.afficher_menu, width=20, height=2, relief="flat") |
|
|
|
self.goto_menu.grid(row=0,column=1, pady=(200,0)) |
|
|
|
|
|
|
|
|
|
|
|
self.ordi = tk.Frame(self.jeu, bg='red') |
|
|
|
self.ordi = tk.Frame(self.frame_principale, bg='red') |
|
|
|
self.vous = tk.Label(self.ordi, text="L'ordinateur",bg="red", fg="black",font=("arial", 15)) |
|
|
|
self.vous.grid(row=0, padx=(10, 10)) |
|
|
|
self.carte_ordi = tk.Label(self.ordi, text=" ",bg="white", fg="black",font=("arial", 200)) |
|
|
|
self.carte_ordi = tk.Label(self.ordi, text="🂠",bg="white", fg="black",font=("arial", 180)) |
|
|
|
self.carte_ordi.grid(row=1, padx=(10, 10),pady=(10, 10)) |
|
|
|
self.nb_carte_ordi = tk.Label(self.ordi, text=str(self.paquet_ordi.taille()),bg="red", fg="black",font=("arial", 60)) |
|
|
|
self.nb_carte_ordi.grid(row=2, padx=(10, 10),pady=(10, 10)) |
|
|
|
self.carte_restantes2 = tk.Label(self.ordi, text="cartes restantes",bg="red", fg="black",font=("arial", 15)) |
|
|
|
self.carte_restantes2.grid(row=3, padx=(10, 10)) |
|
|
|
self.ordi.grid(row=0,column=2) |
|
|
|
self.ordi.grid(row=1,column=3) |
|
|
|
|
|
|
|
self.canvas_ordi = tk.Canvas(self.frame_principale, bg="black",height=463, width=30, highlightthickness=0) |
|
|
|
self.canvas_ordi.grid(row=1,column=4) |
|
|
|
|
|
|
|
def affiche_top_carte(self): |
|
|
|
"""affiche la carte du haut des paquets des joueurs et la taille de leurs paquets""" |
|
|
|
self.carte_joueur.config(text=self.paquet_joueur.tete()) |
|
|
|
self.nb_carte_joueur.config(text=self.paquet_joueur.taille()) |
|
|
|
|
|
|
|
self.update_canvas(self.canvas_joueur, self.paquet_joueur) |
|
|
|
self.update_canvas(self.canvas_ordi, self.paquet_ordi) |
|
|
|
|
|
|
|
self.carte_ordi.config(text=self.paquet_ordi.tete()) |
|
|
|
self.nb_carte_ordi.config(text=self.paquet_ordi.taille()) |
|
|
|
|
|
|
|
def update_canvas(self,canvas, paquet): |
|
|
|
"""met à jour les cartes affichées du paquet""" |
|
|
|
canvas.delete("all") |
|
|
|
tmp = File() |
|
|
|
i=0 |
|
|
|
while not paquet.est_vide(): |
|
|
|
tmp_valeur = paquet.defiler() |
|
|
|
tmp.enfiler(tmp_valeur) |
|
|
|
canvas.create_text(15,30*i-10,fill="white",font="Times 20",text=tmp_valeur) |
|
|
|
i+=1 |
|
|
|
while not tmp.est_vide(): |
|
|
|
paquet.enfiler(tmp.defiler()) |
|
|
|
|
|
|
|
def carte_suivante(self): |
|
|
|
"""méthode principale : réalise une manche""" |
|
|
|
if not self.paquet_joueur.est_vide() and not self.paquet_ordi.est_vide(): |
|
|
@ -130,11 +159,13 @@ class Interface(tk.Frame): |
|
|
|
|
|
|
|
else: |
|
|
|
if self.paquet_joueur.taille() <= 1: |
|
|
|
self.affiche_top_carte() |
|
|
|
messagebox.showinfo("Fin de Partie", "Vous avez perdu, l'ordinateur a gagné.") |
|
|
|
self.afficher_menu() |
|
|
|
return |
|
|
|
|
|
|
|
elif self.paquet_ordi.taille() <= 1: |
|
|
|
self.affiche_top_carte() |
|
|
|
messagebox.showinfo("Fin de Partie", "L'ordinateur a perdu, vous avez gagné.") |
|
|
|
self.afficher_menu() |
|
|
|
return |
|
|
@ -154,7 +185,7 @@ class Interface(tk.Frame): |
|
|
|
if __name__ == "__main__": |
|
|
|
root = tk.Tk() |
|
|
|
root.title("Bataille") |
|
|
|
root.geometry("800x500") |
|
|
|
root.geometry("728x500") |
|
|
|
hello_frame = Interface(root) |
|
|
|
hello_frame.mainloop() |
|
|
|
|