|
@ -2,26 +2,22 @@ from File import File_chaine |
|
|
import tkinter as tk |
|
|
import tkinter as tk |
|
|
from PIL import Image, ImageTk |
|
|
from PIL import Image, ImageTk |
|
|
import sqlite3 |
|
|
import sqlite3 |
|
|
|
|
|
import random |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Carte: |
|
|
class Carte: |
|
|
def __init__(self, couleur, valeur, img_path): |
|
|
def __init__(self, couleur, valeur, img_path): |
|
|
self.valeur = valeur |
|
|
self.valeur = valeur |
|
|
self.couleur = couleur |
|
|
self.couleur = couleur |
|
|
print(img_path) |
|
|
|
|
|
image = Image.open(img_path) |
|
|
image = Image.open(img_path) |
|
|
self.image = ImageTk.PhotoImage((image)) |
|
|
self.image = ImageTk.PhotoImage((image)) |
|
|
# self.image = img_path |
|
|
|
|
|
|
|
|
|
|
|
def compare(self, other): |
|
|
def compare(self, other): |
|
|
self.other = other.valeur |
|
|
if self.valeur > other.valeur: |
|
|
if self.valeur > self.other : |
|
|
|
|
|
return 1 |
|
|
return 1 |
|
|
elif self.valeur < self.other : |
|
|
elif self.valeur < other.valeur: |
|
|
return -1 |
|
|
return -1 |
|
|
elif self.valeur == self.other : |
|
|
|
|
|
return 0 |
|
|
return 0 |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def __str__(self) -> str: |
|
|
def __str__(self) -> str: |
|
|
return str(self.valeur) + ' de ' + self.couleur |
|
|
return str(self.valeur) + ' de ' + self.couleur |
|
@ -46,62 +42,52 @@ class Jeux: |
|
|
self.paquet.append(Carte(data[i][0], data[i][1], data[i][3])) |
|
|
self.paquet.append(Carte(data[i][0], data[i][1], data[i][3])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def distribute(self) : #-> File_chaine: |
|
|
def distribute(self) -> File_chaine: |
|
|
for i in range(nbcarte): |
|
|
joueur = [File_chaine(), File_chaine()] |
|
|
|
|
|
while len(self.paquet) > 0: |
|
|
|
|
|
for i in range(2): |
|
|
|
|
|
random_number = random.randint(0, len(self.paquet)-1) |
|
|
|
|
|
joueur[i].enfiler(self.paquet.pop(random_number)) |
|
|
|
|
|
return joueur |
|
|
|
|
|
|
|
|
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): |
|
|
def jeu(self): |
|
|
j1 = distribute() |
|
|
self.j1, self.j2 = self.distribute() |
|
|
j2 = distribute() |
|
|
while not (self.j1.est_vide() or self.j2.est_vide()): |
|
|
while not j1.estvide() or j2.estvide() : |
|
|
self.bataille() |
|
|
|
|
|
|
|
|
#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 : |
|
|
if self.j1.est_vide() == True : |
|
|
j1.enfiler(j1.defiler()) |
|
|
# self.j1 a perdu donc self.j2 gagne toutes les cartes |
|
|
j1.enfiler(j2.defiler()) |
|
|
|
|
|
|
|
|
|
|
|
elif j1.compare(j2) == -1 :#j1.tete().compare(j2.tete()) == -1 : |
|
|
print(self.j1, self.j2) |
|
|
j2.enfiler(j1.defiler()) |
|
|
else: |
|
|
j2.enfiler(j2.defiler()) |
|
|
print(self.j1, self.j2) |
|
|
|
|
|
|
|
|
j1.defiler() |
|
|
def bataille(self, buffer_draw=[File_chaine(), File_chaine()]): |
|
|
j2.defiler() |
|
|
j1_active_carte, j2_active_carte = self.j1.defiler(), self.j2.defiler() |
|
|
|
|
|
if j1_active_carte.compare(j2_active_carte) == 0 : |
|
|
|
|
|
# envers |
|
|
|
|
|
buffer_draw[0].enfiler(j1_active_carte) # carte du dessus |
|
|
|
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte a l'envers |
|
|
|
|
|
|
|
|
|
|
|
buffer_draw[1].enfiler(j2_active_carte) # carte du dessus |
|
|
|
|
|
buffer_draw[1].enfiler(self.j2.defiler()) # carte a l'envers |
|
|
|
|
|
|
|
|
|
|
|
self.bataille(buffer_draw) |
|
|
|
|
|
|
|
|
if j1.estvide() == True : |
|
|
elif j1_active_carte.compare(j2_active_carte) == 1 : |
|
|
# j1 a perdu donc j2 gagne toutes les cartes |
|
|
while not buffer_draw[0].est_vide(): |
|
|
|
|
|
self.j1.enfiler(buffer_draw[0].defiler()) |
|
|
|
|
|
self.j1.enfiler(buffer_draw[1].defiler()) |
|
|
|
|
|
self.j1.enfiler(self.j2.defiler()) |
|
|
|
|
|
|
|
|
pass |
|
|
elif j1_active_carte.compare(j2_active_carte) == -1 :#self.j1.tete().compare(self.j2.tete()) == -1 : |
|
|
else: |
|
|
while not buffer_draw[0].est_vide(): |
|
|
# j2 a perdu |
|
|
self.j2.enfiler(buffer_draw[0].defiler()) |
|
|
pass |
|
|
self.j2.enfiler(buffer_draw[1].defiler()) |
|
|
|
|
|
self.j2.enfiler(self.j1.defiler()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class App: |
|
|
class App: |
|
@ -109,9 +95,10 @@ class App: |
|
|
self.win = tk.Tk() |
|
|
self.win = tk.Tk() |
|
|
|
|
|
|
|
|
self.jeu = Jeux(32) |
|
|
self.jeu = Jeux(32) |
|
|
|
|
|
self.jeu.jeu() |
|
|
self.images = [] |
|
|
self.images = [] |
|
|
|
|
|
|
|
|
self.display_card(self.jeu.paquet[12]) |
|
|
# self.display_card(self.jeu.paquet[12]) |
|
|
|
|
|
|
|
|
self.win.mainloop() |
|
|
self.win.mainloop() |
|
|
|
|
|
|
|
|