Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import *
- from random import *
- class Box(Turtle):
- def __init__(self, x, y):
- Turtle.__init__(self)
- self.speed(0)
- self.penup()
- self.shape("square")
- self.goto(x,y)
- self.iX = x/size
- self.iY = y/size
- self.c = "color"
- s=Screen()
- s.tracer(0)
- size=22
- Box_list = []
- for j in range(-10, 11):
- for i in range(-10, 11):
- Box_list.append(Box(i*size, j*size))
- for box in Box_list:
- if abs(box.iX)==10:
- box.color("red")
- if abs(box.iY)==10:
- box.color("red")
- def random_map():
- for box in Box_list:
- if box.iX % 2 == 0 and abs(box.iX) != 10 and abs(box.iY) != 10 and abs(box.iY) != 9:
- box.color("green")
- box.c = "green"
- player = Turtle()
- player.speed(0)
- player.penup()
- player.shape("circle")
- player.color("blue")
- player.goto(9*size, -9*size)
- def move_up():
- iY = player.ycor()/size
- if iY != 9:
- y = player.ycor() + size
- player.sety(y)
- s.update()
- def move_down():
- iY = player.ycor()/size
- if iY != -9:
- y = player.ycor() - size
- player.sety(y)
- s.update()
- def move_left():
- iX = player.xcor() / size
- if iX != -9:
- x = player.xcor() - size
- player.setx(x)
- s.update()
- def move_right():
- iX = player.xcor()/size
- if iX != 9:
- x = player.xcor() + size
- player.setx(x)
- s.update()
- def check_color():
- for box in Box_list:
- print(box.iX, box.iY, box.c)
- check_color()
- s.listen()
- s.onkey(move_up, "w")
- s.onkey(move_down, "s")
- s.onkey(move_left, "a")
- s.onkey(move_right, "d")
- random_map()
- s.update()
- s.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement