import turtle
import copy
from random import *
turtle.setup(500,500)
fangkuai=[[0,0]]
zhuzi=[[230,i] for i in range(-240,241,10)]
zhuzi2=[[-30,i] for i in range(-240,241,10)]
def square(x,y,size,color):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
for i in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
jishi=1
jishi2=1
cishu=0
acti=10
def zhuang():
global jishi
shi=zhuzi
shi.pop(randint(0,23))
for i in shi:
square(i[0],i[1],10,'red')
jishi-=1
def zhuang2():
global jishi2
shi=zhuzi2
shi.pop(randint(0,23))
for i in shi:
square(i[0],i[1],10,'red')
jishi2-=1
def check():
global cishu
if [fangkuai[0][0],fangkuai[0][1]] in zhuzi or fangkuai[0] in zhuzi2:
print('Gver')
return True
else:
return False
jibie=1
active=500
def move():
global zhuzi
global zhuzi2
global jishi
global jishi2
global jibie
global active
global cishu
turtle.clear()
shi=zhuzi
zhuzi=[]
for i in shi:
zhuzi.append([i[0]-acti,i[1]])
shi2=zhuzi2
zhuzi2=[]
for i in shi2:
zhuzi2.append([i[0]-acti,i[1]])
if check():
return True
square(fangkuai[0][0],fangkuai[0][1],10,'green')
if jishi:
zhuang()
else:
for i in zhuzi:
if i[0]<-240:
zhuzi=[[230,i] for i in range(-240,240,10)]
jishi=1
cishu+=1
break
else:
square(i[0],i[1],10,'red')
if jishi2:
zhuang2()
else:
for i in zhuzi2:
if i[0]<-240:
zhuzi2=[[230,i] for i in range(-240,240,10)]
jishi2+=1
cishu+=1
break
else:
square(i[0],i[1],10,'red')
if jibie==1 and cishu>=5:
jibie=2
active=400
elif jibie==2 and cishu>=10:
jibie=3
active=300
elif jibie==3 and cishu>=15:
jibie=4
active=200
elif jibie==4 and cishu>=20 and cishu<=25:
jidie='Gver'
active=100
elif cishu>25:
print(jibie)
return False
turtle.ontimer(move,active)
def f1():
global fangkuai
fangkuai[0][1]=fangkuai[0][1]+10
def f2():
global fangkuai
fangkuai[0][1]=fangkuai[0][1]-10
turtle.tracer(False)
turtle.listen()
turtle.onkey(lambda :f1(),'Up')
turtle.onkey(lambda :f2(),'Down')
turtle.hideturtle()
turtle.done()