import turtle
import random
import time
t = turtle.Turtle()
t.ht()
def pixel(x,y,c,forward=100):
t.color(c)
t.penup()
t.goto(x, y)
t.pendown()
t.begin_fill()
for i in range(4):
t.forward(forward)
t.left(90)
t.end_fill()
turtle.tracer(False)
pixel(-50,-50,"pink")
pixel(-150,-50,"green")
pixel(50,-50,"blue")
pixel(-50,50,"yellow")
pixel(-50,-150,"red")
pixel(-150,50,"purple")
pixel(-150,-150,"grey")
pixel(50,50,"orange")
pixel(50,-150,"brown")
turtle.tracer(True)
t1=turtle.Turtle()
t1.shape("turtle")
def tur(a):
t1.penup()
t.ht()
if a == 1:
t1.goto(-100,100)
elif a==2:
t1.goto(0,100)
elif a==3:
t1.goto(100,100)
elif a==4:
t1.goto(-100,0)
elif a == 5:
t1.goto(0,0)
elif a==6:
t1.goto(100,0)
elif a==7:
t1.goto(-100,-100)
elif a==8:
t1.goto(0,-100)
elif a==9:
t1.goto(100,-100)
else:
print("你是怎么做到的?")
exit(0)
t1.pendown()
t1.showturtle()
time.sleep(1)
t1.ht()
t2 = turtle.Turtle()
t2.speed(0)
t2.color("violet")
t2.ht()
while True:
s=""
for x in range(4):
area = random.randint(1,9)
#print(area)
tur(area)
s += str(area)
a=input("请输入海龟的出现顺序:")
if a == s:
t2.penup()
t2.goto(-30,-200)
t2.pendown()
t2.write("回答正确!",font=("行楷",20))
break
else:
t2.penup()
t2.goto(-100,-200)
t2.pendown()
t2.write("回答错误 请再试一次",font=("行楷",20))
time.sleep(3)
t2.clear()
turtle.done()
相似问题