大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> VB 贪吃蛇 单人版游戏

VB 贪吃蛇 单人版游戏

时间: 2021-07-31 作者:daque

安排思绪:================================(一)发端新游戏1.1 获得并运用各个参数(暂时级别,遏制键等),初始化随机数(randomize)。1.2 废除舆图上的一切货色,各个统计数值置零。1.3 初始化舆图:安置食品,空包弹,蛇身场所以及蛇头的挪动目标——在picturebox上绘绘图像 并窜改对应的舆图格属性值(mapproperty()数组)。1.4 启用timer准时器,游戏发端。

(二)游戏操纵2.1 休憩\回复——窜改表白游戏状况的boolean型变量值;表露\湮没 表白游戏状况的label;休憩\回复 timer准时器。

2.2 遏制目标(按照nokia馋嘴蛇的操纵办法)——因为蛇头只能朝左右安排4个目标挪动,然而目标键有8个,以是“斜线目标”的遏制键和程度,笔直目标的遏制键源代码上有点各别

2.2.1 斜线目标键(以“右上”目标键为例)——即使暂时蛇头朝着左边(程度目标)疏通,则将程度目标的重量变为0,再将笔直目标的重量变为-1(进取疏通);即使暂时蛇头朝着上方(笔直目标)疏通,则将笔直目标的重量变为0,再将程度目标的重量变为 1(向右疏通)。其他“左上,左下,右下”的目标键源代码与上述好像。

2.2.2“程度,笔直”目标键——当蛇以 程度 目标挪动时,“左”和“右”的按键失效;(即不处置按键事变)当蛇以 笔直 目标挪动时,“上”和“下”的按键失效。

(三)挪动蛇身3.1 按照疏通目标,找到蛇头的新坐标;3.2 确定蛇头新坐标下的 舆图属性——(1)即使蛇头的新坐标 和暂时 蛇尾 的坐标重合,那不算gameover--由于跟着蛇头的挪动,蛇身各个节点城市向前跟进,使得暂时 蛇尾 坐标下的网格在挪动之后会形成 空缺地。(2)即使暂时蛇头场所的舆图属性是“食品”——减少蛇身长度,统计玩家吃进的食品数目,减少分数,弥补舆图上的食品,记载(累加)暂时吃进的货色,即使吃进的货色(cureatcount) 到达确定数目(eatcountpershowprize)就在舆图上表露奖品。(3)即使暂时蛇头场所的舆图属性是“空包弹“(组织)——统计玩家吃进的空包弹数目,扣分(即使分数小于0,就gameover),弥补舆图上的空包弹,记载(累加)暂时吃进的货色,即使吃进的货色到达确定数目就表露奖品。(4)即使暂时蛇头场所的舆图属性是“奖品”——加分,从新累计 吃进的货色数(cureatcount = 0)3.3 革新蛇身坐标,革新 舆图网格属性 以及画面(1)在革新蛇身坐标之前,生存从来的 蛇尾坐标;(2)先在舆图上 擦除旧的的蛇头,而后在舆图上 美术出新的蛇头;(3)窜改变量值,标志蛇头新坐标下的舆图格属性为:蛇身;(4)要先革新 蛇身除去蛇头外其他局部的坐标;(5)之后才革新 蛇头的坐标;(6)确定能否须要 减少蛇身长度——即使要减少长度:旧蛇尾的坐标静止,蛇身长度 + 1;  要不(无需减少蛇身长度):即使蛇头的新坐标与旧蛇尾的坐标重合,就不必在旧蛇尾的坐标下 美术空缺地的图案(由于该网格属性仍旧是 蛇头,而不是空缺地)(7)在舆图上擦除旧蛇尾,美术空缺地;(8)在舆图上把 旧蛇尾坐标 下的舆图格的属性树立为 空缺地;

 

《规范模块 module1 代码》——

option explicit

'******************************************************************************************************************************'全部 恒量

