1 pièce(s) jointe(s)
Problème évenements Turtle
Bonjour, pour un projet en ICN, je dois créer une sorte de snake en multi avec turtle
(vu que turtle c'est du tkinter c'est bien la bonne section ??? :roll: )
seulement, pour des raisons obscures, mon code ne marche pas, je soupçonne cependant les évenements d'y etre pour quelque chose
Code:
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
| # Créé par auxence.fromont, le 08/02/2018 en Python 3.4
# __ _______ _______ _____ ___ __
# /""\ /" \ /" "|(\" \|" \ /""\
# / \ |: |(: ______)|.\\ \ | / \
# /' /\ \ |_____/ ) \/ | |: \. \\ | /' /\ \
# // __' \ // / // ___)_ |. \ \. | // __' \
# / / \\ \ |: __ \ (: "|| \ \ | / / \\ \
# (___/ \___)|__| \___) \_______) \___|\____\)(___/ \___)
# ____ __ _ _ ____ ___ ____ ___ __ ____ ____
# / ___) / \ / )( \( _ \ / __)( __) / __)/ \( \( __)
# \___ \( O )) \/ ( ) /( (__ ) _) ( (__( O )) D ( ) _)
# (____/ \__/ \____/(__\_) \___)(____) \___)\__/(____/(____)
from turtle import *
# préparation du terrain
bgcolor("black") #couleur du fond
# tortues "balais"
color("white")
other = Turtle()
other.color("white")
left(90)
other.right(90)
# positionnement des joueurs
red = Turtle()
red.color("red")
blue = Turtle()
blue.left(180)
blue.color("blue")
red.forward(100)
blue.forward(100)
global red_heading
global blue_heading
blue_heading = "null"
red_heading = "haut"
# attributtion des vies
blue_live = 1
red_live = 1
# definition des fonctions
def haut__bleu() :
print("haut bleu")
blue_heading = "haut"
def bas_bleu() :
blue_heading ="bas"
def gauche_bleu() :
blue_heading ="gauche"
def droite_bleu() :
blue_heading ="droite"
def haut_rouge() :
red_heading = "haut"
def bas_rouge() :
red_heading ="bas"
def gauche_rouge() :
red_heading ="gauche"
def droite_rouge() :
red_heading ="droite"
def fin():
blue_live = 0
red_live = 0
listen()
onkeypress(haut_rouge,"z")
onkeypress(bas_rouge,"s")
onkeypress(gauche_rouge,"q")
onkeypress(droite_rouge,"d")
onkeypress(haut_rouge,"Up")
onkeypress(bas_rouge,"Down")
onkeypress(gauche_rouge,"Left")
onkeypress(droite_rouge,"Right")
onkeypress(fin,"r")
while blue_live + red_live > 1 : # tant que tt le monde vit
#déplacements
onkeypress(haut_rouge,"z")
onkeypress(bas_rouge,"s")
onkeypress(gauche_rouge,"q")
onkeypress(droite_rouge,"d")
onkeypress(haut_rouge,"Up")
onkeypress(bas_rouge,"Down")
onkeypress(gauche_rouge,"Left")
onkeypress(droite_rouge,"Right")
onkeypress(fin,"r")
if red_heading == "haut" :
red.setheading(90)
red.forward(3)
if red_heading == "bas" :
red.setheading(270)
red.forward(3)
if red_heading == "gauche" :
red.setheading(180)
red.forward(3)
if red_heading == "droite" :
red.setheading(0)
red.forward(3)
if blue == "haut" :
blue.setheading(90)
blue.forward(3)
if red_heading == "bas" :
blue.setheading(270)
blue.forward(3)
if blue_heading == "gauche" :
blue.setheading(180)
blue.forward(3)
if blue_heading == "droite" :
blue.setheading(0)
blue.forward(3)
blue_live = blue_live - 0.00001 #pour éviter que ça plante
mainloop() |
quelqu’un saurait me notifier l’erreur ? svp