public h
h=THISFORM.TIMER1.INTERVAL
G=THISFORM.LABEL1.LEFT
I=THISFORM.LABEL0.LEFT
P=THISFORM.LABEL1.TOP
L=THISFORM.LABEL0.TOP
a1=1
a="1"
do while a1<=ab && 蛇身位置赋值
top&a=thisform.label&a .top
left&a=thisform.label&a .left
a=allt(str(&a+1))
a1=a1+1
enddo
if mx=2
thisform.label06.caption="不可穿墙"
thisform.label06.forecolor=rgb(255,0,0)
thisform.label06.fontbold=.t.
IF G<0 or p<0
MESSAGEBOX("游戏结束",0+48,"提示")
k=MESSAGEBOX("是否重来",4+32+0,"提示")
endif
IF G>516 OR P>312
MESSAGEBOX("游戏结束",0+48,"提示")
k=MESSAGEBOX("是否重来",4+32+0,"提示")
ENDIF
if k=7
quit
endif
if k=6
thisform.release
do form d:\vfp\表单\FINALLY\贪吃蛇.scx
endif
else
thisform.label06.caption="可穿墙"
thisform.label06.forecolor=rgb(255,0,0)
thisform.label06.fontbold=.t.
do case
case p<11 and x=5
thisform.label1.top=324
case g<11 and x=19
thisform.label1.left=528
case g>515 and x=4
thisform.label1.left=-12
case p>311and x=24
thisform.label1.top=-12
endcase
endif
do case
case x=5 && 上
a="1"
a1=1
thisform.label&a .top=thisform.label&a .top-12
case x=24 && 下
a="1"
a1=1
thisform.label&a .top=thisform.label&a .top+12
case x=19 && 左
a="1"
a1=1
thisform.label&a .left=thisform.label&a .left-12
case x=4 && 右
a="1"
a1=1
thisform.label&a .left=thisform.label&a .left+12
endcase
do while a1<ab && 使蛇身随蛇头移动
a=allt(str(&a+1))
a1=a1+1
az=allt(str(&a-1))
thisform.label&a .top=top&az
thisform.label&a .left=left&az
enddo
if mx=1
a="1"
a1=1
do while a1<ab && 判断蛇头是否碰到蛇身
a=allt(str(&a+1))
if top1=top&a and left1=left&a
MESSAGEBOX("游戏结束",0+48,"提示")
k=MESSAGEBOX("是否重来",4+32+0,"提示")
exit
else
a1=a1+1
endif
enddo
if k=7
quit
endif
if k=6
thisform.release
do form d:\vfp\表单\FINALLY\贪吃蛇.scx
endif
endif
if ABS(I-G)<5 AND ABS(P-L)<5 && 蛇身吃到食物,蛇身变长
M=M+1
thisform.label02.caption=allt(str((m*10)))
bx="label"+"&ax"
thisform.AddObject("&bx","label")
thisform.&bx .caption=" "
thisform.&bx .backcolor=rgb(int(rand()*250),int(rand()*250),int(rand()*250))
thisform.&bx .width=12
thisform.&bx .height=12
thisform.&bx .left=thisform.label&a .left
thisform.&bx .top=thisform.label&a .top
thisform.&bx .visible=.t.
ax=allt(str(val(ax)+1))
ab=ab+1
do while .t. && 食物的位置 top
e=rand()*50
i=int(e)*12
if i<=516 and i>=0
THISFORM.LABEL0.LEFT=i
exit
endif
enddo
do while .T. && 食物的位置 top
e=rand()*50
l=int(e)*12
if l<=312 and l>=0
THISFORM.LABEL0.top=l
EXIT
endif
enddo
IF H>70
THISFORM.TIMER1.INTERVAL=THISFORM.TIMER1.INTERVAL-10
ENDIF
endif