public enum map_property '舆图属性    map_empty = 0 '空缺地    map_food '食品    map_bomb '空包弹,组织    map_prize '加分奖品    map_snake '蛇身end enum

public const map_scale as integer = 15 '舆图夸大倍数

'舆图网格数(index值,首值为0)public const max_col_index as integer = 19public const max_row_index as integer = 10

public const start_snake_length as integer = 8 '蛇身初始长度

public const speed_lv1 as integer = 200 '第头等(最慢)的速率(timer.interval,最快第9级=40)public const speed_change as integer = 20 '前后2个等第之间的 interval差值(毫秒)

'设置遏制键    public const key_pause as integer = vbkeynumpad5        public const key_up as integer = vbkeynumpad8    public const key_dn as integer = vbkeynumpad2    public const key_lf as integer = vbkeynumpad4    public const key_rt as integer = vbkeynumpad6        public const key_lfup as integer = vbkeynumpad7    public const key_lfdn as integer = vbkeynumpad1    public const key_rtup as integer = vbkeynumpad9    public const key_rtdn as integer = vbkeynumpad3

'设置弥补色    public const head_color as long = &h80ff  '蛇头脸色    public const body_color as long = vbgreen '蛇身脸色    public const empty_color as long = &he0e0e0 '空缺地脸色    public const food_color as long = vbblue '食品脸色    public const bomb_color as long = vbred '空包弹脸色    public const full_color as long = 255 ^ 3    public const record_file_name as string = "\record.dat" '记载得分榜的 文献名

public const max_prize as integer = 50 '开始 赞美分数的 下限public const min_prize as integer = 20 '开始 赞美分数的 下限'全部 变量

'记载玩家的关系消息和树立值:public type theplayerinfo    score as integer '记载得分    headcolor as long '蛇头弥补色    bodycolor as long '蛇身弥补色    food as integer '记载吃进的 食品数目    bomb as integer '记载吃进的 空包弹数目    blngameover as boolean '标志该玩家能否仍旧game over'    snakecolor as long '美术蛇身运用的弥补色……姑且简略……    snakelength as integer '蛇身长度    '蛇头挪动目标(值为 -1,0,1)    x_way as integer    y_way as integer    '遏制键(8个)……姑且简略(沿用默许遏制键)end type

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''记载 玩家的得分和名字type therecord    name as string * 15    score as integerend type

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''用来表白二维坐标值public type theposition    x as integer    y as integerend type

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''public foodcount_atonetime as integer '舆图上同声展示的 食品数目public bombcount_atonetime as integer '舆图上同声展示的 空包弹数目

vb 贪吃蛇 单人版游戏图1

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)    map_width = (max_col_index + 1) * map_scale    map_height = (max_row_index + 1) * map_scale    picdisplay.cls    picdisplay.width = map_width + 2    picdisplay.height = map_height + 2    picdisplay.line (0, 0)-step(map_width, map_height), map_empty_color, bf            foodcount_atonetime = 2 '舆图上同声生存的 食品数目    bombcount_atonetime = 1 '舆图上同声生存的 空包弹数目        eatcountpershowprize = 5 '树立 蛇每吃进几何货色(囊括食品和空包弹,奖品不计)才表露一次奖品        curlevel = hscrlevel.value    addscoreperfood = curlevel '每吃进一个 食品,所减少的分数=暂时的级别值    addscoreperbomb = -curlevel * 2 '每吃进一个 空包弹,所扣掉的分数            p1.score = abs(addscoreperbomb) + 1 '玩家的初始分数='每吃进一个 空包弹,所扣掉的分数+1    p1.food = 0    p1.bomb = 0    prizeremain = 0    p1.blngameover = false    lblscore.caption = p1.score    lblfoodcount.caption = p1.food    lblbombcount.caption = p1.bomb        '初始化p1蛇身    redim snake_p1(start_snake_length)    for i = 0 to ubound(snake_p1)        '设定蛇身各段的开始场所        snake_p1(i).x = max_col_index - ubound(snake_p1) + i        snake_p1(i).y = max_row_index        '初始化挪动目标        p1.x_way = -1        p1.y_way = 0        mapproperty(snake_p1(i).x, snake_p1(i).y) = map_snake        picdisplay.line (snake_p1(i).x * map_scale, snake_p1(i).y * map_scale)-step(map_scale, map_scale), body_color, bf    next    '运用蛇头脸色 从新美术蛇头    picdisplay.line (snake_p1(0).x * map_scale, snake_p1(0).y * map_scale)-step(map_scale, map_scale), head_color, bf            '安置食品    for i = 1 to foodcount_atonetime        call addfood    next        '安置空包弹    for i = 1 to bombcount_atonetime        call addbomb    next        lblpause.visible = false    lblscore.caption = p1.score    lblfoodcount.caption = p1.food    lblbombcount.caption = p1.bomb        p1.blngameover = false    hscrlevel.enabled = false '游戏举行功夫不许变换级别    tmrmove.enabled = trueend sub

