高一VB小游戏

高一VB小游戏,第1张

'在态亩肢界面上拖一个image,复制image1,粘贴,形成控件数组,然后删除image1(1),

'只留下image1(0),调整其高度和宽度,放到窗口的左上角

'耐喊准备p1-p12个图片,红色和黑色的图片放到“F:\编程\VB\高一游戏\”下

Dim ipick%, clicked As Boolean

Private Sub Form_Load()

For i = 1 To 11

Load Image1(i)

Image1(i).Visible = True

Image1(i).Stretch = True

Image1(i).Picture = LoadPicture("F:\编程\VB\高一游戏\p" & i + 1 & ".jpg")

Image1(i).Left = (i Mod 4) * Image1(0).Width

Image1(i).Top = (i \ 4) * Image1(0).Height

Form1.Width = Image1(0).Width * 4

Form1.ScaleHeight = Image1(0).Height * 3

Next i

clicked = True

Form1.Caption = 10

Timer1.Interval = 3000

End Sub

Private Sub Image1_Click(Index As Integer)

If Index = ipick Then

clicked = True

Image1(ipick).Picture = LoadPicture("F:\编程\VB\高一游戏\p" & ipick + 1 & ".jpg")

End If

End 帆世Sub

Private Sub Timer1_Timer()

If Not clicked Then

Image1(ipick).Picture = LoadPicture("F:\编程\VB\高一游戏\red.jpg")

Form1.Caption = Form1.Caption - 1

If Form1.Caption = 0 Then

Timer1.Interval = 0

MsgBox "加油呀", , "颜色游戏"

End If

End If

ipick = Int(Rnd * 12)

Image1(ipick).Picture = LoadPicture("F:\编程\VB\高一游戏\black.jpg")

clicked = False

End Sub

下面是源代码:

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

窗体放两个Label控件,一个Timer控件答颤:

Dim n As Integer

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyUp

If Label1.Top >0 Then Label1.Top = Label1.Top - 50

Case vbKeyDown

If Label1.Top <ScaleHeight - Label1.Height Then Label1.Top = Label1.Top + 50

Case vbKeyLeft

If Label1.Left >清悄败 0 Then Label1.Left = Label1.Left - 50

Case vbKeyRight

If Label1.Left <ScaleWidth - Label1.Width Then Label1.Left = Label1.Left + 50

End Select

Call check

End Sub

Private Sub check()

If Abs(Label1.Top - Label2.Top) <= 50 And Abs(Label1.Left - Label2.Left) <= 50 Then

n = n + 1

Label2.Move Rnd * ScaleWidth, Rnd * ScaleHeight

End If

End Sub

Private Sub Form_Load()

KeyPreview = True

Randomize

With Label1

.Caption = ""

.BackColor = vbWhite

.Move (ScaleWidth - .Width) / 2, (ScaleHeight - .Height) / 2, 500, 500

End With

With Label2

.Caption = ""

.BackColor = vbYellow

.Move Rnd * ScaleWidth, Rnd * ScaleHeight, 500, 500

End With

Timer1.Interval = 60000

Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

MsgBox "运颂这局对准了" &n &"次黄方块"

Unload Me

End Sub


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存