|
|
@ -8,7 +8,10 @@ class Carte: |
|
|
|
def __init__(self, couleur, valeur, img_path): |
|
|
|
self.valeur = valeur |
|
|
|
self.couleur = couleur |
|
|
|
self.image = img_path |
|
|
|
print(img_path) |
|
|
|
image = Image.open(img_path) |
|
|
|
self.image = ImageTk.PhotoImage((image)) |
|
|
|
# self.image = img_path |
|
|
|
|
|
|
|
def compare(self, other): |
|
|
|
self.other = other.valeur |
|
|
@ -29,7 +32,7 @@ class Jeux: |
|
|
|
self.paquet = [] |
|
|
|
self.nombre_carte = nb |
|
|
|
if self.nombre_carte != 32 and self.nombre_carte != 52: |
|
|
|
raise ValueError("Saissisez 32 ou 54 cartes") |
|
|
|
raise ValueError("Saissisez 32 ou 52 cartes") |
|
|
|
|
|
|
|
# Création du paquet de carte en fonction du nombre de carte |
|
|
|
conn = sqlite3.connect('bdd.db') |
|
|
@ -43,63 +46,78 @@ class Jeux: |
|
|
|
self.paquet.append(Carte(data[i][0], data[i][1], data[i][3])) |
|
|
|
|
|
|
|
|
|
|
|
def distribute(self, joueur) -> File_chaine: |
|
|
|
def distribute(self) : #-> File_chaine: |
|
|
|
for i in range(nbcarte): |
|
|
|
mcarte1 = paquet - 1 #enlever moitie val |
|
|
|
mcarte2 = paquet # le reste du paquet |
|
|
|
|
|
|
|
while not paquet.taille() == paquet.taille() // 2 : |
|
|
|
paquet.defiler() |
|
|
|
# taille |
|
|
|
mcarte2 = paquet # le reste du paquet |
|
|
|
if joueur == j1 : |
|
|
|
return File_chaine(mcarte1) |
|
|
|
elif joueur == j2 : |
|
|
|
return File_chaine(mcarte2) |
|
|
|
|
|
|
|
# reflexion sur repartition des cartes |
|
|
|
# for i in range(self.nombre_carte): # problème lien entre fonction et class |
|
|
|
# |
|
|
|
# while not paquet.taille() == paquet.taille() // 2 : |
|
|
|
# paquet.defiler() |
|
|
|
# |
|
|
|
# return paquet |
|
|
|
|
|
|
|
def jeu(self): |
|
|
|
j1 = distribute(1) |
|
|
|
j2 = distribute(2) |
|
|
|
j1 = distribute() |
|
|
|
j2 = distribute() |
|
|
|
while not j1.estvide() or j2.estvide() : |
|
|
|
|
|
|
|
j1tete = j1.tete() |
|
|
|
j2tete = j2.tete() |
|
|
|
#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 j1tete.valeur() > j2tete.valeur() : |
|
|
|
j1.enfiler(j1tete) |
|
|
|
j1.enfiler(j2tete) |
|
|
|
if j1.compare(j2) == 1 :#j1.tete().compare(j2.tete()) == 1 : |
|
|
|
j1.enfiler(j1.defiler()) |
|
|
|
j1.enfiler(j2.defiler()) |
|
|
|
|
|
|
|
elif j1tete.valeur() < j2tete.valeur() : |
|
|
|
j2.enfiler(j1tete) |
|
|
|
j2.enfiler(j2tete) |
|
|
|
elif j1.compare(j2) == -1 :#j1.tete().compare(j2.tete()) == -1 : |
|
|
|
j2.enfiler(j1.defiler()) |
|
|
|
j2.enfiler(j2.defiler()) |
|
|
|
|
|
|
|
j1.defiler() |
|
|
|
j2.defiler() |
|
|
|
|
|
|
|
elif j1tete.valeur() == j2tete.valeur() : |
|
|
|
j1.depiler() |
|
|
|
j2.depiler() |
|
|
|
|
|
|
|
|
|
|
|
if j1.estvide() == True : |
|
|
|
# j1 a perdu |
|
|
|
# j1 a perdu donc j2 gagne toutes les cartes |
|
|
|
|
|
|
|
pass |
|
|
|
else: |
|
|
|
# j2 a perdu |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class Gui: |
|
|
|
class App: |
|
|
|
def __init__(self) -> None: |
|
|
|
self.win = tk.Tk() |
|
|
|
|
|
|
|
self.jeu = Jeux(32) |
|
|
|
self.images = [] |
|
|
|
image = Image.open('photo/5.png') |
|
|
|
test = ImageTk.PhotoImage((image)) |
|
|
|
self.images.append(tk.Label(image=test)) |
|
|
|
self.images[0].pack() |
|
|
|
|
|
|
|
# self.display_card(jeu.paquet[0]) |
|
|
|
self.display_card(self.jeu.paquet[12]) |
|
|
|
|
|
|
|
self.win.mainloop() |
|
|
|
|
|
|
|
def display_card(self, carte :Carte) -> None: |
|
|
|
image = Image.open('photo/5.png') |
|
|
|
test = ImageTk.PhotoImage((image)) |
|
|
|
self.images.append(tk.Label(image=test)) |
|
|
|
self.images[0].pack() |
|
|
|
self.images.append(tk.Label(image=carte.image)) |
|
|
|
self.images[-1].pack() |
|
|
|
|
|
|
|
|
|
|
|
jeu = Jeux(32) |
|
|
|
gui = Gui() |
|
|
|
gui = App() |