'表露得分榜private sub cmdshowscorelist_click()    if blnpause = false then call form_keydown(key_pause, 0) '即使游戏正在举行,则发送“休憩”按键事变,休憩游戏    frmscorelist.show    end sub

private sub form_keydown(keycode as integer, shift as integer)        if p1.blngameover or blnstartgame = false or blnonkeyevents = false then exit sub '以次情景(游戏中断、游戏还没有发端、禁止使用击键事变)不接受按键操纵。        '按“numpad 5”键--休憩/连接    if keycode = key_pause then        blnpause = not blnpause        lblpause.visible = blnpause        tmrmove.enabled = not blnpause        exit sub    end if        if blnpause then exit sub '在休憩状况下不接收“esc”外的其它按键        select case keycode        case key_lfup            blnonkeyevents = false            if p1.x_way <> 0 then                p1.x_way = 0                p1.y_way = -1            elseif p1.y_way <> 0 then                p1.x_way = -1                p1.y_way = 0            end if        case key_lfdn            blnonkeyevents = false            if p1.x_way <> 0 then                p1.x_way = 0                p1.y_way = 1            elseif p1.y_way <> 0 then                p1.x_way = -1                p1.y_way = 0            end if                case key_rtup            blnonkeyevents = false            if p1.x_way <> 0 then                p1.x_way = 0                p1.y_way = -1            elseif p1.y_way <> 0 then                p1.x_way = 1                p1.y_way = 0            end if        case key_rtdn            blnonkeyevents = false            if p1.x_way <> 0 then                p1.x_way = 0                p1.y_way = 1            elseif p1.y_way <> 0 then                p1.x_way = 1                p1.y_way = 0            end if            '当蛇以 程度 目标挪动时,lf 和 rt 按键失效        case key_lf            blnonkeyevents = false            if p1.x_way = 0 then                p1.x_way = -1                p1.y_way = 0            end if        case key_rt            blnonkeyevents = false            if p1.x_way = 0 then                p1.x_way = 1                p1.y_way = 0            end if            '当蛇以 笔直 目标挪动时,up 和 dn 按键失效        case key_up            blnonkeyevents = false            if p1.y_way = 0 then                p1.x_way = 0                p1.y_way = -1            end if        case key_dn            blnonkeyevents = false            if p1.y_way = 0 then                p1.x_way = 0                p1.y_way = 1            end if                case else            exit sub    end select        tmrmove.enabled = false '休憩timer事变,比及此次挪动操纵十足实行后(即sub refreshsnake(...)进程实行结束),再启用timer        call playermove    end sub

private sub form_keyup(keycode as integer, shift as integer)    blnonkeyevents = true '摊开一个键之后,本领接受按键事变end sub

private sub form_load()    me.keypreview = true    picdisplay.backcolor = empty_color    curlevel = 6 '默许级别:6    hscrlevel.value = curlevel    end sub

