From 05a361eb5bacc776676e9da3396cf18d68f42e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DELPUI=20Lo=C3=AFc?= Date: Wed, 20 Dec 2023 14:28:20 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salut les quoicoubébous UWUWUWUWUUW --- projet bataille.py | 255 ++++++++++++++++++++++++++------------------- 1 file changed, 149 insertions(+), 106 deletions(-) diff --git a/projet bataille.py b/projet bataille.py index 521ae3f..8ebe510 100644 --- a/projet bataille.py +++ b/projet bataille.py @@ -1,107 +1,150 @@ -from tkinter import * -from File import * -from random import shuffle -from time import sleep - -class Carte: - def __init__(self, valeur, couleur): - self.valeur = valeur - self.couleur = couleur - 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: - return 0 - elif self.valeur < other.valeur: - return 1 - return 2 - -class Jeux: - def __init__ (self, nbr_cartes): - self.nb = nbr_cartes - if self.nb != 32 and self.nb != 52: - raise ValueError("Choisissez 32 ou 52 cartes") - self.paquet = [] - for i in couleurs: - if self.nb == 52: - for j in numeros: - self.paquet.append(Carte(j, i)) - else: - for j in numeros[5:]: - self.paquet.append(Carte(j, i)) - shuffle(self.paquet) - - def distribue(self): - while len(self.paquet) > 0: - for player in players: - player.enfiler(self.paquet.pop(0)) - -def click(event): - def afficher(): - for i in range(2): - 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())) - if cartes_tour[i].couleur in ["♥", "♦"]: - canvas.itemconfig(player_carte[i], fill = "#f00") - else: - 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 = ["♥", "♦", "♣", "♠"] -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) - -players = [File_chaine(), File_chaine()] - -jeu.distribue() - -window = Tk() -window.title("Bataille") -window.geometry(f"700x400+300+200") - -canvas = Canvas(window, width = 650, height = 300, background = "#070") -canvas.place(x = 25, y = 50) - -canvas.create_rectangle(50, 100, 150, 250, fill = "#f77") -canvas.create_rectangle(500, 100, 600, 250, fill = "#f77") -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_carte = [canvas.create_text(250, 150, text = "", font = ("Courrier New", 30, "bold")), canvas.create_text(400, 150, text = "", font = ("Courrier New", 30, "bold"))] - -canvas.bind("