BARRAUX Arthur 2 years ago
parent
commit
3fe29ca281
  1. BIN
      bdd.db
  2. 108
      main.py

BIN
bdd.db

Binary file not shown.

108
main.py

@ -3,6 +3,7 @@ import tkinter as tk
from PIL import Image, ImageTk
import sqlite3
import random
import time
class Carte:
@ -25,6 +26,7 @@ class Carte:
class Jeux:
def __init__(self, nb) -> None:
self.win = tk.Tk()
self.paquet = []
self.nombre_carte = nb
if self.nombre_carte != 32 and self.nombre_carte != 52:
@ -40,76 +42,60 @@ class Jeux:
data = c.fetchall()
for i, carte in enumerate(data):
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()
while not (self.j1.est_vide() or self.j2.est_vide()):
self.bataille()
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)
else:
elif self.j2.est_vide():
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()
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 display_card(self, carte :Carte) -> None:
self.images.append(tk.Label(image=carte.image))
self.images[-1].pack()
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 bataille(self, buffer_draw=[File_chaine(), File_chaine()]) -> None:
# cartes retounées
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)
Loading…
Cancel
Save