'游戏中断private sub gameover()    dim ans as integer        p1.blngameover = true    tmrmove.enabled = false    if prizeremain > 0 then call showprize(false)        msgbox "游戏中断。你的得分是:" & vbcrlf & p1.score, vbinformation, "game over"    call checkrecord(p1.score)  '查看分数是否上榜        call cmdnewgame_click '筹备新一轮游戏

end sub

'蛇挪动 的处置进程private sub playermove()    dim temphead as theposition '偶尔寄存蛇头的新坐标    dim blnaddlengh as boolean '能否减少蛇身的长度(t=减少)        '找到蛇头的新坐标    temphead.x = snake_p1(0).x + p1.x_way    temphead.y = snake_p1(0).y + p1.y_way        if blnthroughwall then '即使暂时是 穿墙形式(默许)        if temphead.x < 0 then            temphead.x = max_col_index        elseif temphead.x > max_col_index then            temphead.x = 0        elseif temphead.y < 0 then            temphead.y = max_row_index        elseif temphead.y > max_row_index then            temphead.y = 0        end if    else        '非 穿墙形式的挪动代码未树立    end if            '确定蛇头新坐标下的 舆图属性    select case mapproperty(temphead.x, temphead.y)        case map_empty '空缺地            '姑且没有空缺地的挪动操纵        case map_snake '蛇身            '即使蛇头的新坐标 和暂时 蛇尾 的坐标重合,就不算gameover--由于跟着蛇头的挪动,蛇身各个节点城市向前跟进,使得暂时 蛇尾 坐标下的网格形成 空缺地。            if not (temphead.x = snake_p1(ubound(snake_p1)).x and temphead.y = snake_p1(ubound(snake_p1)).y) then                call gameover                exit sub            end if        case map_food '食品            blnaddlengh = true '减少蛇身长度            p1.food = p1.food + 1 '统计玩家吃进的 食品数目            lblfoodcount.caption = p1.food '表露所有吃进的 食品数目            call changescore(addscoreperfood, true) '加分            call addfood '弥补舆图上的 食品        case map_bomb '空包弹            p1.bomb = p1.bomb + 1 '统计玩家吃进的 空包弹数目            lblbombcount.caption = p1.bomb '表露所有吃进的 空包弹数目            call changescore(addscoreperbomb, true) '扣分            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 ifend 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 playermoveend 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 gameoverend 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 '表露奖品        '探求一个空缺地,用来安置奖品        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 = trueend sub

'查看得分是否上榜--即使能上榜,则革新排行榜public sub checkrecord(score as integer)    dim filenum as integer    dim pos as integer, i as integer, list as listbox 'pos --排名    dim name as string  '记载玩家称呼    dim topten as boolean '确定得分能否加入前十名    dim ans as integer        filenum = freefile    set list = frmscorelist.lstscore '映照到列表框 frmscorelist.lstscore    do        if score >= val(list.list(pos)) then            topten = true                        do '轮回,树立玩家玩家称呼                name = inputbox("你的得分是第 " & pos + 1 & "名" & vbcrlf & "请输出你的称呼(不胜过15个字符)", "加入前10名!")                if len(name) = 0 then                    msgbox "你废除了 top 10 得分备案", vbinformation                    exit sub                end if                if len(rtrim(name)) > 15 then                    ans = msgbox("玩家称呼的长度不许胜过15个字符!" & vbcrlf & "你输出的 “" & name & "”" & "将机动改为 “" & left(name, 15) & "”" & "能否承诺?", vbquestion or vbyesno, "输出玩家称呼")                    if ans = vbyes then name = left(name, 15)                                    end if            loop until len(rtrim(name)) <= 15 and len(rtrim(name)) > 0 '直到玩家称呼的长度适合规则,才退出轮回                    end if                pos = pos + 1    loop until pos = 10 or topten = true        if topten = true then        list.additem score, pos - 1        frmscorelist.lstname.additem name, pos - 1                if list.listcount > 10 then list.removeitem list.listcount - 1        if frmscorelist.lstname.listcount > 10 then frmscorelist.lstname.removeitem frmscorelist.lstname.listcount - 1        call putrecord '革新 记载文献的实质    end if    end sub

