如何用VB程序设计打地鼠游戏

如何用VB程序设计打地鼠游戏,第1张

下面是源代码:

Form1:

Private Sub Form_Load() Dim temp As Integer Randomize

temp = Int(Rnd * 3) + 1

Form1.Picture = LoadPicture("C:\Users\Administrator\Desktop\打地鼠\picture" &temp &".jpg") WindowsMediaPlayer1.URL = "C:\Users\Administrator\Desktop\打地鼠\Heaven's Devils.wma" End Sub

Private Sub Label1_Click() Form2.Show Form2.num = -1 Form1.Hide

WindowsMediaPlayer1.URL = ""

Open "C:\Users\Administrator\Desktop\打地鼠\primary.dat"稿郑 For Append As #1 '写 *** 作 Close #1

Open "C:\Users\Administrator\Desktop\打地鼠茄尺\intermediate.dat" For Append As #2 Close #2

Open "C:\Users\键纳颂Administrator\Desktop\打地鼠\advanced.dat" For Append As #3 Close #3 End Sub

Private Sub Label2_Click() End End Sub

Form2:

Dim allnum As Integer, oknum As Integer '定义变化次数 打中次数 Public num As Integer '判别是否第一次开始游戏 Dim flags1 As Boolean '判别文件是否保存 Public flags As Boolean '判别是否播放声音 Private Sub countine_Click() pause.Enabled = True Timer1.Enabled = True countine.Enabled = False WLXZ.Enabled = True End Sub

Private Sub exit_Click() Dim X As Integer Dim tt As Integer

X = MsgBox("是否真的退出?", vbYesNo, "退出游戏框")

If X = 6 Then

tt = MsgBox("退出游戏之前,是否保存", vbYesNo, "保存提示") If tt = 6 Then

If flags1 = True Then EndElse

If Timer1.Interval = 1000 Then

Open "C:\Users\Administrator\Desktop\打地鼠\primary.dat" For Append As #1'写 *** 作

Print #1, Text1.Text + " " + Format(Date, "M/d/yy") Close #1

ElseIf Timer1.Interval = 500 Then

Open "C:\Users\Administrator\Desktop\打地鼠\intermediate.dat" For Append As #2

Print #2, Text1.Text + " " + Format(Date, "M/d/yy") Close #2Else

Open "C:\Users\Administrator\Desktop\打地鼠\advanced.dat" For Append As #3

Print #3, Text1.Text + " " + Format(Date, "M/d/yy") Close #3End If End If End If End End If End Sub

Private Sub Form_Load() Form4.Check1.Value = 1

WindowsMediaPlayer1.Controls.stop countine.Enabled = False pause.Enabled = False WLXZ.Enabled = False

Form5.Top = Form2.Top + 700 Form5.Left = Form2.Left flags1 = False flags = True End Sub

Private Sub help_Click() Form3.Show End Sub

Private Sub new_game_Click() num = num + 1 Dim t As Integer

If (num >0) Then

t = MsgBox("新游戏开始之前,是否保存", vbYesNo, "保存提示") If t = 6 Then

flags1 = True

If Timer1.Interval = 1000 Then

Open "C:\Users\Administrator\Desktop\打地鼠\primary.dat" For Append As #1'写 *** 作

Print #1, Text1.Text + " " + Format(Date, "M/d/yy") Close #1

ElseIf Timer1.Interval = 500 Then

Open "C:\Users\Administrator\Desktop\打地鼠\intermediate.dat" For Append As #2

Print #2, Text1.Text + " " + Format(Date, "M/d/yy") Close #2 Else

Open "C:\Users\Administrator\Desktop\打地鼠\advanced.dat" For Append As #3

Print #3, Text1.Text + " " + Format(Date, "M/d/yy") Close #3 End If End If End If

Call Form_Load

allnum = 0 '变化次数初始为0 oknum = 0 '打中次数初始为0 Timer1.Enabled = True pause.Enabled = True WLXZ.Enabled = True End Sub

Private Sub options_Click() Timer1.Enabled = False Form4.Show

WLXZ.Enabled = False countine.Enabled = True End Sub

Private Sub pause_Click() Dim r, g, b As Integer Timer1.Enabled = False countine.Enabled = True pause.Enabled = False WLXZ.Enabled = False

Form5.Top = Form2.Top + 700 Form5.Left = Form2.Left Form5.Show

1、控件

picture1(0~8)

排三列三排

timer1

interval设誉裂空为1000

text1

text

设为0

command1

caption

设为“开始”

2、代码:

private

declare

sub

sleep

lib

"kernel32"

(byval

dwmilliseconds

as

long)

dim

m,

i,

n

as

integer

private

sub

form_load()

timer1.enabled

=

false

for

l

=

0

to

8

picture1(l).visible

=

false

next

l

end

sub

private

sub

command1_click()

timer1.enabled

=

true

end

sub

private

sub

timer1_timer()

if

i

<

9

then

picture1(i).visible

=

false

end

if

randomize

i

=

(rnd()

*

8)

mod

10

picture1(i).visible

=

true

picture1(i).zorder

if

n

=

10

then

picture1(i).visible

=

false

if

text1

>=

80

then

m

=

m

+

1

c

=

msgbox("恭喜你过关了。你的得庆瞎分为"

text1

vbcrlf

"是否进入"

m

+

1

"关",

4)

if

c

=

vbyes

then

timer1.interval

=

timer1.interval

-

100

*

(11

-

m)

/

10

else

timer1.enabled

=

false

end

if

else

msgbox

"请重新开始!"

end

if

n

=

0

text1

=

0

end

if

n

=

n

+

1

end

sub

private

sub

picture1_click(index

as

integer)

select

case

index

case

index

if

index

=

i

then

timer1.enabled

=

false

text1

=

text1

+

10

msgbox

"恭源尺喜你!"

timer1.enabled

=

true

end

if

end

select

end

sub

图晌激文并茂。。。。好难啊~~

流程给你讲一下吧

9个 图片控件 1个 按钮控件 2个时间控件

按钮按下 游戏开始

按下按钮的 事件 应该是修改 时间控件 响应为 true

时间控件 是 设置时间间隔 然后

清空 图片控件的 图片

随机 1~9数字

随机数字对应 9个 图片

随到那个数字 那个搭谨败显示图片

图片的单击事件

表现 被打的图片

重置 时知颤间控件

嗯。。。差不多是这样的。。。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12440375.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存