|
@ -3,6 +3,7 @@ import tkinter as tk |
|
|
from PIL import Image, ImageTk |
|
|
from PIL import Image, ImageTk |
|
|
import sqlite3 |
|
|
import sqlite3 |
|
|
import random |
|
|
import random |
|
|
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Carte: |
|
|
class Carte: |
|
@ -25,6 +26,7 @@ class Carte: |
|
|
|
|
|
|
|
|
class Jeux: |
|
|
class Jeux: |
|
|
def __init__(self, nb) -> None: |
|
|
def __init__(self, nb) -> None: |
|
|
|
|
|
self.win = tk.Tk() |
|
|
self.paquet = [] |
|
|
self.paquet = [] |
|
|
self.nombre_carte = nb |
|
|
self.nombre_carte = nb |
|
|
if self.nombre_carte != 32 and self.nombre_carte != 52: |
|
|
if self.nombre_carte != 32 and self.nombre_carte != 52: |
|
@ -41,75 +43,59 @@ class Jeux: |
|
|
for i, carte in enumerate(data): |
|
|
for i, carte in enumerate(data): |
|
|
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: |
|
|
|
|
|
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): |
|
|
|
|
|
self.j1, self.j2 = self.distribute() |
|
|
self.j1, self.j2 = self.distribute() |
|
|
while not (self.j1.est_vide() or self.j2.est_vide()): |
|
|
self.win.bind('<Return>', lambda x: self.bataille()) |
|
|
self.bataille() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.j1.est_vide(): |
|
|
if self.j1.est_vide(): |
|
|
# self.j1 a perdu donc self.j2 gagne toutes les cartes |
|
|
# self.j1 a perdu donc self.j2 gagne toutes les cartes |
|
|
|
|
|
|
|
|
print(self.j1, self.j2) |
|
|
print(self.j1, self.j2) |
|
|
else: |
|
|
elif self.j2.est_vide(): |
|
|
print(self.j1, self.j2) |
|
|
print(self.j1, self.j2) |
|
|
|
|
|
|
|
|
def bataille(self, buffer_draw=[File_chaine(), File_chaine()]): |
|
|
self.win.mainloop() |
|
|
# print('buffer', buffer_draw[0], buffer_draw[1], sep='\n') |
|
|
|
|
|
j1_active_carte, j2_active_carte = self.j1.tete(), self.j2.tete() |
|
|
|
|
|
if j1_active_carte.compare(j2_active_carte) == 0 : |
|
|
|
|
|
try: |
|
|
|
|
|
|
|
|
|
|
|
# envers |
|
|
|
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte du dessus |
|
|
|
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte a l'envers |
|
|
|
|
|
|
|
|
|
|
|
buffer_draw[1].enfiler(self.j2.defiler()) # carte du dessus |
|
|
|
|
|
buffer_draw[1].enfiler(self.j2.defiler()) # carte a l'envers |
|
|
|
|
|
# print('next_buff' ,buffer_draw[0], buffer_draw[1]) |
|
|
|
|
|
self.bataille(buffer_draw) |
|
|
|
|
|
except IndexError: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
def __init__(self) -> None: |
|
|
|
|
|
self.win = tk.Tk() |
|
|
|
|
|
|
|
|
|
|
|
self.jeu = Jeux(32) |
|
|
|
|
|
self.jeu.jeu() |
|
|
|
|
|
self.images = [] |
|
|
|
|
|
|
|
|
|
|
|
# self.display_card(self.jeu.paquet[12]) |
|
|
|
|
|
|
|
|
|
|
|
self.win.mainloop() |
|
|
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 display_card(self, carte :Carte) -> None: |
|
|
def bataille(self, buffer_draw=[File_chaine(), File_chaine()]) -> None: |
|
|
self.images.append(tk.Label(image=carte.image)) |
|
|
# cartes retounées |
|
|
self.images[-1].pack() |
|
|
if not (self.j1.est_vide() or self.j2.est_vide()): |
|
|
|
|
|
print(buffer_draw[0], buffer_draw[1]) |
|
|
|
|
|
j1_active_carte, j2_active_carte = self.j1.tete(), self.j2.tete() |
|
|
|
|
|
if j1_active_carte.compare(j2_active_carte) == 0 : # égalité |
|
|
|
|
|
try: |
|
|
|
|
|
# envers |
|
|
|
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte du dessus |
|
|
|
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte a l'envers |
|
|
|
|
|
|
|
|
|
|
|
buffer_draw[1].enfiler(self.j2.defiler()) # carte du dessus |
|
|
|
|
|
buffer_draw[1].enfiler(self.j2.defiler()) # carte a l'envers |
|
|
|
|
|
# print('next_buff' ,buffer_draw[0], buffer_draw[1]) |
|
|
|
|
|
self.bataille(buffer_draw) |
|
|
|
|
|
except IndexError: |
|
|
|
|
|
print('hello') |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
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()) |
|
|
|
|
|
else: |
|
|
|
|
|
print(self.j1, self.j2, sep='\n') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gui = App() |
|
|
jeu = Jeux(32) |