1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| from tkinter import *
from random import *
Interface=Tk()
#Regles du jeu
def AfficheRegles():
def DetruireRegles():
Regles.configure(text="Règles",command=AfficheRegles)
TexteRegles.destroy()
TexteRegles=Label(Interface, text="Félicitations! Vous venez de gagner un voyage autour du monde! \n Mais votre voyage sera semé d'embuches et vous devrez \n faire marcher votre cerveau pour arriver le plus vite possible à* la fin de votre voyage.\n Bon voyage!\n Chaque joueur joue chacun son tour en lançant le dé.\n Suivant le nombre obtenu, le pion avance case par case. \n Pour chaque case il faut répondre à* une question avec plusieurs choix de réponse. \nSi la réponse est exacte le joueur peut relancer le dé.\nSinon le joueur suivant joue.\n Un joueur gagne lorsqu'il répond juste à* la dernière question.", font=("castellar", 10), fg="orangered")
TexteRegles.place(x=25,y=140)
Regles.configure(text="Enlever les règles",command=DetruireRegles)
Regles.place(x=350,y=350)
#Jeu
def AfficherJeu():
def lancer_de():
global R
R=randrange(1,7)
Resultat_de=Label(Interface,text="",width=15,fg='orangered')
Resultat_de.place(x=670,y=50)
Resultat_de.configure(text="Avancer de "+str(R))
#Nbre de joueur
def ValiderJoueurs():
Nbre=float(E.get())
global taillepion
if Nbre == 2:
P1=Canvas(Interface,bg="red",width=taillepion,height=taillepion)
P1.place(x=160,y=10)
P2=Canvas(Interface,bg="blue",width=taillepion,height=taillepion)
P2.place(x=190,y=10)
elif Nbre == 3:
P1=Canvas(Interface,bg="red",width=taillepion,height=taillepion)
P1.place(x=160,y=10)
P2=Canvas(Interface,bg="blue",width=taillepion,height=taillepion)
P2.place(x=190,y=10)
P3=Canvas(Interface,bg="green",width=taillepion,height=taillepion)
P3.place(x=220,y=10)
if Nbre == 4:
P1=Canvas(Interface,bg="red",width=taillepion,height=taillepion)
P1.place(x=160,y=10)
P2=Canvas(Interface,bg="blue",width=taillepion,height=taillepion)
P2.place(x=190,y=10)
P3=Canvas(Interface,bg="green",width=taillepion,height=taillepion)
P3.place(x=220,y=10)
P4=Canvas(Interface,bg="yellow",width=taillepion,height=taillepion)
P4.place(x=250,y=10)
#déplacement du pion
def Clic(event):
""" Gestion de l'événement Clic gauche """
global DETECTION_CLIC_SUR_OBJET
#position du pointeur de la souris
X=event.x
Y=event.y
#coordonnées de l'objet
[xmin,ymin,xmax,ymax] = C.coords(P1)
if xmin<=X<=xmax and ymin<=Y<=ymax:
DETECTION_CLIC_SUR_OBJET = True
else: DETECTION_CLIC_SUR_OBJET = False
def Drag(event):
""" Gestion de l'événement bouton gauche enfoncé """
X = event.x
Y = event.y
if DETECTION_CLIC_SUR_OBJET == True:
# limite de l'objet dans la zone graphique
if X<0: X=0
if X>Largeur: X=Largeur
if Y<0: Y=0
if Y>Hauteur: Y=Hauteur
# mise à jour de la position de l'objet (drag)
P1.coords(P1,X-taillepion,Y-taillepion,X+taillepion,Y+taillepion)
DETECTION_CLIC_SUR_OBJET = False
#Côté droit
F1=Canvas(Interface,bg="rosybrown",width=150,height=500)
F1.pack()
F1.place(x=0,y=0)
#Côté gauche
F2=Canvas(Interface,bg="rosybrown",width=150,height=500)
F2.pack()
F2.place(x=650,y=0)
#Plateau de jeu
C=Canvas(Interface,bg="white", width=500,height=500)
C.pack()
C.place(x=150,y=0)
#Nombre de joueurs
L=Label(Interface,text="Nombre de joueurs",fg='orangered')
L.place(x=10,y=10)
E=Entry(Interface)
E.place(x=10,y=50)
V=Button(Interface,text="Valider",bg='gray',command=ValiderJoueurs,fg='red')
V.place(x=10,y=100)
#Dé
De=Button(Interface, text='Lancer le dé',command=lancer_de,fg='orangered')
De.place(x=680,y=10)
Quitter=Button(Interface, text="Quitter", command=Interface.destroy, font="castellar", fg="orangered")
Quitter.place(x=680, y=460)
##La méthode bind() permet de lier un événement avec une fonction
P1=Canvas(Interface,bg="red",width=taillepion,height=taillepion)
P1.bind('<Button-1>',Clic) # évévement clic gauche (press)
P1.bind('<B1-Motion>',Drag) # événement bouton gauche enfoncé (hold down)
P1.focus_set()
P1.pack(padx=10,pady=10)
#Interface du jeu
Interface.title("Tour du monde")
Interface.configure(bg="rosybrown", width=800, height=500)
Terre=PhotoImage(file="IMG6.gif")
Fond=Canvas(Interface, width=800, height=500)
Fond.place(x=0,y=0)
Fond.create_image(400, 250, image=Terre)
Titre=Label(Interface, text="Tour du monde", font=("castellar", 20), fg="orangered")
Titre.place(x=260,y=10)
Quitter=Button(Interface, text="Quitter", command=Interface.destroy, font="castellar", fg="orangered")
Quitter.place(x=700, y=460)
#Apparition des règles
Regles=Button(Interface, text="Règles", font="castellar", fg="orangered",command=AfficheRegles)
Regles.place(x=350, y=350)
#Apparition du jeu
Jouer=Button(Interface, text="Jouer", command=AfficherJeu, font="castellar", fg="orangered")
Jouer.place(x=350, y=200)
#taille d'un pion
taillepion=25
Interface.mainloop() |
Partager