You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

2 years ago
from random import randint
from lib.File import File_lst as File
2 years ago
class Carte:
2 years ago
"""
Classe représentant une carte
2 years ago
2 years ago
Arguments:
2 years ago
valeur: int -- Valeur allant de 2 à 14 (Valet=11, Dame=12, Roi=13, As=14)
2 years ago
couleur: int -- Allant de 0 à 3 (0: Carreau, 1: Coeur, 2: Pique, 3: Trefle)
2 years ago
"""
2 years ago
CARREAU = 0
COEUR = 1
PIQUE = 2
TREFLE = 3
VALET = 11
DAME = 12
ROI = 13
AS = 14
def __init__(self, valeur, couleur):
self.valeur = valeur
self.couleur = couleur
2 years ago
def compare(self, other):
2 years ago
if self.valeur > other.valeur:
return 1
2 years ago
elif self.valeur < other.valeur:
return -1
else:
return 0
2 years ago
class Jeux:
2 years ago
def __init__(self, nbcartes):
self.paquet = File()
2 years ago
self.couleur = File()
2 years ago
if nbcartes == 32:
2 years ago
for couleur in [Carte.CARREAU, Carte.COEUR, Carte.PIQUE, Carte.TREFLE]:
valeurs = [7, 8, 9, 10, Carte.VALET, Carte.DAME, Carte.ROI, Carte.AS]
for i in range(8):
rand = randint(0, len(valeurs)-1)
carte = Carte(valeurs.pop(rand), couleur)
self.paquet.enfiler(carte)
#self.couleur.enfiler(couleur)
#valeurs.pop(rand)
2 years ago
else:
2 years ago
pq = [2, 3, 4, 5, 6, 7, 8, 9, 10, Carte.VALET, Carte.DAME, Carte.ROI, Carte.AS]
2 years ago
def distribue(self):
2 years ago
cp = self.paquet
2 years ago
f1 = File()
f2 = File()
2 years ago
while not cp.est_vide():
f1.enfiler(cp.defiler())
f2.enfiler(cp.defiler())
return f1, f2
2 years ago
2 years ago
class Joueur:
2 years ago
def __init__(self, paquet, nom):
self.paquet = paquet
2 years ago
self.nom = nom
2 years ago
self.derniere_carte = None
2 years ago
def tire_carte(self):
2 years ago
self.derniere_carte = self.paquet.defiler()
return self.derniere_carte