|
@ -1,12 +1,14 @@ |
|
|
from tkinter import * |
|
|
from tkinter import * |
|
|
from File import * |
|
|
from File import * |
|
|
from random import shuffle |
|
|
from random import shuffle |
|
|
|
|
|
from time import sleep |
|
|
|
|
|
|
|
|
class Carte: |
|
|
class Carte: |
|
|
def __init__(self, valeur, couleur): |
|
|
def __init__(self, valeur, couleur): |
|
|
self.valeur = valeur |
|
|
self.valeur = valeur |
|
|
self.couleur = couleur |
|
|
self.couleur = couleur |
|
|
def compare(self, other): |
|
|
def compare(self, other): |
|
|
|
|
|
#Les valeurs revoyées ne respectent pas les consignes pour des raisons d'optimisation et d'allègement du programme |
|
|
if self.valeur > other.valeur: |
|
|
if self.valeur > other.valeur: |
|
|
return 0 |
|
|
return 0 |
|
|
elif self.valeur < other.valeur: |
|
|
elif self.valeur < other.valeur: |
|
@ -34,27 +36,52 @@ class Jeux: |
|
|
player.enfiler(self.paquet.pop(0)) |
|
|
player.enfiler(self.paquet.pop(0)) |
|
|
|
|
|
|
|
|
def click(event): |
|
|
def click(event): |
|
|
x, y = event.x, event.y |
|
|
def afficher(): |
|
|
if x > 50 and x < 150 and y > 100 and y < 250: |
|
|
|
|
|
cartes_tour = [] |
|
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
|
|
if winner == 2: |
|
|
|
|
|
pass |
|
|
|
|
|
else: |
|
|
|
|
|
for carte in cartes_tour: |
|
|
|
|
|
players[winner].enfiler(carte) |
|
|
|
|
|
for i in range(2): |
|
|
for i in range(2): |
|
|
canvas.itemconfig(player_carte[i], text = cartes_tour[i].valeur + cartes_tour[i].couleur) |
|
|
canvas.itemconfig(player_cartecolor[i], fill = "#fff") |
|
|
|
|
|
canvas.itemconfig(player_carte[i], text = cartes_tour[-i-1].valeur + cartes_tour[-i-1].couleur) |
|
|
canvas.itemconfig(player_left[i], text = "Left : " + str(players[i].taille())) |
|
|
canvas.itemconfig(player_left[i], text = "Left : " + str(players[i].taille())) |
|
|
if cartes_tour[i].couleur in ["♥", "♦"]: |
|
|
if cartes_tour[i].couleur in ["♥", "♦"]: |
|
|
canvas.itemconfig(player_carte[i], fill = "#f00") |
|
|
canvas.itemconfig(player_carte[i], fill = "#f00") |
|
|
else: |
|
|
else: |
|
|
canvas.itemconfig(player_carte[i], fill = "#000") |
|
|
canvas.itemconfig(player_carte[i], fill = "#000") |
|
|
|
|
|
|
|
|
|
|
|
def premiere_carte(): |
|
|
|
|
|
window.after(3000, retourne_carte) |
|
|
|
|
|
|
|
|
|
|
|
def retourne_carte(): |
|
|
|
|
|
for rep in range(2): |
|
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
|
|
for i in range(2): |
|
|
|
|
|
canvas.itemconfig(player_cartecolor[i], fill = "#f77") |
|
|
|
|
|
canvas.itemconfig(player_carte[i], text = "") |
|
|
|
|
|
canvas.itemconfig(player_left[i], text = "Left : " + str(players[i].taille())) |
|
|
|
|
|
window.after(3000, prochaine_carte) |
|
|
|
|
|
|
|
|
|
|
|
def prochaine_carte(): |
|
|
|
|
|
for rep in range(2): |
|
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
|
|
afficher() |
|
|
|
|
|
|
|
|
|
|
|
x, y = event.x, event.y |
|
|
|
|
|
if x > 50 and x < 150 and y > 100 and y < 250: |
|
|
|
|
|
cartes_tour = [] |
|
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
|
|
while winner == 2: |
|
|
|
|
|
afficher() |
|
|
|
|
|
premiere_carte() |
|
|
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
|
|
for carte in cartes_tour: |
|
|
|
|
|
players[winner].enfiler(carte) |
|
|
|
|
|
afficher() |
|
|
|
|
|
|
|
|
couleurs = ["♥", "♦", "♣", "♠"] |
|
|
couleurs = ["♥", "♦", "♣", "♠"] |
|
|
numeros = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "R", "S"] |
|
|
numeros = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "R", "S"] |
|
|
|
|
|
#J=Jack |
|
|
|
|
|
#Q=Queen |
|
|
|
|
|
#R=Roi |
|
|
|
|
|
#S=aS |
|
|
|
|
|
|
|
|
jeu = Jeux(52) |
|
|
jeu = Jeux(52) |
|
|
|
|
|
|
|
@ -66,14 +93,12 @@ window = Tk() |
|
|
window.title("Bataille") |
|
|
window.title("Bataille") |
|
|
window.geometry(f"700x400+300+200") |
|
|
window.geometry(f"700x400+300+200") |
|
|
|
|
|
|
|
|
canvas = Canvas(window, width = 650, height = 300, background = "#fff") |
|
|
canvas = Canvas(window, width = 650, height = 300, background = "#070") |
|
|
canvas.place(x = 25, y = 50) |
|
|
canvas.place(x = 25, y = 50) |
|
|
|
|
|
|
|
|
canvas.create_rectangle(50, 100, 150, 250, fill = "#f77") |
|
|
canvas.create_rectangle(50, 100, 150, 250, fill = "#f77") |
|
|
canvas.create_rectangle(200, 75, 300, 225, fill = "#fff") |
|
|
|
|
|
canvas.create_rectangle(500, 100, 600, 250, fill = "#f77") |
|
|
canvas.create_rectangle(500, 100, 600, 250, fill = "#f77") |
|
|
canvas.create_rectangle(350, 75, 450, 225, fill = "#fff") |
|
|
player_cartecolor = [canvas.create_rectangle(200, 75, 300, 225, fill = "#fff"), canvas.create_rectangle(350, 75, 450, 225, fill = "#fff")] |
|
|
|
|
|
|
|
|
player_left = [canvas.create_text(100, 175, text = "Left : " + str(players[0].taille())), canvas.create_text(550, 175, text = "Left : " + str(players[1].taille()))] |
|
|
player_left = [canvas.create_text(100, 175, text = "Left : " + str(players[0].taille())), canvas.create_text(550, 175, text = "Left : " + str(players[1].taille()))] |
|
|
player_carte = [canvas.create_text(250, 150, text = "", font = ("Courrier New", 30, "bold")), canvas.create_text(400, 150, text = "", font = ("Courrier New", 30, "bold"))] |
|
|
player_carte = [canvas.create_text(250, 150, text = "", font = ("Courrier New", 30, "bold")), canvas.create_text(400, 150, text = "", font = ("Courrier New", 30, "bold"))] |
|
|
|
|
|
|
|
|