Advertisement
KozlovSergey

Labirint

May 5th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. from turtle import *
  2. from random import *
  3.  
  4. class Box(Turtle):
  5. def __init__(self, x, y):
  6. Turtle.__init__(self)
  7. self.speed(0)
  8. self.penup()
  9. self.shape("square")
  10. self.goto(x,y)
  11. self.iX = x/size
  12. self.iY = y/size
  13. self.c = "color"
  14.  
  15. s=Screen()
  16. s.tracer(0)
  17. size=22
  18. Box_list = []
  19.  
  20. for j in range(-10, 11):
  21. for i in range(-10, 11):
  22. Box_list.append(Box(i*size, j*size))
  23.  
  24. for box in Box_list:
  25. if abs(box.iX)==10:
  26. box.color("red")
  27. if abs(box.iY)==10:
  28. box.color("red")
  29.  
  30. def random_map():
  31. for box in Box_list:
  32. if box.iX % 2 == 0 and abs(box.iX) != 10 and abs(box.iY) != 10 and abs(box.iY) != 9:
  33. box.color("green")
  34. box.c = "green"
  35.  
  36. player = Turtle()
  37. player.speed(0)
  38. player.penup()
  39. player.shape("circle")
  40. player.color("blue")
  41. player.goto(9*size, -9*size)
  42.  
  43. def move_up():
  44. iY = player.ycor()/size
  45. if iY != 9:
  46. y = player.ycor() + size
  47. player.sety(y)
  48. s.update()
  49.  
  50. def move_down():
  51. iY = player.ycor()/size
  52. if iY != -9:
  53. y = player.ycor() - size
  54. player.sety(y)
  55. s.update()
  56.  
  57. def move_left():
  58. iX = player.xcor() / size
  59. if iX != -9:
  60. x = player.xcor() - size
  61. player.setx(x)
  62. s.update()
  63.  
  64. def move_right():
  65. iX = player.xcor()/size
  66. if iX != 9:
  67. x = player.xcor() + size
  68. player.setx(x)
  69. s.update()
  70.  
  71. def check_color():
  72. for box in Box_list:
  73. print(box.iX, box.iY, box.c)
  74. check_color()
  75.  
  76. s.listen()
  77. s.onkey(move_up, "w")
  78. s.onkey(move_down, "s")
  79. s.onkey(move_left, "a")
  80. s.onkey(move_right, "d")
  81. random_map()
  82.  
  83. s.update()
  84. s.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement