Browse Source

Transférer les fichiers vers ''

Mon quoicoubébou Uwu
master
DELPUI Loïc 12 months ago
parent
commit
b87f611dfe
  1. 69
      projet bataille.py

69
projet bataille.py

@ -34,7 +34,33 @@ class Jeux:
player.enfiler(self.paquet.pop(0))
def click(event):
print("ok")
x, y = event.x, event.y
if x > 50 and x < 150 and y > 100 and y < 250:
cartes_tour = []
cartes_tour.extend([players[0].defiler(), players[1].defiler()])
winner = cartes_tour[-2].compare(cartes_tour[-1])
if winner == 2:
pass
else:
for carte in cartes_tour:
players[winner].enfiler(carte)
for i in range(2):
canvas.itemconfig(player_carte[i], text = cartes_tour[i].valeur + cartes_tour[i].couleur)
canvas.itemconfig(player_left[i], text = "Left : " + str(players[i].taille()))
if cartes_tour[i].couleur in ["", ""]:
canvas.itemconfig(player_carte[i], fill = "#f00")
else:
canvas.itemconfig(player_carte[i], fill = "#000")
couleurs = ["", "", "", ""]
numeros = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "R", "S"]
jeu = Jeux(52)
players = [File_chaine(), File_chaine()]
jeu.distribue()
window = Tk()
window.title("Bataille")
@ -43,41 +69,14 @@ window.geometry(f"700x400+300+200")
canvas = Canvas(window, width = 650, height = 300, background = "#fff")
canvas.place(x = 25, y = 50)
player1_pack = canvas.create_rectangle(50, 100, 150, 250, fill = "#f77")
player1_carte = canvas.create_rectangle(200, 75, 300, 225, fill = "#fff")
canvas.create_rectangle(50, 100, 150, 250, fill = "#f77")
canvas.create_rectangle(200, 75, 300, 225, fill = "#fff")
canvas.create_rectangle(500, 100, 600, 250, fill = "#f77")
canvas.create_rectangle(350, 75, 450, 225, fill = "#fff")
player2_pack = canvas.create_rectangle(500, 100, 600, 250, fill = "#f77")
player2_carte = canvas.create_rectangle(350, 75, 450, 225, fill = "#fff")
player_left = [canvas.create_text(100, 175, text = "Left : " + str(players[0].taille())), canvas.create_text(550, 175, text = "Left : " + str(players[1].taille()))]
player_carte = [canvas.create_text(250, 150, text = "", font = ("Courrier New", 30, "bold")), canvas.create_text(400, 150, text = "", font = ("Courrier New", 30, "bold"))]
canvas.bind("<Button 1>", click)
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()]
next_game = [[], []]
jeu.distribue()
while not (players[0].est_vide() and len(next_game[0])!=0 or players[1].est_vide() and len(next_game[1])!=0):
cartes_tour = []
cartes_tour.extend([players[0].defiler(), players[1].defiler()])
winner = cartes_tour[-2].compare(cartes_tour[-1])
if winner == 2:
pass
else:
next_game[winner].extend(cartes_tour)
for player_id in range(2):
if players[player_id].est_vide() and len(next_game[player_id])==0:
shuffle(next_game[player_id])
for i in next_game[player_id]:
players[player_id].enfiler(i)
next_game[player_id] = []
if players[0].est_vide():
print("Le joueur 1 a perdu", players[0].taille(), players[1].taille())
elif players[1].est_vide():
print("Le joueur 2 a perdu")
window.mainloop()
Loading…
Cancel
Save