蛇类int 蛇长int 方向int 速度function 移动(遍利蛇长。0读的是方向,其他读前一个的位置,并判断死亡,0碰墙,0碰其他)function 加长(蛇长加一)function 变向(接收键盘上下左右,改变int 方向)function 加速(速度加一)果类int 位置Xint 位置Yfunction 产生果(随机X Y)function 果消失(dimiss原果)流程:产生墙产生蛇产生果接收第一个方向,蛇.移动接收键盘输入,蛇.变向蛇0碰果,1果消失 2蛇.加长 3果生成累计N次,蛇速+1把代码复制到空窗体中按f5运行即可。 option explicit private withevents timer1 as timer private withevents label1 as label dim gfangxiang as boolean dim hwb as single dim she() as shenti dim x as long, y as long dim zhuangtai(23, 23) as long private type shenti f as long x as long y as long end type private sub form_keydown(keycode as integer, shift as integer) dim c as long if keycode = 27 then end if keycode = 32 then if timer1.enabled = true then timer1.enabled = false label1.visible = true else timer1.enabled = true label1.visible = false end if end if c = ubound(she) if gfangxiang = true then exit sub select case keycode case 37 if she(c).f = 2 then exit sub she(c).f = 0 gfangxiang = true case 38 if she(c).f = 3 then exit sub she(c).f = 1 gfangxiang = true case 39 if she(c).f = 0 then exit sub she(c).f = 2 gfangxiang = true case 40 if she(c).f = 1 then exit sub she(c).f = 3 gfangxiang = true end select end sub private sub form_load() me.autoredraw = true me.backcolor = &hc000& me.fillcolor = 255 me.fillstyle = 0 me.scalewidth = 24 me.scaleheight = 24 me.windowstate = 2 set timer1 = controls.add("vb.timer", "timer1") set label1 = controls.add("vb.label", "label1") label1.autosize = true label1.backstyle = 0 label1 = "暂停" label1.forecolor = rgb(255, 255, 0) label1.fontsize = 50 chushihua end sub private sub form_resize() on error goto 1: with me if .windowstate <> 1 then .cls .scalemode = 3 hwb = .scaleheight / .scalewidth .scalewidth = 24 .scaleheight = 24 label1.move (me.scalewidth - label1.width) / 2, (me.scaleheight - label1.height) / 2 huatu me.line (x, y)-(x + 1, y + 1), rgb(255, 255, 0), bf end if end with 1: end sub private sub timer1_timer() dim c as long, i as long on error goto 2: qingchu c = ubound(she) select case she(c).f case 0 if zhuangtai(she(c).x - 1, she(c).y) = 2 then c = c + 1 redim preserve she(c) she(c).f = she(c - 1).f she(c).x = she(c - 1).x - 1 she(c).y = she(c - 1).y chanshengshiwu goto 1: elseif zhuangtai(she(c).x - 1, she(c).y) = 1 then goto 2: end if case 1 if zhuangtai(she(c).x, she(c).y - 1) = 2 then c = c + 1 redim preserve she(c) she(c).f = she(c - 1).f she(c).x = she(c - 1).x she(c).y = she(c - 1).y - 1 chanshengshiwu goto 1: elseif zhuangtai(she(c).x, she(c).y - 1) = 1 then goto 2: end if case 2 if zhuangtai(she(c).x + 1, she(c).y) = 2 then c = c + 1 redim preserve she(c) she(c).f = she(c - 1).f she(c).x = she(c - 1).x + 1 she(c).y = she(c - 1).y chanshengshiwu goto 1: elseif zhuangtai(she(c).x + 1, she(c).y) = 1 then goto 2: end if case 3 if zhuangtai(she(c).x, she(c).y + 1) = 2 then c = c + 1 redim preserve she(c) she(c).f = she(c - 1).f she(c).x = she(c - 1).x she(c).y = she(c - 1).y + 1 chanshengshiwu goto 1: elseif zhuangtai(she(c).x, she(c).y + 1) = 1 then goto 2: end if end select zhuangtai(she(0).x, she(0).y) = 0 for i = 0 to c select case she(i).f case 0 she(i).x = she(i).x - 1 case 1 she(i).y = she(i).y - 1 case 2 she(i).x = she(i).x + 1 case 3 she(i).y = she(i).y + 1 end select next tiaozheng 1: gfangxiang = false zhuangtai(she(c).x, she(c).y) = 1 huatu exit sub 2: if msgbox("游戏结束,点“是”重新开始游戏,点“否”", vbyesno, "贪吃蛇") = vbyes then chushihua else end end if end sub private sub chushihua() me.cls timer1.enabled = true timer1.interval = 200 erase zhuangtai redim she(2) she(0).f = 2 she(0).x = 9 she(0).y = 11 zhuangtai(9, 11) = 1 she(1).f = 2 she(1).x = 10 she(1).y = 11 zhuangtai(10, 11) = 1 she(2).f = 2 she(2).x = 11 she(2).y = 11 zhuangtai(11, 11) = 1 huatu chanshengshiwu end sub private sub qingchu() dim i as long for i = 0 to ubound(she) me.line (she(i).x, she(i).y)-(she(i).x + 1, she(i).y + 1), me.backcolor, bf next end sub private sub huatu() dim i as long for i = 0 to ubound(she) me.circle (she(i).x + 0.5, she(i).y + 0.5), 0.49, rgb(255, 255, 0), , , hwb next end sub private sub tiaozheng() dim i as long for i = 0 to ubound(she) - 1 she(i).f = she(i + 1).f next end sub private sub chanshengshiwu() randomize timer 1: x = int(rnd * 24) y = int(rnd * 24) if zhuangtai(x, y) > 0 then goto 1: zhuangtai(x, y) = 2 me.line (x, y)-(x + 1, y + 1), rgb(255, 255, 0), bf end sub 应该就是这个了