do
tempprize.x = int(rnd() * (max_col_index + 1))
tempprize.y = int(rnd() * (max_row_index + 1))
loop until mapproperty(tempprize.x, tempprize.y) = map_empty
prizepos = tempprize '记录奖品的坐标
mapproperty(prizepos.x, prizepos.y) = map_prize '标记地图格的属性为 奖品
tempcolor = int(rnd() * (full_color + 1)) '产生随机颜色
picdisplay.line (prizepos.x * map_scale, prizepos.y * map_scale)-step(map_scale, map_scale), tempcolor, bf '在地图上用 随机颜色绘画 奖品
prizeremain = int(rnd() * (max_prize - min_prize + 1)) + min_prize '随机设定 起始的奖励分数
lblprizeremain.forecolor = full_color - tempcolor '剩余的分数,用反色显示
lblprizeremain.caption = prizeremain '显示当前剩余的 奖励分数
lblprizeremain.move prizepos.x * map_scale, prizepos.y * map_scale, map_scale, map_scale '将显示奖励分数的 label移动到地图中 奖品的坐标上面。
lblprizeremain.visible = true
tmrprize.enabled = true '启动tmrprize,不断地减少奖励分数
else '清除奖品
picdisplay.line (prizepos.x * map_scale, prizepos.y * map_scale)-step(map_scale, map_scale), map_empty_color, bf '在地图上擦除 奖品图案
mapproperty(prizepos.x, prizepos.y) = map_empty '标记地图格的属性为 空白地
lblprizeremain.visible = false
tmrprize.enabled = false
end if
end sub
'刷新蛇身坐标,更新 地图网格属性 以及画面
'参数:蛇头的新坐标_x,蛇头的新坐标_y,是否增加蛇身长度(t=增加)
private sub refreshsnake(newhead_x as integer, newhead_y as integer, blnaddlength as boolean)
dim i as integer
dim oldtail as theposition '用于在更新蛇身坐标之前,保存原来的 蛇尾坐标
oldtail = snake_p1(ubound(snake_p1)) '保存旧的蛇尾坐标
picdisplay.line (snake_p1(0).x * map_scale, snake_p1(0).y * map_scale)-step(map_scale, map_scale), p1.bodycolor, bf '在地图上 擦除旧的的蛇头
picdisplay.line (newhead_x * map_scale, newhead_y * map_scale)-step(map_scale, map_scale), p1.headcolor, bf '在地图上 绘画出新的蛇头
mapproperty(newhead_x, newhead_y) = map_snake '标记蛇头新坐标下的地图格属性为 玩家蛇身
'必须先更新 蛇身 除蛇头外其余部分的坐标。否则会出错
for i = (ubound(snake_p1)) to 1 step -1
snake_p1(i) = snake_p1(i - 1)
next
'然后更新 蛇头的坐标
snake_p1(0).x = newhead_x
snake_p1(0).y = newhead_y
'判断是否需要 增加蛇身长度
if blnaddlength then '增加长度
redim preserve snake_p1(ubound(snake_p1) + 1) '最后才设定新的 蛇尾坐标(关键字“preserve”的作用是:保留原数组的内容)
snake_p1(ubound(snake_p1)) = oldtail '旧蛇尾的坐标不变
p1.snakelength = ubound(snake_p1) + 1 '蛇身长度 + 1
else '蛇身长度不变
'如果蛇头的新坐标与旧蛇尾的坐标重合,就不用在旧蛇尾的坐标下 绘画空白地的图案(因为该网格属性已经是 蛇头,而不是空白地)
if not (newhead_x = oldtail.x and newhead_y = oldtail.y) then
mapproperty(oldtail.x, oldtail.y) = map_empty '在地图上把 旧蛇尾坐标 下的地图格的属性设置为 空白地
picdisplay.line (oldtail.x * map_scale, oldtail.y * map_scale)-step(map_scale, map_scale), map_empty_color, bf '在地图上擦除旧蛇尾,绘画空白地
end if
end if
tmrmove.enabled = true
end sub
'检查得分能否上榜--如果能上榜,则更新排行榜
public sub checkrecord(score as integer)
dim filenum as integer
dim pos as integer, i as integer, list as listbox 'pos --排名