@ -0,0 +1 @@ |
|||||
|
__pycache__ |
@ -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()) |
After Width: | Height: | Size: 440 B |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 623 B |
After Width: | Height: | Size: 596 B |
After Width: | Height: | Size: 630 B |
After Width: | Height: | Size: 583 B |
After Width: | Height: | Size: 554 B |
After Width: | Height: | Size: 679 B |
After Width: | Height: | Size: 608 B |
After Width: | Height: | Size: 634 B |
After Width: | Height: | Size: 533 B |
After Width: | Height: | Size: 612 B |
After Width: | Height: | Size: 618 B |
After Width: | Height: | Size: 625 B |
After Width: | Height: | Size: 525 B |
After Width: | Height: | Size: 610 B |
After Width: | Height: | Size: 453 B |
After Width: | Height: | Size: 609 B |
After Width: | Height: | Size: 606 B |
After Width: | Height: | Size: 513 B |
After Width: | Height: | Size: 510 B |
After Width: | Height: | Size: 520 B |
After Width: | Height: | Size: 531 B |
After Width: | Height: | Size: 463 B |
After Width: | Height: | Size: 553 B |
After Width: | Height: | Size: 558 B |
After Width: | Height: | Size: 578 B |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 478 B |
After Width: | Height: | Size: 474 B |
After Width: | Height: | Size: 486 B |
After Width: | Height: | Size: 494 B |
After Width: | Height: | Size: 435 B |
After Width: | Height: | Size: 505 B |
After Width: | Height: | Size: 511 B |
After Width: | Height: | Size: 508 B |
After Width: | Height: | Size: 440 B |
After Width: | Height: | Size: 457 B |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 463 B |
After Width: | Height: | Size: 474 B |
After Width: | Height: | Size: 411 B |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.0 KiB |
@ -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) |
||||
|
|
@ -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() |