|
|
|
from File import File_chaine
|
|
|
|
import tkinter as tk
|
|
|
|
from urllib.request import urlopen
|
|
|
|
import PIL
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
|
|
class Carte:
|
|
|
|
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
|
|
|
|
if self.valeur > self.other :
|
|
|
|
return 1
|
|
|
|
elif self.valeur < self.other :
|
|
|
|
return -1
|
|
|
|
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 = []
|
|
|
|
self.nombre_carte = nb
|
|
|
|
if self.nombre_carte != 32 and self.nombre_carte != 52:
|
|
|
|
raise ValueError("Saissisez 32 ou 52 cartes")
|
|
|
|
|
|
|
|
# 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) -> File_chaine:
|
|
|
|
for i in range(nbcarte):
|
|
|
|
mcarte1 = paquet - 1 #enlever moitie val
|
|
|
|
mcarte2 = paquet # le reste du paquet
|
|
|
|
if joueur == j1 :
|
|
|
|
return File_chaine(mcarte1)
|
|
|
|
elif joueur == j2 :
|
|
|
|
return File_chaine(mcarte2)
|
|
|
|
|
|
|
|
def jeu(self):
|
|
|
|
j1 = distribute(1)
|
|
|
|
j2 = distribute(2)
|
|
|
|
while not j1.estvide() or j2.estvide() :
|
|
|
|
|
|
|
|
#j1tete = j1.tete()
|
|
|
|
#j2tete = j2.tete()
|
|
|
|
|
|
|
|
while not j1.compare(j2) == 0 : #j1.tete().compare(j2.tete()) == 0 :
|
|
|
|
# envers
|
|
|
|
j1.enfiler(j1.defiler())
|
|
|
|
j2.enfiler(j2.defiler())
|
|
|
|
# endroit
|
|
|
|
j1.enfiler(j1.defiler())
|
|
|
|
j2.enfiler(j2.defiler())
|
|
|
|
|
|
|
|
if j1.compare(j2) == 1 :#j1.tete().compare(j2.tete()) == 1 :
|
|
|
|
j1.enfiler(j1.defiler())
|
|
|
|
j1.enfiler(j2.defiler())
|
|
|
|
|
|
|
|
elif j1.compare(j2) == -1 :#j1.tete().compare(j2.tete()) == -1 :
|
|
|
|
j2.enfiler(j1.defiler())
|
|
|
|
j2.enfiler(j2.defiler())
|
|
|
|
|
|
|
|
j1.defiler()
|
|
|
|
j2.defiler()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if j1.estvide() == True :
|
|
|
|
# j1 a perdu donc j2 gagne toutes les cartes
|
|
|
|
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# j2 a perdu
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Gui:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.win = tk.Tk()
|
|
|
|
# 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()
|
|
|
|
Jeux(32)
|