Forum Programmation.python [AIDE] projet python jeu de domino

Posté par  . Licence CC By‑SA.
Étiquettes :
-1
14
nov.
2021

Bonjour,

Je travaille sur un projet python de jeu de domino à rendre pour demain. C'est super important pour mon orientation mais je suis bloquée.
Je dois utiliser le module tkinter et créer une fenêtre de saisir de mot de passe pour pouvoir entrer dans le jeu (elle est créée mais je n'arrive pas à définir le mot de passe à l'intérieur et afficher "veuillez ressayer" si le mot de passe est incorrect. Au niveau du reste du programme je dois afficher 2 fenêtres tkinter pour la saisie des noms des deux joueurs cela fonctionne.

Je dois ensuite réaliser le plateau de jeu avec les boutons en bas j'ai rattaché chaque bouton à une fonction mais ces boutons ne fonctionnent pas car je ne parvient pas à faire fonctionner les fonctions derrière. Les boutons sont piocher rejouer commencer et abandonner.
Ce projet est super important toute aide est la bienvenue. Au niveau du jeu notre professeur ne veut pas que l'on utilise la bibliothèque pygame et nous a imposé de mettre des photos pour chaque domino. Ce pourquoi j'ai créé un dossier compréssé nommé domino avec chacun des 28 dominos.
Voici mon programme ci-dessous aidez moi svp je suis foutu sinon. Pour toute question/info contactez moi en mp.

Mon code ci-dessous :

import tkinter as TK
from tkinter import Canvas #Pour éviter d'écrire TK.Canvas
from PIL import Image
import time as tm
import random

domino=['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','.\domino\domino-2_0.PNG','.\domino\domino-3_0.PNG','.\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','.\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']


def START(*args):
    print("start function")
    Domino = ['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']
    noms[0] = []
    Rnd_1 = []

    for j in range(6):
        while(1):
            idx = random.randint(1,27)
            if idx not in Rnd_1:
                noms[0].append(Pdmn(Domino[idx]))
                Rnd_1.append(idx)
                break

    noms[1] = []
    Rnd_2 = Rnd_1.copy()

    for j in range(6):
        while(1):
            idx = random.randint(1,27)
            if idx not in Rnd_2:
                noms[1].append(Pdmn(Domino[idx]))
                Rnd_2.append(idx)
                break
        photo=TK.PhotoImage(file=".\domino\domino-00.PNG") #ou 0_0
        photo.resize((40,40), Image.ANTIALIAS)
        canvas.create_image(100,300, image = photo)

    return

def ABANDON(*args):
        print("hey")
        return

def PIOCHER(dominoafficher):
   x=random.randint(0, 27)
   dominoafficher=PhotoImage(file=domino[x])
   #Canevas.create_image(50,50, image=domnioafficher)
   canvas.create_image(50,50,image=dominoafficher)


def REJOUER(*args):
    print("rejouer")
    return

def QUITTER(*args):
    global fen
    fen.destroy()



if __name__=='__main__':
    noms=[]
    for joueurs in range(2):
        def show():
            nom = Nom_du_joueur.get()
            noms.append(nom)
            #print(p)
            app.destroy()

        app = TK.Tk()
        app.title("Saisie nom des joueurs")
        app.geometry('400x400')
        canvas=TK.Canvas(background="#B0E0E6",height=300,width=300)
        img0=TK.PhotoImage(file="C:\\Users\\leila\\OneDrive\\Bureau\\joueur_image.PNG")
        canvas.create_image(150,150,image=img0)
        canvas.pack()
        Nom_du_joueur = TK.StringVar()
        nomEntry = TK.Entry(app, textvariable=Nom_du_joueur).pack()
        sumbmit = TK.Button(app, text='Saisir le nom des joueurs',command=show).pack()
        app.mainloop()

    print(noms)

fen = TK.Tk()
fen.title("Jeu de Domino")
canvas=Canvas(fen,width=600,height=600,background='#B0E0E6')

#1ère ligne du quadrillage
c11=Canvas.create_rectangle(canvas,100,100,140,140, fill="white")
c12=Canvas.create_rectangle(canvas,140,100,180,140, fill="white")
c13=Canvas.create_rectangle(canvas,180,100,220,140, fill="white")
c14=Canvas.create_rectangle(canvas,220,100,260,140, fill="white")
c15=Canvas.create_rectangle(canvas,260,100,300,140, fill="white")
c16=Canvas.create_rectangle(canvas,300,100,340,140, fill="white")
c17=Canvas.create_rectangle(canvas,340,100,380,140, fill="white")
c18=Canvas.create_rectangle(canvas,380,100,420,140, fill="white")
c19=Canvas.create_rectangle(canvas,420,100,460,140, fill="white")
c1A=Canvas.create_rectangle(canvas,460,100,500,140, fill="white")

#2ème ligne
c21=Canvas.create_rectangle(canvas,100,140,140,180, fill="white")
c22=Canvas.create_rectangle(canvas,140,140,180,180, fill="white")
c23=Canvas.create_rectangle(canvas,180,140,220,180, fill="white")
c24=Canvas.create_rectangle(canvas,220,140,260,180, fill="white")
c25=Canvas.create_rectangle(canvas,260,140,300,180, fill="white")
c26=Canvas.create_rectangle(canvas,300,140,340,180, fill="white")
c27=Canvas.create_rectangle(canvas,340,140,380,180, fill="white")
c28=Canvas.create_rectangle(canvas,380,140,420,180, fill="white")
c29=Canvas.create_rectangle(canvas,420,140,460,180, fill="white")
c2A=Canvas.create_rectangle(canvas,460,140,500,180, fill="white")

#3ème ligne
c31=Canvas.create_rectangle(canvas,100,180,140,220, fill="white")
c32=Canvas.create_rectangle(canvas,140,180,180,220, fill="white")
c33=Canvas.create_rectangle(canvas,180,180,220,220, fill="white")
c34=Canvas.create_rectangle(canvas,220,180,260,220, fill="white")
c35=Canvas.create_rectangle(canvas,260,180,300,220, fill="white")
c36=Canvas.create_rectangle(canvas,300,180,340,220, fill="white")
c37=Canvas.create_rectangle(canvas,340,180,380,220, fill="white")
c38=Canvas.create_rectangle(canvas,380,180,420,220, fill="white")
c39=Canvas.create_rectangle(canvas,420,180,460,220, fill="white")
c3A=Canvas.create_rectangle(canvas,460,180,500,220, fill="white")

#4ème ligne
c41=Canvas.create_rectangle(canvas,100,220,140,260, fill="white")
c42=Canvas.create_rectangle(canvas,140,220,180,260, fill="white")
c43=Canvas.create_rectangle(canvas,180,220,220,260, fill="white")
c44=Canvas.create_rectangle(canvas,220,220,260,260, fill="white")
c45=Canvas.create_rectangle(canvas,260,220,300,260, fill="white")
c46=Canvas.create_rectangle(canvas,300,220,340,260, fill="white")
c47=Canvas.create_rectangle(canvas,340,220,380,260, fill="white")
c48=Canvas.create_rectangle(canvas,380,220,420,260, fill="white")
c49=Canvas.create_rectangle(canvas,420,220,460,260, fill="white")
c4A=Canvas.create_rectangle(canvas,460,220,500,260, fill="white")

#5ème ligne
c51=Canvas.create_rectangle(canvas,100,260,140,300, fill="white")
c52=Canvas.create_rectangle(canvas,140,260,180,300, fill="white")
c53=Canvas.create_rectangle(canvas,180,260,220,300, fill="white")
c54=Canvas.create_rectangle(canvas,220,260,260,300, fill="white")
c55=Canvas.create_rectangle(canvas,260,260,300,300, fill="white")
c56=Canvas.create_rectangle(canvas,300,260,340,300, fill="white")
c57=Canvas.create_rectangle(canvas,340,260,380,300, fill="white")
c58=Canvas.create_rectangle(canvas,380,260,420,300, fill="white")
c59=Canvas.create_rectangle(canvas,420,260,460,300, fill="white")
c5A=Canvas.create_rectangle(canvas,460,260,500,300, fill="white")

#6ème ligne
c61=Canvas.create_rectangle(canvas,100,300,140,340, fill="white")
c62=Canvas.create_rectangle(canvas,140,300,180,340, fill="white")
c63=Canvas.create_rectangle(canvas,180,300,220,340, fill="white")
c64=Canvas.create_rectangle(canvas,220,300,260,340, fill="white")
c65=Canvas.create_rectangle(canvas,260,300,300,340, fill="white")
c66=Canvas.create_rectangle(canvas,300,300,340,340, fill="white")
c67=Canvas.create_rectangle(canvas,340,300,380,340, fill="white")
c68=Canvas.create_rectangle(canvas,380,300,420,340, fill="white")
c69=Canvas.create_rectangle(canvas,420,300,460,340, fill="white")
c6A=Canvas.create_rectangle(canvas,460,300,500,340, fill="white")

#7ème ligne
c71=Canvas.create_rectangle(canvas,100,340,140,380, fill="white")
c72=Canvas.create_rectangle(canvas,140,340,180,380, fill="white")
c73=Canvas.create_rectangle(canvas,180,340,220,380, fill="white")
c74=Canvas.create_rectangle(canvas,220,340,260,380, fill="white")
c75=Canvas.create_rectangle(canvas,260,340,300,380, fill="white")
c76=Canvas.create_rectangle(canvas,300,340,340,380, fill="white")
c77=Canvas.create_rectangle(canvas,340,340,380,380, fill="white")
c78=Canvas.create_rectangle(canvas,380,340,420,380, fill="white")
c79=Canvas.create_rectangle(canvas,420,340,460,380, fill="white")
c7A=Canvas.create_rectangle(canvas,460,340,500,380, fill="white")

#8ème ligne
c81=Canvas.create_rectangle(canvas,100,380,140,420, fill="white")
c82=Canvas.create_rectangle(canvas,140,380,180,420, fill="white")
c83=Canvas.create_rectangle(canvas,180,380,220,420, fill="white")
c84=Canvas.create_rectangle(canvas,220,380,260,420, fill="white")
c85=Canvas.create_rectangle(canvas,260,380,300,420, fill="white")
c86=Canvas.create_rectangle(canvas,300,380,340,420, fill="white")
c87=Canvas.create_rectangle(canvas,340,380,380,420, fill="white")
c88=Canvas.create_rectangle(canvas,380,380,420,420, fill="white")
c89=Canvas.create_rectangle(canvas,420,380,460,420, fill="white")
c8A=Canvas.create_rectangle(canvas,460,380,500,420, fill="white")

#9ème ligne
c91=Canvas.create_rectangle(canvas,100,420,140,460, fill="white")
c92=Canvas.create_rectangle(canvas,140,420,180,460, fill="white")
c93=Canvas.create_rectangle(canvas,180,420,220,460, fill="white")
c94=Canvas.create_rectangle(canvas,220,420,260,460, fill="white")
c95=Canvas.create_rectangle(canvas,260,420,300,460, fill="white")
c96=Canvas.create_rectangle(canvas,300,420,340,460, fill="white")
c97=Canvas.create_rectangle(canvas,340,420,380,460, fill="white")
c98=Canvas.create_rectangle(canvas,380,420,420,460, fill="white")
c99=Canvas.create_rectangle(canvas,420,420,460,460, fill="white")
c9A=Canvas.create_rectangle(canvas,460,420,500,460, fill="white")


#dernière ligne
cA1=Canvas.create_rectangle(canvas,100,460,140,500, fill="white")
cA2=Canvas.create_rectangle(canvas,140,460,180,500, fill="white")
cA3=Canvas.create_rectangle(canvas,180,460,220,500, fill="white")
cA4=Canvas.create_rectangle(canvas,220,460,260,500, fill="white")
cA5=Canvas.create_rectangle(canvas,260,460,300,500, fill="white")
cA6=Canvas.create_rectangle(canvas,300,460,340,500, fill="white")
cA7=Canvas.create_rectangle(canvas,340,460,380,500, fill="white")
cA8=Canvas.create_rectangle(canvas,380,460,420,500, fill="white")
cA9=Canvas.create_rectangle(canvas,420,460,460,500, fill="white")
cAA=Canvas.create_rectangle(canvas,460,460,500,500, fill="white")

font3=('Times',30,'bold')

Canvas.create_text(canvas, 300, 55, text="SCORE", font=font3, fill="#517369")
Canvas.create_text(canvas, 50, 55, text="00", font=font3, fill="#517369")
Canvas.create_text(canvas, 550, 55, text="00", font=font3, fill="#517369")
Canvas.create_text(canvas, 50, 105, text=noms[0])
Canvas.create_text(canvas, 550, 105, text=noms[1])

d11=Canvas.create_rectangle(canvas,30,140,70,180, fill="white")
d12=Canvas.create_rectangle(canvas,30,190,70,230, fill="white")
d13=Canvas.create_rectangle(canvas,30,240,70,280, fill="white")
d14=Canvas.create_rectangle(canvas,30,290,70,330, fill="white")
d15=Canvas.create_rectangle(canvas,30,340,70,380, fill="white")
d16=Canvas.create_rectangle(canvas,30,390,70,430, fill="white")
d17=Canvas.create_rectangle(canvas,30,440,70,480, fill="white")

d21=Canvas.create_rectangle(canvas,530,140,570,180, fill="white")
d22=Canvas.create_rectangle(canvas,530,190,570,230, fill="white")
d23=Canvas.create_rectangle(canvas,530,240,570,280, fill="white")
d24=Canvas.create_rectangle(canvas,530,290,570,330, fill="white")
d25=Canvas.create_rectangle(canvas,530,340,570,380, fill="white")
d26=Canvas.create_rectangle(canvas,530,390,570,430, fill="white")
d27=Canvas.create_rectangle(canvas,530,440,570,480, fill="white")

#Ajouter le bouton start
B1=Canvas.create_rectangle(canvas,60,530,130,580, fill="#6db4bf", tags = "START-Button")
B2=Canvas.create_rectangle(canvas,160,530,230,580, fill="#6db4bf", tags = "ABANDON-Button")
B3=Canvas.create_oval(canvas,250,520,340,590, fill="#6db4bf", tags = "PIOCHER-Button")
B4=Canvas.create_rectangle(canvas,360,530,430,580, fill="#6db4bf", tags = "REJOUER-Button")
B5=Canvas.create_rectangle(canvas,460,530,530,580, fill="#6db4bf", tags = "QUITTER-Button")

font1=('Calibri',11,'bold')

#Ajouter le nom de chaque bouton

Canvas.create_text(canvas, 95, 555, text= "START",font=font1, fill="white", tags = "START-Button")
Canvas.create_text(canvas, 195, 555, text= "ABANDON",font=font1, fill="white", tags = "ABANDON-Button")
Canvas.create_text(canvas, 295, 555, text= "PIOCHER",font=font1, fill="white", tags = "PIOCHER-Button")
Canvas.create_text(canvas, 395, 555, text= "REJOUER",font=font1, fill="white", tags = "REJOUER-Button")
Canvas.create_text(canvas, 495, 555, text= "QUITTER",font=font1, fill="white", tags = "QUITTER-Button")
canvas.pack()


#Ajout des actions aux boutons
canvas.tag_bind("START-Button","<Button-1>",START)
canvas.tag_bind("ABANDON-Button","<Button-1>",ABANDON)
canvas.tag_bind("PIOCHER-Button","<Button-1>",PIOCHER)
canvas.tag_bind("REJOUER-Button","<Button-1>",REJOUER)
canvas.tag_bind("QUITTER-Button","<Button-1>",QUITTER)


#canvas.pack()
fen.mainloop()


###--------------------------------CODE MOT DE PASSE---------------------------------------

from tkinter import *
import tkinter as tk

fen = tk.Tk()
fen.title("login")
fen.geometry("350x100")
fen.configure(bg = '#B0E0E6')
font2=('Times',16,'bold')

l1=tk.Label(fen,text='Mot de passe :',font=font2,bg='#B0E0E6')
l1.grid(row=1,column=1,padx=10,pady=10)
str=tk.StringVar()

e1 = tk.Entry(fen,font=font2,width=15,show='*',textvariable=str)
e1.grid(row=1,column=2,padx=5,pady=5)
c_v1=IntVar(value=0)


def my_show():
    if(c_v1.get()==1):
        e1.config(show='') #mot de passe visible
    else:
        e1.config(show='*') #mot de passe caché


c1=tk.Checkbutton(fen,text='Afficher',variable=c_v1,onvalue=1,offvalue=0,command=my_show,bg='#B0E0E6')

c1.grid(row=2,column=1)

fen.mainloop()

###

def saisie():
    #programme de saisie de mot de passe
    mot_de_passe = input("Entrer le mot de passe \n-->")
    if mot_de_passe != 'domino':
        saisie()
    else:
        print("Accès autorisé")

saisie()
  • # manque des libs ?

    Posté par  . Évalué à 2.

    Il doit manquer des librairies ?

  • # Résolu ?

    Posté par  . Évalué à 4. Dernière modification le 14 novembre 2021 à 18:35.

    Salut,

    Le cross-posting, c'est pas forcément bien vu (surtout si ce n'est pas indiqué), des personnes risquent de se pencher inutilement sur un problème qui n'en est plus un.

    Est-ce résolu comme indiqué ici ?

    Par ailleurs, ça aurait été bien d'indiquer ce qui posait problème, et la notion de mp n'existe pas ici. Et on ne fait pas de choses dans l'urgence, ce n'est pas de notre faute si c'est à rendre pour demain, ou important pour toi :)

    Matricule 23415

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.