Pièce jointe 178875
Je voudrais que lorsque un pion arrive sur un case et qu'il saute automatiquement encore de deux case .Enfaite c'est un jeu de l'oie que je fait donc
SVP aide moi ! Je suis une débutante pas très douée dans la programmation .Est ce que quelqu'un aurait la gentillesse de m'aider . Je vous en remercie





Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
from tkinter import *
import random
 
 
def NouveauLance():
    global nb
    nb = random.randint(1,6)
    Texte.set(str(nb))
 
 
def Clavier():
    global PosX,PosY
    global nb
    NouveauLance()
    valeur=int(nb)
    # déplacement vers la gauche
    PosY -= 0
    PosX -= -50*valeur
    # on dessine le pion à sa nouvelle position
    Canevas.coords(Pion,PosX -10, PosY +10, PosX+10,PosY -10)
    if PosX==-480:
        PosY -=10*valeur
        PosX -=-480
 
 
 
 
# Création de la fenêtre principale
Mafenetre = Tk()
Mafenetre.title('Pion')
 
 
Texte = StringVar()
 
# position initiale du pion
PosX = 20
PosY = 420
nb=0
 
 
# Création d'un widget Canvas (zone graphique)
Largeur = 800
Hauteur = 500
Canevas = Canvas(Mafenetre, width = 800, height = 500, bg ='white')
 
 
Pion = Canevas.create_oval(PosX-10,PosY-10,PosX+10,PosY+10,width=2,outline='black',fill='red')
 
#1ere rangée de cases (déplacement vers la droite du pion)
case1= Canevas.create_rectangle(PosX+30, PosY+20,PosX+80,PosY-20,width=5,outline='black')
case2= Canevas.create_rectangle(PosX+80,PosY+20,PosX+130,PosY-20,width=5,outline='black')
case3= Canevas.create_rectangle(PosX+130,PosY+20,PosX+180,PosY-20,width=5,outline='black')
case4= Canevas.create_rectangle(PosX+180,PosY+20,PosX+230,PosY-20,width=5,outline='black')
case5= Canevas.create_rectangle(PosX+230,PosY+20,PosX+280,PosY-20,width=5,outline='black')
case6= Canevas.create_rectangle(PosX+280,PosY+20,PosX+330,PosY-20,width=5,outline='black')
case7= Canevas.create_rectangle(PosX+330,PosY+20,PosX+380,PosY-20,width=5,outline='black')
case8= Canevas.create_rectangle(PosX+380,PosY+20,PosX+430,PosY-20,width=5,outline='black')
case9= Canevas.create_rectangle(PosX+430,PosY+20,PosX+480,PosY-20,width=5,outline='black')
case10= Canevas.create_rectangle(PosX+480,PosY+20,PosX+530,PosY-20,width=5,outline='black')
case11= Canevas.create_rectangle(PosX+530,PosY+20,PosX+580,PosY-20,width=5,outline='black')
case12= Canevas.create_rectangle(PosX+580,PosY+20,PosX+630,PosY-20,width=5,outline='black')
case13= Canevas.create_rectangle(PosX+630,PosY+20,PosX+680,PosY-20,width=5,outline='black')
case14= Canevas.create_rectangle(PosX+680,PosY+20,PosX+730,PosY-20,width=5,outline='black')
case15= Canevas.create_rectangle(PosX+730,PosY+20,PosX+780,PosY-20,width=5,outline='black')
 
 
 
 
 
 
 
 
Canevas.focus_set()
Canevas.bind('<Key>',Clavier)
Canevas.pack(padx =5, pady =5)
 
 
 
# Création d'un widget Button (bouton Lancer)
BoutonLancer = Button(Mafenetre, text ='Lancer', command = Clavier)
 
# Positionnement du widget avec la méthode pack()
BoutonLancer.pack(side = LEFT, padx = 5, pady = 5)
 
# Création d'un widget Label (texte 'Résultat -> x')
LabelResultat = Label(Mafenetre, textvariable = Texte, fg ='red', bg ='white')
LabelResultat.pack(side = LEFT, padx = 5, pady = 5)
 
 
# Création d'un widget Button (bouton Quitter)
Button(Mafenetre, text ='Quitter', command = Mafenetre.destroy).pack(side=LEFT,padx=5,pady=5)
 
Mafenetre.mainloop()