diff --git a/bataille.py b/bataille.py index 794742d..8b9399a 100644 --- a/bataille.py +++ b/bataille.py @@ -2,6 +2,7 @@ from File import File_chaine as File import random from time import sleep +#creation de la classe Carte qui ermet de comparer deux cartes entres elles class Carte: "carte" def __init__(self, valeur, couleur): @@ -17,14 +18,20 @@ class Carte: def __repr__(self): return str(self.valeur) 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: - def __init__(self, nbmax): + def __init__(self, nbmax=52): i = 0 valeurs = [1, 7, 8, 9, 10, 11, 12, 13, 2, 3, 4, 5, 6] - couleurs = ["coeur", "pique", "carreau", "trefle"] + couleurs = ["♥", "♠", "♦", "♣️"] jeu = [] for val in valeurs: if i >= nbmax: @@ -74,7 +81,7 @@ def partie(jeu1, jeu2): jeu2.enfiler(gain.defiler()) """ -class partie_TeSt: +"""class partie_TeSt: def __init__(self, nb_carte = 52): jeux = Jeux(nb_carte) self.j1, self.j2 = jeux.distribue() @@ -111,56 +118,57 @@ class partie_TeSt: while not self.Gain.est_vide(): self.j2.enfiler(self.Gain.defiler()) - while not (j1.est_vide() or j2.est_vide() or winner == "égalité"): - print(Round) - Round += 1 - - c1 = j1.defiler() - c2 = j2.defiler() + while not (j1.est_vide() or j2.est_vide() or winner == "égalité"): + print(Round) + Round += 1 - - 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() c2 = j2.defiler() - if random.randint(1, 2) == 1: - gain.enfiler(c2) - gain.enfiler(c1) - else: - gain.enfiler(c1) - gain.enfiler(c2) + + + gain = File() + 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(): - j1.enfiler(gain.defiler()) - elif resultat == -1: - winner = "c'est j2 qui a gagné" + 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() + 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(): - j2.enfiler(gain.defiler()) - else: - 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: + while not gain.est_vide(): + j1.enfiler(gain.defiler()) + elif resultat == -1: winner = "c'est j2 qui a gagné" + + while not gain.est_vide(): + j2.enfiler(gain.defiler()) else: - winner = "égalité" - break - print(j1, j2) - return winner + 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é" + else: + winner = "égalité" + break + print(j1, j2) + return winner""" - -jeu = Jeux(8) -j1, j2 = jeu.distribue() -print(partie_TeSt(j1, j2)) \ No newline at end of file +if __name__ == "__main__": + jeu = Jeux() + j1, j2 = jeu.distribue() + #print(partie_TeSt(j1, j2)) + print(j1, j2) \ No newline at end of file