VB 贪吃蛇 单人版游戏 (原作)[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 bugs1984 的 blog

    x_way as integer
    y_way as integer
    '控制键(8个)……暂时省略(采用默认控制键)
end type

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'记录 玩家的得分和名字
type therecord
    name as string * 15
    score as integer
end type

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'用于表示二维坐标值
public type theposition
    x as integer
    y as integer
end type

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public foodcount_atonetime as integer '地图上同时出现的 食物数量
public bombcount_atonetime as integer '地图上同时出现的 炸弹数量

public prizeremain as integer '当前剩余的 奖励分数
public eatcountpershowprize '记录 蛇每吃进多少物品(包括食物和炸弹,奖品不计)才显示一次奖品

public addscoreperfood as integer '每吃进一个 食物,所增加的分数
public addscoreperbomb as integer '每吃进一个 炸弹,所扣掉的分数
'**************************************************************************************************************************

sub main()
   
    frmplay.show
    frmscorelist.show '第一次运行时先显示得分榜

end sub

================================

《主窗体 frmplay 代码》——

private blnstartgame as boolean '标记是否已经开始 新游戏(t=游戏已经开始)
private blnpause as boolean '标记当前是否处于暂停状态(t=暂停)
private blnthroughwall as boolean '标记是否为穿墙模式(t=可以穿墙)
private blnonkeyevents as boolean '标记是否能够 接收键盘事件(t=可以接收),此变量可防止 form_keydown()事件重复执行

private map_width as integer '地图宽度(象素)
private map_height as integer '地图高度(象素)
private map_empty_color '地图-空白地颜色
private map_bomb_color '地图-炸弹颜色
private map_food_color '地图-食物颜色
private mapproperty() as integer '记录地图各个网格的属性

private cureatcount as integer '记录 每次出现奖品之前,一共吃进多少物品(包括食物和炸弹,奖品不计),当奖品出现后,此变量值变为 零"0",然后进入下一次统计
private curlevel as integer '当前级别
private p1 as theplayerinfo '记录player1 的信息

private snake_p1() as theposition '记录蛇身坐标
private prizepos as theposition '记录奖品的坐标

private record(9) as therecord '存放前十名的 得分记录信息

option explicit

private sub cmdhelp_click()
    if blnpause = false then call form_keydown(key_pause, 0) '如果游戏正在进行,则发送“暂停”按键事件,暂停游戏
    frmhelp.show
   
end sub

'开始新游戏
private sub cmdnewgame_click()
    dim i as integer
   
    randomize '重新生成随机数列
   
    blnstartgame = not blnstartgame
    if blnstartgame then
        cmdnewgame.caption = "停止"
    else
        cmdnewgame.caption = "新游戏"
    end if
   
   
    '中止游戏
    if blnstartgame = false then
        '如果上一次的奖品还没有消失(以 prizeremain > 0 为标志),就先清除旧的奖品,然后才显示新的奖品
        if prizeremain > 0 then call showprize(false)

        picdisplay.cls
       
        p1.score = 0 '玩家的初始分数
        p1.food = 0
        p1.bomb = 0
        cureatcount = 0
        prizeremain = 0
        blnpause = false
        lblpause.visible = false
        lblscore.caption = p1.score
        lblfoodcount.caption = p1.food
        lblbombcount.caption = p1.bomb
        p1.blngameover = true
        hscrlevel.enabled = true
        tmrmove.enabled = false
        exit sub
    end if
   
    blnthroughwall = true '穿墙模式
    blnonkeyevents = true
   
    '暂时使用默认填充色
    map_bomb_color = bomb_color
    map_empty_color = empty_color
    map_food_color = food_color
    p1.bodycolor = body_color
    p1.headcolor = head_color
   
    '地图初始化
    redim mapproperty(max_col_index, max_row_index)

本文关键:游戏 贪吃蛇 PictureBox
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top