|
|
@ -1,7 +1,8 @@ |
|
|
|
from tkinter import * |
|
|
|
from File import * |
|
|
|
from random import shuffle |
|
|
|
from time import sleep |
|
|
|
from tkinter import messagebox |
|
|
|
import sqlite3 |
|
|
|
|
|
|
|
class Carte: |
|
|
|
def __init__(self, valeur, couleur): |
|
|
@ -10,16 +11,14 @@ class Carte: |
|
|
|
def compare(self, other): |
|
|
|
#Les valeurs revoyées ne respectent pas les consignes pour des raisons d'optimisation et d'allègement du programme |
|
|
|
if self.valeur > other.valeur: |
|
|
|
return 0 |
|
|
|
elif self.valeur < other.valeur: |
|
|
|
return 1 |
|
|
|
elif self.valeur < other.valeur: |
|
|
|
return 0 |
|
|
|
return 2 |
|
|
|
|
|
|
|
class Jeux: |
|
|
|
def __init__ (self, nbr_cartes): |
|
|
|
self.nb = nbr_cartes |
|
|
|
if self.nb != 32 and self.nb != 52: |
|
|
|
raise ValueError("Choisissez 32 ou 52 cartes") |
|
|
|
self.paquet = [] |
|
|
|
for i in couleurs: |
|
|
|
if self.nb == 52: |
|
|
@ -36,6 +35,8 @@ class Jeux: |
|
|
|
player.enfiler(self.paquet.pop(0)) |
|
|
|
|
|
|
|
def click(event): |
|
|
|
global status, cartes_tour |
|
|
|
|
|
|
|
def afficher(): |
|
|
|
for i in range(2): |
|
|
|
canvas.itemconfig(player_cartecolor[i], fill = "#fff") |
|
|
@ -46,9 +47,6 @@ def click(event): |
|
|
|
else: |
|
|
|
canvas.itemconfig(player_carte[i], fill = "#000") |
|
|
|
|
|
|
|
def premiere_carte(): |
|
|
|
window.after(3000, retourne_carte) |
|
|
|
|
|
|
|
def retourne_carte(): |
|
|
|
for rep in range(2): |
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
@ -56,25 +54,46 @@ def click(event): |
|
|
|
canvas.itemconfig(player_cartecolor[i], fill = "#f77") |
|
|
|
canvas.itemconfig(player_carte[i], text = "") |
|
|
|
canvas.itemconfig(player_left[i], text = "Left : " + str(players[i].taille())) |
|
|
|
window.after(3000, prochaine_carte) |
|
|
|
|
|
|
|
def prochaine_carte(): |
|
|
|
for rep in range(2): |
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
afficher() |
|
|
|
if players[0].taille() == 0: |
|
|
|
messagebox.showinfo("Le joueur 2 a gagné", "LE JOUEUR 2 A GAGNÉ !") |
|
|
|
exit() |
|
|
|
if players[1].taille() == 0: |
|
|
|
messagebox.showinfo("Le joueur 1 a gagné", "LE JOUEUR 1 A GAGNÉ !") |
|
|
|
exit() |
|
|
|
|
|
|
|
x, y = event.x, event.y |
|
|
|
if x > 50 and x < 150 and y > 100 and y < 250: |
|
|
|
if status == 1: |
|
|
|
cartes_tour = [] |
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
while winner == 2: |
|
|
|
if winner == 2: |
|
|
|
status = 2 |
|
|
|
else: |
|
|
|
for carte in cartes_tour: |
|
|
|
players[winner].enfiler(carte) |
|
|
|
afficher() |
|
|
|
premiere_carte() |
|
|
|
elif status == 2: |
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
retourne_carte() |
|
|
|
status = 3 |
|
|
|
else: |
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
if winner == 2: |
|
|
|
status = 2 |
|
|
|
else: |
|
|
|
status = 1 |
|
|
|
for carte in cartes_tour: |
|
|
|
players[winner].enfiler(carte) |
|
|
|
afficher() |
|
|
|
Per1 = ("Joueur 1", str(players[0].taille()),) |
|
|
|
c.execute("INSERT INTO Cartes VALUES (?, ?)", Per1) |
|
|
|
Per2 = ("Joueur 2", str(players[1].taille()),) |
|
|
|
c.execute("INSERT INTO Cartes VALUES (?, ?)", Per2) |
|
|
|
c.execute("SELECT * FROM Cartes") |
|
|
|
conn.commit() |
|
|
|
|
|
|
|
couleurs = ["♥", "♦", "♣", "♠"] |
|
|
|
numeros = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "R", "S"] |
|
|
@ -83,10 +102,32 @@ numeros = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "R", "S"] |
|
|
|
#R=Roi |
|
|
|
#S=aS |
|
|
|
|
|
|
|
jeu = Jeux(52) |
|
|
|
def starting(nb_cartes): |
|
|
|
global jeu |
|
|
|
jeu = Jeux(nb_cartes) |
|
|
|
start.destroy() |
|
|
|
|
|
|
|
start = Tk() |
|
|
|
start_title = Label(start, text = "La Bataille", font = ("Courrier New", 30, "bold")) |
|
|
|
start_title.pack() |
|
|
|
button_32 = Button(start, text = "Jeu de 32 cartes", font = ("Courrier New", 20, "bold"), command = lambda: starting(32)) |
|
|
|
button_32.pack() |
|
|
|
button_52 = Button(start, text = "Jeu de 52 cartes", font = ("Courrier New", 20, "bold"), command = lambda: starting(52)) |
|
|
|
button_52.pack() |
|
|
|
start.mainloop() |
|
|
|
|
|
|
|
players = [File_chaine(), File_chaine()] |
|
|
|
|
|
|
|
conn = sqlite3.connect("Bataille.db") |
|
|
|
c = conn.cursor() |
|
|
|
c.execute('''CREATE TABLE if not exists Cartes(Joueur VARCHAR(255), NombreCartes INT)''') |
|
|
|
Per1 = ("Joueur 1", str(players[0].taille()),) |
|
|
|
c.execute("INSERT INTO Cartes VALUES (?, ?)", Per1) |
|
|
|
Per2 = ("Joueur 2", str(players[1].taille()),) |
|
|
|
c.execute("INSERT INTO Cartes VALUES (?, ?)", Per2) |
|
|
|
c.execute("SELECT * FROM Cartes") |
|
|
|
conn.commit() |
|
|
|
|
|
|
|
jeu.distribue() |
|
|
|
|
|
|
|
window = Tk() |
|
|
@ -102,6 +143,8 @@ player_cartecolor = [canvas.create_rectangle(200, 75, 300, 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"))] |
|
|
|
|
|
|
|
status = 1 |
|
|
|
|
|
|
|
canvas.bind("<Button 1>", click) |
|
|
|
|
|
|
|
window.mainloop() |