Browse Source

Dépot : Modif

master
vandepoele.e 2 years ago
parent
commit
debffd12fc
  1. 1
      .gitignore
  2. 91
      Pile.py
  3. 39
      README.txt
  4. BIN
      img/1.png
  5. BIN
      img/10.png
  6. BIN
      img/11.png
  7. BIN
      img/12.png
  8. BIN
      img/13.png
  9. BIN
      img/14.png
  10. BIN
      img/15.png
  11. BIN
      img/16.png
  12. BIN
      img/17.png
  13. BIN
      img/18.png
  14. BIN
      img/19.png
  15. BIN
      img/2.png
  16. BIN
      img/20.png
  17. BIN
      img/21.png
  18. BIN
      img/22.png
  19. BIN
      img/23.png
  20. BIN
      img/24.png
  21. BIN
      img/25.png
  22. BIN
      img/26.png
  23. BIN
      img/27.png
  24. BIN
      img/28.png
  25. BIN
      img/29.png
  26. BIN
      img/3.png
  27. BIN
      img/30.png
  28. BIN
      img/31.png
  29. BIN
      img/32.png
  30. BIN
      img/33.png
  31. BIN
      img/34.png
  32. BIN
      img/35.png
  33. BIN
      img/36.png
  34. BIN
      img/37.png
  35. BIN
      img/38.png
  36. BIN
      img/39.png
  37. BIN
      img/4.png
  38. BIN
      img/40.png
  39. BIN
      img/41.png
  40. BIN
      img/42.png
  41. BIN
      img/43.png
  42. BIN
      img/44.png
  43. BIN
      img/45.png
  44. BIN
      img/46.png
  45. BIN
      img/47.png
  46. BIN
      img/48.png
  47. BIN
      img/49.png
  48. BIN
      img/5.png
  49. BIN
      img/50.png
  50. BIN
      img/51.png
  51. BIN
      img/52.png
  52. BIN
      img/6.png
  53. BIN
      img/7.png
  54. BIN
      img/8.png
  55. BIN
      img/9.png
  56. 14
      main.py
  57. 39
      window.py

1
.gitignore

@ -0,0 +1 @@
__pycache__

91
Pile.py

@ -0,0 +1,91 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from listeChaine import ListeChaine
class Pile_lst:
"""Implémentation d'une pile par une liste."""
def __init__(self):
"""Crée une pile vide."""
self.__pile = []
def est_vide(self):
"""Indique si la pile est vide."""
return self.__pile == []
def empiler(self, valeur):
"""Empile la valeur."""
self.__pile.append(valeur)
def depiler(self):
"""Dépile le sommet de la pile et le renvoie."""
return self.__pile.pop()
def taille(self):
"""Renvoie la taille de la pile."""
return len(self.__pile)
def sommet(self):
"""Renvoie le sommet de la pile (sans le dépiler)."""
return self.__pile[-1]
def __str__(self):
s = "|"
for val in self.__pile:
s = str(val) + "->" + s
return s
class Pile_chaine:
"""Implémentation d'une pile par une liste chaînée."""
def __init__(self):
"""Crée une pile vide."""
self.__pile = ListeChaine()
self.__taille = 0
def est_vide(self):
"""Indique si la pile est vide."""
return self.__taille == 0
def empiler(self, valeur):
"""Empile la valeur."""
self.__pile.ajoute(valeur)
self.__taille += 1
def depiler(self):
"""Dépile le sommet de la pile et le renvoie."""
if self.est_vide():
raise IndexError("Impossible de dépiler une pile vide.")
valeur = self.__pile.tete()
self.__pile = self.__pile.queue()
self.__taille -= 1
return valeur
def taille(self):
"""Renvoie la taille de la pile."""
return self.__taille
def sommet(self):
"""Renvoie le sommet de la pile (sans le dépiler)."""
if self.est_vide():
raise IndexError("Une pile vide n'a pas de sommet.")
return self.__pile.tete()
def __str__(self):
return str(self.__pile) + "->|"
if __name__ == "__main__":
p = Pile_lst()
print(p.est_vide())
p.empiler('A')
p.empiler('B')
p.empiler('C')
print(p.est_vide())
print(p.sommet())
print(p)
print(p.taille())
print(p.depiler())
print(p.depiler())
print(p.depiler())
print(p.est_vide())

39
README.txt

