Browse Source

yhugyu

tkinter
enora.delmas 2 days ago
parent
commit
17ef1c5517
  1. 108
      bataille.py

108
bataille.py

@ -2,6 +2,7 @@ from File import File_chaine as File
import random import random
from time import sleep from time import sleep
#creation de la classe Carte qui ermet de comparer deux cartes entres elles
class Carte: class Carte:
"carte" "carte"
def __init__(self, valeur, couleur): def __init__(self, valeur, couleur):
@ -17,14 +18,20 @@ class Carte:
def __repr__(self): def __repr__(self):
return str(self.valeur) return str(self.valeur)
def __str__(self): def __str__(self):
return str(self.valeur) + " de " + self.couleur if self.valeur == 11:
return "V" + self.couleur
if self.valeur == 12:
return "D" + self.couleur
if self.valeur == 13:
return "R" + self.couleur
return str(self.valeur) + self.couleur
#creation de la classe jeu qui permet de créer un jeu de cartes de le melanger et de le distribuer
class Jeux: class Jeux:
def __init__(self, nbmax): def __init__(self, nbmax=52):
i = 0 i = 0
valeurs = [1, 7, 8, 9, 10, 11, 12, 13, 2, 3, 4, 5, 6] valeurs = [1, 7, 8, 9, 10, 11, 12, 13, 2, 3, 4, 5, 6]
couleurs = ["coeur", "pique", "carreau", "trefle"] couleurs = ["", "", "", "♣️"]
jeu = [] jeu = []
for val in valeurs: for val in valeurs:
if i >= nbmax: if i >= nbmax:
@ -74,7 +81,7 @@ def partie(jeu1, jeu2):
jeu2.enfiler(gain.defiler()) jeu2.enfiler(gain.defiler())
""" """
class partie_TeSt: """class partie_TeSt:
def __init__(self, nb_carte = 52): def __init__(self, nb_carte = 52):
jeux = Jeux(nb_carte) jeux = Jeux(nb_carte)
self.j1, self.j2 = jeux.distribue() self.j1, self.j2 = jeux.distribue()
@ -111,56 +118,57 @@ class partie_TeSt:
while not self.Gain.est_vide(): while not self.Gain.est_vide():
self.j2.enfiler(self.Gain.defiler()) self.j2.enfiler(self.Gain.defiler())
while not (j1.est_vide() or j2.est_vide() or winner == "égalité"): while not (j1.est_vide() or j2.est_vide() or winner == "égalité"):
print(Round) print(Round)
Round += 1 Round += 1
c1 = j1.defiler()
c2 = j2.defiler()
gain = File()
gain.enfiler(c1)
gain.enfiler(c2)
resultat = c1.compare(c2)
while resultat == 0 and j1.taille() >= 2 and j2.taille() >= 2:
if random.randint(1, 2) == 1:
gain.enfiler(j1.defiler())
gain.enfiler(j2.defiler())
else:
gain.enfiler(j2.defiler())
gain.enfiler(j1.defiler())
c1 = j1.defiler() c1 = j1.defiler()
c2 = j2.defiler() c2 = j2.defiler()
if random.randint(1, 2) == 1:
gain.enfiler(c2)
gain.enfiler(c1) gain = File()
else: gain.enfiler(c1)
gain.enfiler(c1) gain.enfiler(c2)
gain.enfiler(c2)
resultat = c1.compare(c2) resultat = c1.compare(c2)
if resultat == 1: while resultat == 0 and j1.taille() >= 2 and j2.taille() >= 2:
winner = "c'est j1 qui a gagné" if random.randint(1, 2) == 1:
gain.enfiler(j1.defiler())
while not gain.est_vide(): gain.enfiler(j2.defiler())
j1.enfiler(gain.defiler()) else:
elif resultat == -1: gain.enfiler(j2.defiler())
winner = "c'est j2 qui a gagné" gain.enfiler(j1.defiler())
c1 = j1.defiler()
c2 = j2.defiler()
if random.randint(1, 2) == 1:
gain.enfiler(c2)
gain.enfiler(c1)
else:
gain.enfiler(c1)
gain.enfiler(c2)
resultat = c1.compare(c2)
if resultat == 1:
winner = "c'est j1 qui a gagné"
while not gain.est_vide(): while not gain.est_vide():
j2.enfiler(gain.defiler()) j1.enfiler(gain.defiler())
else: elif resultat == -1:
if j1.taille() < 2 and not j2.taille() < 2:
winner = "c'est j2 qui a gagné"
elif not j1.taille() < 2 and j2.taille() < 2:
winner = "c'est j2 qui a gagné" winner = "c'est j2 qui a gagné"
while not gain.est_vide():
j2.enfiler(gain.defiler())
else: else:
winner = "égalité" if j1.taille() < 2 and not j2.taille() < 2:
break winner = "c'est j2 qui a gagné"
print(j1, j2) elif not j1.taille() < 2 and j2.taille() < 2:
return winner winner = "c'est j2 qui a gagné"
else:
winner = "égalité"
break
print(j1, j2)
return winner"""
if __name__ == "__main__":
jeu = Jeux(8) jeu = Jeux()
j1, j2 = jeu.distribue() j1, j2 = jeu.distribue()
print(partie_TeSt(j1, j2)) #print(partie_TeSt(j1, j2))
print(j1, j2)
Loading…
Cancel
Save