loic.delpui 11 months ago
commit
54bd78adf1
  1. 47
      projet bataille.py

47
projet bataille.py

@ -0,0 +1,47 @@
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 1
elif self.valeur < other.valeur:
return -1
return 0
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()]
jeu.distribue()
while not (players[0].est_vide() or players[1].est_vide()):
players[0].compare(players[1])
Loading…
Cancel
Save