@ -2,23 +2,30 @@ Votre mission, si vous l’acceptez (et même si vous ne l’acceptez pas), est
utilisant une structure de donnée adaptée, et avec une interface graphique. Vous aurez pour cela 6 heures
(les trois séances jusqu’aux vacances de Noël).
Plus précisément, on attend au minimum :
• Une classe Carte ayant
– deux attributs valeur et couleur
– une méthode compare qui prend en paramètre une autre carte other, et qui renvoie
1 si la valeur de self est supérieure à la valeur de other ;
−1 si la valeur de other est supérieure à la valeur de self ;
0 si les deux valeurs sont les mêmes.
• Une classe Jeux ayant
– Un attribut paquet contenant toutes les cartes du jeux. Le nombre de cartes (32 ou 54) sera un paramètre
du constructeur. Ce paquet sera créé puis mélangé dans le constructeur.
– Une méthode distribue qui renvoie deux Files contenant la moitié des cartes du paquet chacune. On
utilisera la classe File du cours (disponible sur Moodle).
À chaque tour de jeu, chaque joueur joue la carte supérieure de son paquet. Le joueur ayant la carte de plus
grande valeur récupère les deux cartes et les remets sous son paquet.
En cas d’égalité, chaque joueur ajoute une carte à l’envers, puis une autre carte à l’endroit, et on compare à
nouveau les valeurs. En cas de nouvelle égalité, on réitère le processus. Le gagnant remporte l’ensemble des
cartes jouées.
• Une classe Carte ayant
– deux attributs valeur et couleur
– une méthode compare qui prend en paramètre une autre carte other, et qui renvoie: 1 si la valeur de self est supérieure à la valeur de other ;
−1 si la valeur de other est supérieure à la valeur de self ;
0 si les deux valeurs sont les mêmes.
• Une classe Jeux ayant
– Un attribut paquet contenant toutes les cartes du jeux. Le nombre de cartes (32 ou 52) sera un paramètre du constructeur. Ce paquet sera créé puis mélangé dans le constructeur.
– Une méthode distribue qui renvoie deux Files contenant la moitié des cartes du paquet chacune. On utilisera la classe File du cours (disponible sur Moodle).
À chaque tour de jeu, chaque joueur joue la carte supérieure de son paquet. Le joueur ayant la carte de plus grande valeur récupère les deux cartes et les remets sous son paquet.
En cas d’égalité, chaque joueur ajoute une carte à l’envers, puis une autre carte à l’endroit, et on compare à nouveau les valeurs. En cas de nouvelle égalité, on réitère le processus.
Le gagnant remporte l’ensemble des cartes jouées.
Si un joueur ne peut plus jouer car il n’a plus de carte, il a perdu la partie.
Concernant l’interface graphique, elle sera réalisée en Tkinter, et permettra de faire une partie contre l’or-
dinateur. Il n’est pas nécessaire d’afficher les cartes à un format graphique (même si ce n’est bien sûr pas
interdit) : on pourra se contenter de textes de la forme « 3 de carreau » ou « roi de pique ».

BIN
img/1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

BIN
img/10.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
img/11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
img/12.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/13.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
img/14.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/15.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/17.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

BIN
img/18.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

BIN
img/19.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

BIN
img/2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

BIN
img/20.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

BIN
img/21.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

BIN
img/22.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

BIN
img/23.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

BIN
img/24.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

BIN
img/25.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

BIN
img/26.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

BIN
img/27.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

BIN
img/28.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
img/29.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

BIN
img/3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

BIN
img/30.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

BIN
img/31.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

BIN
img/32.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

BIN
img/33.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

BIN
img/34.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

BIN
img/35.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

BIN
img/36.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
img/37.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

BIN
img/38.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

BIN
img/39.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

BIN
img/4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

BIN
img/40.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

BIN
img/41.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

BIN
img/42.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

BIN
img/43.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

BIN
img/44.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

BIN
img/45.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

BIN
img/46.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

BIN
img/47.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

BIN
img/48.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

BIN
img/49.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

BIN
img/5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/50.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
img/51.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

BIN
img/52.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
img/6.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/7.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
img/8.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
img/9.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

14
main.py

@ -0,0 +1,14 @@
from bataille import *
def bataille():
tour = 1
jeux = Jeux()
carte_j1, carte_j2 = jeux.depiler()
nom = str(input("Entrez votre nom"))
j1 = Joueur(carte_j1, nom)
j2 = Joueur(carte_j2, "Bot")
while not j1.paquet_j.est_vide() and not j2.paquet_j.est_vide():
valeur_carte_j1 = j1.tire_carte()
valeur_carte_j2 = j2.tire_carte()
carte_j1.compare(carte_j2)

39
window.py

@ -0,0 +1,39 @@
from tkinter import Tk, Label, Button
class Window(Tk):
def __init__(self, p1, p2):
"""Initialise la fenêtre et prends les deux joueurs en arguments"""
Tk.__init__(self)
self.title("Bataille")
self.minsize(1300, 600)
self.geometry("1300x600")
self.config(background="green")
self.build_window()
self.p1 = p1
self.p2 = p2
self.c1 = None
self.c2 = None
def build_window(self):
self.title = Label(text="Bataille", font=("Courrier", 32))
self.title.grid(row=1, column=1)
self.button = Button(self, text="Jouer") #, command=)
def show_cards(self):
if self.c1 is not None:
self.c1.destroy()
if self.c2 is not None:
self.c2.destroy()
self.c1 = Label(text=self.p1.derniere_carte, font=("Courrier", 48))
self.c2 = Label(text=self.p2.derniere_carte, font=("Courrier", 48))
self.c1.grid(row=2, column=0)
self.c2.grid(row=2, column=2)
if __name__ == "__main__":
app = Window(None, None)
app.show_cards()
app.mainloop()
Loading…
Cancel
Save