'往文献里写入 得分记载private sub putrecord()    dim filenum as integer, i as integer    filenum = freefile    open app.path & record_file_name for random as #filenum len = len(record(0))    for i = 0 to 9        record(i).score = val(frmscorelist.lstscore.list(i))        record(i).name = frmscorelist.lstname.list(i)        put #filenum, , record(i)    next    close #filenumend sub

'连接缩小赞美的分数private sub tmrprize_timer()    dim tempcolor as long        prizeremain = prizeremain - 1    if prizeremain = 0 then        call showprize(false) '当赞美的分数缩小到零,就擦除奖品        exit sub    end if        tempcolor = int(rnd() * (full_color + 1)) '爆发随机脸色    picdisplay.line (prizepos.x * map_scale, prizepos.y * map_scale)-step(map_scale, map_scale), tempcolor, bf '在舆图上用 随机脸色美术 奖品        lblprizeremain.forecolor = full_color - tempcolor '结余的分数,用反色表露    lblprizeremain.caption = prizeremain '表露暂时结余的 赞美分数        end sub

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

《排行榜窗体 frmscorelist 代码》——

private record(9) as therecord '记载得分在前10名的 玩家的得分和名字

vb 贪吃蛇 单人版游戏图2

option explicit

private sub form_load()    dim filenum as integer, i as integer            lstpos.clear    for i = 1 to 10        lstpos.additem i, i - 1    next        lstscore.clear        lstname.clear        '读入得分记载    filenum = freefile    open app.path & record_file_name for random as #filenum len = len(record(0))'    call scoresort(filenum)    for i = 0 to 9        get #filenum, , record(i)        lstscore.additem record(i).score, i        lstname.additem record(i).name, i    next    close #filenum        end sub

'同步3个listbox——

private sub lstname_click()    lstpos.listindex = lstname.listindex    lstscore.listindex = lstname.listindexend sub

private sub lstpos_click()    lstscore.listindex = lstpos.listindex    lstname.listindex = lstpos.listindexend sub

private sub lstscore_click()    lstpos.listindex = lstscore.listindex    lstname.listindex = lstscore.listindexend sub

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

《证明窗体 frmhelp 》——

只需增添一个textbox,其text属性填入操纵证明如次:

《贪食蛇 1.1单人版(穿墙)》游戏证明

(1)遏制键:   “enter”--新游戏/遏止游戏;   “5”--休憩/回复-(数字键盘区,numlock状况);

目标遏制-(数字键盘区,numlock状况):   “8、2、4、6”--上、下、左、右;   “1”--左 / 下;   “3”--右 / 下;   “7”--左 / 上;   “9”--右 / 上。  ( 当蛇头和蛇身任一节重合时,游戏中断

(2)舆图:    蓝色方格--食品 (吃进食品后,蛇身长度减少一节);    赤色方格--空包弹;        淡紫色方格--蛇头;    亮绿色长条--蛇身。        闪耀的方格--奖品;    (奖品上头的数字表白吃进奖品后 减少的分数。)   ( 每个奖品分数的 初始值是20~50之间的随机数,当奖品展示后赞美的分数就会连接缩小。)

(3)计分本领:                ( 当总分 < = 0 时,游戏中断)

    每吃进一个食品 减少的分数即是 级其余数值;    每吃进一个空包弹 扣掉的分数是 级别数值的2倍;

    玩家开始分数即是 级别数值的 2倍再加1分。    (比方 等第为6,则玩家开始分数是13分;每吃进一个食品加6分;每吃进一个空包弹减12分)    游戏运转之后会在地方目次下创造一个"record.dat"的文献,寄存得分记载。

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

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.