|
@ -2,12 +2,14 @@ from File import File_chaine |
|
|
import tkinter as tk |
|
|
import tkinter as tk |
|
|
from urllib.request import urlopen |
|
|
from urllib.request import urlopen |
|
|
import PIL |
|
|
import PIL |
|
|
|
|
|
import sqlite3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Carte: |
|
|
class Carte: |
|
|
def __init__(self,valeur, couleur): |
|
|
def __init__(self, couleur, valeur, img_path): |
|
|
self.valeur = valeur |
|
|
self.valeur = valeur |
|
|
self.couleur = couleur |
|
|
self.couleur = couleur |
|
|
|
|
|
self.image = img_path |
|
|
|
|
|
|
|
|
def compare(self, other): |
|
|
def compare(self, other): |
|
|
self.other = other.valeur |
|
|
self.other = other.valeur |
|
@ -18,23 +20,31 @@ class Carte: |
|
|
elif self.valeur == self.other : |
|
|
elif self.valeur == self.other : |
|
|
return 0 |
|
|
return 0 |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def __str__(self) -> str: |
|
|
|
|
|
return str(self.valeur) + ' de ' + self.couleur |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Jeux: |
|
|
class Jeux: |
|
|
def __init__(self, nb): |
|
|
def __init__(self, nb): |
|
|
paquet = [] |
|
|
paquet = [] |
|
|
nb = len(self.paquet) |
|
|
self.nombre_carte = nb |
|
|
if nb == 32 : |
|
|
if self.nombre_carte != 32 and self.nombre_carte != 52: |
|
|
nbcarte = nb |
|
|
raise ValueError("Saissisez 32 ou 54 cartes") |
|
|
elif nb == 52 : |
|
|
|
|
|
nbcarte = nb |
|
|
# Création du paquet de carte en fonction du nombre de carte |
|
|
else : |
|
|
conn = sqlite3.connect('bdd.db') |
|
|
raise ValueError("Saissisez 32 ou 52 cartes") |
|
|
c = conn.cursor() |
|
|
|
|
|
if self.nombre_carte == 32: |
|
|
for i in range(nbcarte): |
|
|
c.execute('SELECT * FROM Cartes WHERE belote=True') |
|
|
carte = Carte() |
|
|
else: |
|
|
paquet = [] |
|
|
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): |
|
|
for i in range(nbcarte): |
|
|
mcarte1 = paquet - 1 #enlever moitie val |
|
|
mcarte1 = paquet - 1 #enlever moitie val |
|
|
mcarte2 = paquet # le reste du paquet |
|
|
mcarte2 = paquet # le reste du paquet |
|
@ -51,7 +61,7 @@ class Jeux: |
|
|
#j1tete = j1.tete() |
|
|
#j1tete = j1.tete() |
|
|
#j2tete = j2.tete() |
|
|
#j2tete = j2.tete() |
|
|
|
|
|
|
|
|
while not Carte(j1.tete, j2.tete) == 0 : |
|
|
while not j1.compare(j2) == 0 : |
|
|
|
|
|
|
|
|
carte_envers = #id carte à l'envers dans la base de donnée |
|
|
carte_envers = #id carte à l'envers dans la base de donnée |
|
|
j1.emfiler(carte_envers)#add carte à l'envers à j1 |
|
|
j1.emfiler(carte_envers)#add carte à l'envers à j1 |
|
@ -59,13 +69,11 @@ class Jeux: |
|
|
j1.emfiler(j1.defiler()) |
|
|
j1.emfiler(j1.defiler()) |
|
|
j2.emfiler(j2.defiler()) |
|
|
j2.emfiler(j2.defiler()) |
|
|
|
|
|
|
|
|
|
|
|
if j1.compare(j2) == 1 : |
|
|
|
|
|
|
|
|
if Carte(j1.tete, j2.tete) == 1 : |
|
|
|
|
|
j1.enfiler(j1.defiler()) |
|
|
j1.enfiler(j1.defiler()) |
|
|
j1.enfiler(j2.defiler()) |
|
|
j1.enfiler(j2.defiler()) |
|
|
|
|
|
|
|
|
elif Carte(j1.tete, j2.tete) == -1 : |
|
|
elif j1.compare(j2) == -1 : |
|
|
j2.enfiler(j1.defiler()) |
|
|
j2.enfiler(j1.defiler()) |
|
|
j2.enfiler(j2.defiler()) |
|
|
j2.enfiler(j2.defiler()) |
|
|
|
|
|
|
|
@ -73,25 +81,22 @@ class Jeux: |
|
|
j2.defiler() |
|
|
j2.defiler() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if j1.estvide() == True : |
|
|
if j1.estvide() == True : |
|
|
# j1 a perdu |
|
|
# j1 a perdu |
|
|
|
|
|
pass |
|
|
else: |
|
|
else: |
|
|
# j2 a perdu |
|
|
# j2 a perdu |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Gui: |
|
|
class Gui: |
|
|
def __init__(self) -> None: |
|
|
def __init__(self) -> None: |
|
|
self.win = tk.Tk() |
|
|
self.win = tk.Tk() |
|
|
src = 'http://www.iro.umontreal.ca/~reid/ift1146/E06/classic-cards/1.png' |
|
|
# image = tk.PhotoImage(b64_data) |
|
|
url = urlopen(src) |
|
|
# self.can = tk.Canvas(self.win, width=320, height=320) |
|
|
raw_data = url.read() |
|
|
# self.can.create_image(200, 200, image=image) |
|
|
print(raw_data) |
|
|
# self.can.pack() |
|
|
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() |
|
|
|
|
|
self.win.mainloop() |
|
|
self.win.mainloop() |
|
|
Gui() |
|
|
Gui() |
|
|
|
|
|
Jeux(32) |