|
@ -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,6 +43,18 @@ 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])) |
|
|
|
|
|
|
|
|
|
|
|
self.j1, self.j2 = self.distribute() |
|
|
|
|
|
self.win.bind('<Return>', lambda x: self.bataille()) |
|
|
|
|
|
|
|
|
|
|
|
if self.j1.est_vide(): |
|
|
|
|
|
# self.j1 a perdu donc self.j2 gagne toutes les cartes |
|
|
|
|
|
|
|
|
|
|
|
print(self.j1, self.j2) |
|
|
|
|
|
elif self.j2.est_vide(): |
|
|
|
|
|
print(self.j1, self.j2) |
|
|
|
|
|
|
|
|
|
|
|
self.win.mainloop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def distribute(self) -> File_chaine: |
|
|
def distribute(self) -> File_chaine: |
|
|
joueur = [File_chaine(), File_chaine()] |
|
|
joueur = [File_chaine(), File_chaine()] |
|
@ -50,27 +64,13 @@ class Jeux: |
|
|
joueur[i].enfiler(self.paquet.pop(random_number)) |
|
|
joueur[i].enfiler(self.paquet.pop(random_number)) |
|
|
return joueur |
|
|
return joueur |
|
|
|
|
|
|
|
|
|
|
|
def bataille(self, buffer_draw=[File_chaine(), File_chaine()]) -> None: |
|
|
def jeu(self): |
|
|
# cartes retounées |
|
|
self.j1, self.j2 = self.distribute() |
|
|
if not (self.j1.est_vide() or self.j2.est_vide()): |
|
|
while not (self.j1.est_vide() or self.j2.est_vide()): |
|
|
print(buffer_draw[0], buffer_draw[1]) |
|
|
self.bataille() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.j1.est_vide(): |
|
|
|
|
|
# self.j1 a perdu donc self.j2 gagne toutes les cartes |
|
|
|
|
|
|
|
|
|
|
|
print(self.j1, self.j2) |
|
|
|
|
|
else: |
|
|
|
|
|
print(self.j1, self.j2) |
|
|
|
|
|
|
|
|
|
|
|
def bataille(self, buffer_draw=[File_chaine(), File_chaine()]): |
|
|
|
|
|
# print('buffer', buffer_draw[0], buffer_draw[1], sep='\n') |
|
|
|
|
|
j1_active_carte, j2_active_carte = self.j1.tete(), self.j2.tete() |
|
|
j1_active_carte, j2_active_carte = self.j1.tete(), self.j2.tete() |
|
|
if j1_active_carte.compare(j2_active_carte) == 0 : |
|
|
if j1_active_carte.compare(j2_active_carte) == 0 : # égalité |
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
# envers |
|
|
# envers |
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte du dessus |
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte du dessus |
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte a l'envers |
|
|
buffer_draw[0].enfiler(self.j1.defiler()) # carte a l'envers |
|
@ -80,6 +80,7 @@ class Jeux: |
|
|
# print('next_buff' ,buffer_draw[0], buffer_draw[1]) |
|
|
# print('next_buff' ,buffer_draw[0], buffer_draw[1]) |
|
|
self.bataille(buffer_draw) |
|
|
self.bataille(buffer_draw) |
|
|
except IndexError: |
|
|
except IndexError: |
|
|
|
|
|
print('hello') |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
elif j1_active_carte.compare(j2_active_carte) == 1 : |
|
|
elif j1_active_carte.compare(j2_active_carte) == 1 : |
|
@ -93,23 +94,8 @@ class Jeux: |
|
|
self.j2.enfiler(buffer_draw[0].defiler()) |
|
|
self.j2.enfiler(buffer_draw[0].defiler()) |
|
|
self.j2.enfiler(buffer_draw[1].defiler()) |
|
|
self.j2.enfiler(buffer_draw[1].defiler()) |
|
|
self.j2.enfiler(self.j1.defiler()) |
|
|
self.j2.enfiler(self.j1.defiler()) |
|
|
|
|
|
else: |
|
|
|
|
|
print(self.j1, self.j2, sep='\n') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class App: |
|
|
jeu = Jeux(32) |
|
|
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 display_card(self, carte :Carte) -> None: |
|
|
|
|
|
self.images.append(tk.Label(image=carte.image)) |
|
|
|
|
|
self.images[-1].pack() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gui = App() |
|
|
|