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