call addbomb '补充地图上的 炸弹
case map_prize '奖品
call changescore(prizeremain, false)
call showprize(false) '清除地图上的奖品
end select
call refreshsnake(temphead.x, temphead.y, blnaddlengh) '刷新地图 上的蛇身图像
' tmrmove.enabled = true
end sub
private sub form_unload(cancel as integer)
dim ans as integer
if blnstartgame then ''如果游戏已经开始,则询问是否要退出
if blnpause = false then call form_keydown(key_pause, 0) '如果游戏正在进行,则发送“暂停”按键事件,暂停游戏
ans = msgbox("游戏尚未结束,确定要退出吗?", vbquestion or vbyesno or vbdefaultbutton2)
if ans = vbyes then
end
else
cancel = true
end if
else
end
end if
end sub
'设置游戏级别(速度)
private sub hscrlevel_change()
curlevel = hscrlevel.value
lbllevel.caption = curlevel
tmrmove.interval = speed_lv1 - (curlevel - 1) * speed_change '根据级别,设置速度
end sub
private sub tmrmove_timer()
call playermove
end sub
'改变玩家的分数
'参数:addscore--增加的分数(正数=加分,负数=扣分)
' blnaddeatcount--判断是否要对cureatcount累加(t=累加)(如果当前吃进的不是食物或炸弹,就不进行累加)
private sub changescore(addscore as integer, blnaddeatcount as boolean)
p1.score = p1.score + addscore
if blnaddeatcount then cureatcount = cureatcount + 1 '记录(累加)当前吃进的物品
'如果吃进的物品(cureatcount) 达到一定数量(eatcountpershowprize)就显示奖品
if cureatcount = eatcountpershowprize then
cureatcount = 0 '重新累计 吃进的物品数
'如果上一次的奖品还没有消失(以 prizeremain > 0 为标志),就先清除旧的奖品,然后才显示新的奖品
if prizeremain > 0 then call showprize(false)
call showprize(true)
end if
lblscore.caption = p1.score
if p1.score <= 0 then call gameover
end sub
'增加地图上的 食物
private sub addfood()
dim tempfood as theposition
'寻找一个空白地,用于放置食物
do
tempfood.x = int(rnd() * (max_col_index + 1))
tempfood.y = int(rnd() * (max_row_index + 1))
loop until mapproperty(tempfood.x, tempfood.y) = map_empty
mapproperty(tempfood.x, tempfood.y) = map_food '标记地图格的属性为 食物
picdisplay.line (tempfood.x * map_scale, tempfood.y * map_scale)-step(map_scale, map_scale), map_food_color, bf '在地图上绘出 食物
end sub
'增加地图上的 炸弹
private sub addbomb()
dim tempbomb as theposition
'寻找一个空白地,用于放置炸弹
do
tempbomb.x = int(rnd() * (max_col_index + 1))
tempbomb.y = int(rnd() * (max_row_index + 1))
loop until mapproperty(tempbomb.x, tempbomb.y) = map_empty
mapproperty(tempbomb.x, tempbomb.y) = map_bomb '标记地图格的属性为 炸弹
picdisplay.line (tempbomb.x * map_scale, tempbomb.y * map_scale)-step(map_scale, map_scale), map_bomb_color, bf '在地图上绘出 炸弹
end sub
'在地图上显示 奖品 和 奖励分数
'参数:blnshow(t=显示奖品,f=清除奖品)
private sub showprize(blnshow as boolean)
dim tempprize as theposition
dim tempcolor as long
if blnshow then '显示奖品
'寻找一个空白地,用于放置奖品