From e179735c331ada659879a2bdd28293dce5496a82 Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Sat, 7 Dec 2019 11:57:48 +0100 Subject: [PATCH] =?UTF-8?q?simulation=20de=20robot:=20code=20de=20d=C3=A9p?= =?UTF-8?q?art?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- saison-2/sources/robots/simulateur/départ.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 saison-2/sources/robots/simulateur/départ.py diff --git a/saison-2/sources/robots/simulateur/départ.py b/saison-2/sources/robots/simulateur/départ.py new file mode 100644 index 0000000..b87ce09 --- /dev/null +++ b/saison-2/sources/robots/simulateur/départ.py @@ -0,0 +1,68 @@ +import turtle + + +class Robot: + def __init__(self): + self.direction = "nord" + self.x = 0 + self.y = 0 + + def avance(self): + pass + + def tourne_gauche(self): + pass + + def tourne_droite(self): + pass + + + + +class Simulation: + def __init__(self): + self.robot = Robot() + + def démarre(self): + turtle.goto(0, 0) + turtle.setheading(90) + turtle.pendown() + + turtle.listen() + + self.connecte_touches() + turtle.mainloop() + + def connecte_touches(self): + turtle.onkey(self.avance_robot, "Up") + turtle.onkey(self.tourne_robot_gauche, "Left") + turtle.onkey(self.tourne_robot_droite, "Right") + turtle.onkey(self.quitte, "q") + + def quitte(self): + turtle.bye() + + def avance_robot(self): + self.robot.avance() + self.affiche_robot() + + def tourne_robot_droite(self): + self.robot.tourne_droite() + self.affiche_robot() + + def tourne_robot_gauche(self): + self.robot.tourne_gauche() + self.affiche_robot() + + def affiche_robot(self): + turtle.goto(self.robot.x * 10, self.robot.y * 10) + heading = {"nord": 90, "est": 0, "sud": 270, "ouest": 180}[self.robot.direction] + turtle.setheading(heading) + + +def main(): + simulation = Simulation() + simulation.démarre() + + +main()