[python] Turtle Escape- TDEJ
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import turtle as trtl
- import random as rand
- wall_color = "darkgreen"
- num_sides = 23
- path_width = 24
- def draw_door(pos):
- maze_painter.forward(pos)
- maze_painter.penup()
- maze_painter.forward(path_width*2)
- maze_painter.pendown()
- def draw_barrier(pos):
- maze_painter.forward(pos)
- maze_painter.left(90)
- maze_painter.forward(path_width*2)
- maze_painter.backward(path_width*2)
- maze_painter.right(90)
- def move_forward():
- player.forward(5)
- def move_up():
- player.setheading(90)
- move_forward()
- def move_down():
- player.setheading(270)
- move_forward()
- def move_left():
- player.setheading(180)
- move_forward()
- def move_right():
- player.setheading(0)
- move_forward()
- maze_painter = trtl.Turtle()
- maze_painter.pencolor(wall_color)
- maze_painter.speed(0)
- maze_painter.pensize(3)
- maze_painter.penup()
- maze_painter.goto(path_width*2, -path_width*2)
- maze_painter.pendown()
- player = trtl.Turtle(shape="turtle")
- player.fillcolor("red")
- player.pensize(5)
- player.penup()
- player.goto(-path_width*2, path_width*2)
- #player.pendown()
- wall_len = path_width
- for w in range(num_sides):
- wall_len += path_width
- if (w > 4):
- maze_painter.left(90)
- #value a should be less than b
- door = rand.randint(path_width*2, (wall_len - path_width*2))
- barrier = rand.randint(path_width*2, (wall_len - path_width*2))
- while abs(door - barrier) < path_width:
- door = rand.randint(path_width*2, (wall_len - path_width*2))
- if (door < barrier):
- draw_door(door)
- draw_barrier(barrier - door - path_width*2)
- maze_painter.forward(wall_len - barrier)
- else:
- draw_barrier(barrier)
- draw_door(door - barrier)
- maze_painter.forward(wall_len - door - path_width*2)
- maze_painter.hideturtle()
- wn = trtl.Screen()
- wn.onkeypress(move_up, 'w')
- wn.onkeypress(move_down, 's')
- wn.onkeypress(move_left, 'a')
- wn.onkeypress(move_right, 'd')
- wn.listen()
- wn.bgcolor("lightBlue")
- wn.mainloop()
Editor
You can edit this paste and save as new: