From 7bbe786e0e188fb4d84009ebefe33967e7d26502 Mon Sep 17 00:00:00 2001 From: "barraux.a" Date: Wed, 14 Dec 2022 10:44:47 +0100 Subject: [PATCH] Ajout du paquet --- main.py | 61 ++++++++++++++++++++++++++----------------------- photo/back.png | Bin 0 -> 239 bytes 2 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 photo/back.png diff --git a/main.py b/main.py index 6523f29..668dd4f 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,14 @@ from File import File_chaine import tkinter as tk from urllib.request import urlopen import PIL +import sqlite3 class Carte: - def __init__(self,valeur, couleur): + def __init__(self, couleur, valeur, img_path): self.valeur = valeur self.couleur = couleur + self.image = img_path def compare(self, other): self.other = other.valeur @@ -18,23 +20,31 @@ class Carte: elif self.valeur == self.other : return 0 return None + + def __str__(self) -> str: + return str(self.valeur) + ' de ' + self.couleur + + class Jeux: def __init__(self, nb): paquet = [] - nb = len(self.paquet) - if nb == 32 : - nbcarte = nb - elif nb == 54 : - nbcarte = nb - else : + self.nombre_carte = nb + if self.nombre_carte != 32 and self.nombre_carte != 52: raise ValueError("Saissisez 32 ou 54 cartes") - for i in range(nbcarte): - carte = Carte() - paquet = [] + # Création du paquet de carte en fonction du nombre de carte + conn = sqlite3.connect('bdd.db') + c = conn.cursor() + if self.nombre_carte == 32: + c.execute('SELECT * FROM Cartes WHERE belote=True') + else: + c.execute('SELECT * FROM Carte') + data = c.fetchall() + for i, carte in enumerate(data): + paquet.append(Carte(data[i][0], data[i][1], data[i][3])) - def distribute(self, joueur): + def distribute(self, joueur) -> File_chaine: for i in range(nbcarte): mcarte1 = paquet - 1 #enlever moitie val mcarte2 = paquet # le reste du paquet @@ -59,33 +69,26 @@ class Jeux: j2.enfiler(j1tete) j2.enfiler(j2tete) - elif j1tete.valeur() == j2tete.valeur() : - - - - j1.depiler() - j2.depiler() + elif j1tete.valeur() == j2tete.valeur() : + j1.depiler() + j2.depiler() if j1.estvide() == True : # j1 a perdu + pass else: # j2 a perdu + pass class Gui: def __init__(self) -> None: self.win = tk.Tk() - src = 'http://www.iro.umontreal.ca/~reid/ift1146/E06/classic-cards/1.png' - url = urlopen(src) - raw_data = url.read() - print(raw_data) - url.close() - b64_data = encodestring(raw_data) - print(b64_data) - image = tk.PhotoImage(b64_data) - self.can = tk.Canvas(self.win, width=320, height=320) - self.can.create_image(200, 200, image=image) - self.can.pack() + # image = tk.PhotoImage(b64_data) + # self.can = tk.Canvas(self.win, width=320, height=320) + # self.can.create_image(200, 200, image=image) + # self.can.pack() self.win.mainloop() -Gui() \ No newline at end of file +Gui() +Jeux(32) \ No newline at end of file diff --git a/photo/back.png b/photo/back.png new file mode 100644 index 0000000000000000000000000000000000000000..c116591329250b88e3e159942e2d5b7fbd2446b5 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^?m(Qt!VDz$ninksQU(D&A+A80fuR8e8yf!q{}1Nk zBjz49&jiYI7I;J!Gca(Kf-s|(>fOIU!BkHd$B>FSZ>MkMJYc}X!g`XajpspV%hvxs znM|2UFIhF;-<4ah{nu>mnJvnzbT)5pacXm$x0-S3_CJj_+Eoj0*u6J>+nw~FMcB{c tA&i*s$D~sG|Fg-0{bCbLc1(F$#@tr6=U>G-%da3;db;|#taD0e0ssN~O0)m~ literal 0 HcmV?d00001