您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
此存儲庫已封存,您能瀏覽檔案及複製此存儲庫,但不能推送、建立問題及拉取請求。

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import turtle
  2. class Robot:
  3. def __init__(self):
  4. self.direction = "nord"
  5. self.x = 0
  6. self.y = 0
  7. def avance(self):
  8. pass
  9. def tourne_gauche(self):
  10. pass
  11. def tourne_droite(self):
  12. pass
  13. class Simulation:
  14. def __init__(self):
  15. self.robot = Robot()
  16. def démarre(self):
  17. turtle.goto(0, 0)
  18. turtle.setheading(90)
  19. turtle.pendown()
  20. turtle.listen()
  21. self.connecte_touches()
  22. turtle.mainloop()
  23. def connecte_touches(self):
  24. turtle.onkey(self.avance_robot, "Up")
  25. turtle.onkey(self.tourne_robot_gauche, "Left")
  26. turtle.onkey(self.tourne_robot_droite, "Right")
  27. turtle.onkey(self.quitte, "q")
  28. def quitte(self):
  29. turtle.bye()
  30. def avance_robot(self):
  31. self.robot.avance()
  32. self.affiche_robot()
  33. def tourne_robot_droite(self):
  34. self.robot.tourne_droite()
  35. self.affiche_robot()
  36. def tourne_robot_gauche(self):
  37. self.robot.tourne_gauche()
  38. self.affiche_robot()
  39. def affiche_robot(self):
  40. turtle.goto(self.robot.x * 10, self.robot.y * 10)
  41. heading = {"nord": 90, "est": 0, "sud": 270, "ouest": 180}[self.robot.direction]
  42. turtle.setheading(heading)
  43. def main():
  44. simulation = Simulation()
  45. simulation.démarre()
  46. main()