|
|
|
from tkinter import *
|
|
|
|
from File import *
|
|
|
|
from random import shuffle
|
|
|
|
|
|
|
|
class Carte:
|
|
|
|
def __init__(self, valeur, couleur):
|
|
|
|
self.valeur = valeur
|
|
|
|
self.couleur = couleur
|
|
|
|
def compare(self, other):
|
|
|
|
if self.valeur > other.valeur:
|
|
|
|
return 0
|
|
|
|
elif self.valeur < other.valeur:
|
|
|
|
return 1
|
|
|
|
return 2
|
|
|
|
|
|
|
|
class Jeux:
|
|
|
|
def __init__ (self, nbr_cartes):
|
|
|
|
#self.window = Tk()
|
|
|
|
self.nb = nbr_cartes
|
|
|
|
if self.nb != 32 and self.nb != 52:
|
|
|
|
raise ValueError("Choisissez 32 ou 52 cartes")
|
|
|
|
self.paquet = []
|
|
|
|
for i in couleurs:
|
|
|
|
if self.nb == 52:
|
|
|
|
for j in numeros:
|
|
|
|
self.paquet.append(Carte(j, i))
|
|
|
|
else:
|
|
|
|
for j in numeros[5:]:
|
|
|
|
self.paquet.append(Carte(j, i))
|
|
|
|
shuffle(self.paquet)
|
|
|
|
|
|
|
|
def distribue(self):
|
|
|
|
while len(self.paquet) > 0:
|
|
|
|
for player in players:
|
|
|
|
player.enfiler(self.paquet.pop(0))
|
|
|
|
|
|
|
|
couleurs = ["Coeur", "Pique", "Carreaux", "Trèfle"]
|
|
|
|
numeros = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
|
|
|
|
|
|
|
jeu = Jeux(52)
|
|
|
|
|
|
|
|
players = [File_chaine(), File_chaine()]
|
|
|
|
next_game = [[], []]
|
|
|
|
|
|
|
|
jeu.distribue()
|
|
|
|
|
|
|
|
while not (players[0].est_vide() and len(next_game[0])!=0 or players[1].est_vide() and len(next_game[1])!=0):
|
|
|
|
cartes_tour = []
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()])
|
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1])
|
|
|
|
if winner == 2:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
next_game[winner].extend(cartes_tour)
|
|
|
|
for player_id in range(2):
|
|
|
|
if players[player_id].est_vide() and len(next_game[player_id])==0:
|
|
|
|
shuffle(next_game[player_id])
|
|
|
|
for i in next_game[player_id]:
|
|
|
|
players[player_id].enfiler(i)
|
|
|
|
next_game[player_id] = []
|
|
|
|
|
|
|
|
if players[0].est_vide():
|
|
|
|
print("Le joueur 1 a perdu", players[0].taille(), players[1].taille())
|
|
|
|
elif players[1].est_vide():
|
|
|
|
print("Le joueur 2 a perdu")
|
|
|
|
|
|
|
|
|