vb.net写打地鼠,vb打地鼠代码
如何用VB程序设计打地鼠游戏
下面是源代码:
创新互联建站专注于成都网站设计、成都网站制作、网页设计、网站制作、网站开发。公司秉持“客户至上,用心服务”的宗旨,从客户的利益和观点出发,让客户在网络营销中找到自己的驻足之地。尊重和关怀每一位客户,用严谨的态度对待客户,用专业的服务创造价值,成为客户值得信赖的朋友,为客户解除后顾之忧。
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 End Else
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 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
期末老师让做一个比较有创意的vb.net小软件,无从下手!求帮忙
随手做了个打地鼠,代码拿去吧。
下图是10x10超大窗体“打地鼠”
直接新建个窗体,覆盖全部代码,不需要拖控件,全部动态创建了。
参数都在前面几行,可以随便改。
格子宽和高是70,间距20,因此横格子和竖格子不要超过10,不然窗体会扩张到非常大的程度。
调整时钟的Interval可决定地鼠的出现频率,你可以修改变化概率 = 15这句话改变出现几率。
Public Class Form1
Dim 横格子 = 4
Dim 竖格子 = 4
Dim 背景色 = Color.Bisque
Dim 打中色 = Color.LawnGreen
Dim 失误色 = Color.Red
Dim 按钮(横格子, 竖格子) As Button
Public WithEvents 时钟 As New Timer With {.Interval = 400}
Public WithEvents 分数板 As New Label With {.AutoSize = False, .Width = 120,
.Height = 26}
Dim 字体 = New Font("黑体", 14)
Dim 随机数 As New Random
Dim 打中数 As Integer = 0
Dim 分数 As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Font = 字体
For x = 1 To 横格子
For y = 1 To 竖格子
按钮(x, y) = New Button()
Me.Controls.Add(按钮(x, y))
按钮(x, y).Width = 70
按钮(x, y).Height = 70
按钮(x, y).Text = ""
按钮(x, y).Location = New Point((x - 1) * (按钮(x, y).Width + 20) +
20, (y - 1) * (按钮(x, y).Height + 20) + 20)
按钮(x, y).Name = String.Format("Button_{0}_{1}", x, y)
按钮(x, y).BackColor = 背景色
按钮(x, y).FlatStyle = FlatStyle.Flat
按钮(x, y).Tag = 0
AddHandler 按钮(x, y).Click, AddressOf 按钮点击
Next
Next
Me.Text = "打地鼠" " [空格键暂停]"
Me.KeyPreview = True
Dim k = 按钮(横格子, 竖格子)
Me.Width = k.Left + k.Width + 40
Me.Height = k.Top + k.Height + 65
Me.Controls.Add(分数板)
分数板.Location = New Point(Me.Width / 2 - 25, 0)
分数板.Text = "分数牌"
时钟.Enabled = True
End Sub
Private Sub 按钮点击(sender As Object, e As EventArgs)
If 时钟.Enabled = False Then Exit Sub
Dim 控件名 = CType(sender, Button).Name.Split("_")
Dim x = CInt(控件名(1)) '截取_分割的第二部分Button_{0}_{1}
Dim y = CInt(控件名(2)) '截取_分割的第三部分Button_{0}_{1}
If 按钮(x, y) IsNot Nothing Then
If 按钮(x, y).Text = "地鼠" Then
打中数 = 打中数 + 1
分数 = 分数 + 20
按钮(x, y).Text = 打中数 "!"
分数板.Text = "得分:" 分数
按钮(x, y).BackColor = 打中色
按钮(x, y).Tag = 1
ElseIf 按钮(x, y).Text = "" Then
分数 = 分数 - 20
If 分数 0 Then 分数 = 0
分数板.Text = "得分:" 分数
按钮(x, y).Text = "乱打!"
按钮(x, y).BackColor = 失误色
按钮(x, y).Tag = 2
End If
End If
End Sub
Private Sub 时钟_Tick(sender As Object, e As EventArgs) Handles 时钟.Tick
For x = 1 To 横格子
For y = 1 To 竖格子
Dim 变化概率 = 随机数.Next(1, 100)
If 变化概率 = 40 Then
If 按钮(x, y).Tag = 1 Or 按钮(x, y).Tag = 2 Then
按钮(x, y).Text = ""
按钮(x, y).BackColor = 背景色
按钮(x, y).Tag = 0
End If
End If
If 变化概率 = 15 Then
If 按钮(x, y).Text = "地鼠" Then
按钮(x, y).Text = ""
ElseIf 按钮(x, y).Text = "" Then
按钮(x, y).Text = "地鼠"
End If
End If
Next
Next
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles
MyBase.KeyUp
If e.KeyCode = Keys.Space Then 时钟.Enabled = Not 时钟.Enabled
End Sub
End Class
如满意,请采纳,谢谢。
教我做一个超级超级简单的VB打地鼠游戏吧,要图文并茂…………Please
图文并茂。。。。好难啊~~
流程给你讲一下吧
9个 图片控件 1个 按钮控件 2个时间控件
按钮按下 游戏开始
按下按钮的 事件 应该是修改 时间控件 响应为 true
时间控件 是 设置时间间隔 然后
清空 图片控件的 图片
随机 1~9数字
随机数字对应 9个 图片
随到那个数字 那个显示图片
图片的单击事件
表现 被打的图片
重置 时间控件
嗯。。。差不多是这样的。。。
VB制作打地鼠游戏
Private Sub CmdStart_click()
nt = Timer
End Sub
同时去掉
Private Sub Form_Load()
nt = Timer
End Sub
vb程序啊啊啊啊啊
Private Sub Action_Query()
Sheet2.Select
Dim mima As String
Dim t1 As Integer
mima = "1"
t1 = InputBox("ÇëÊäÈëÃÜÂë")
If t1 mima Then
MsgBox "ÄúµÄÃÜÂë´íÎó£¡"
Exit Sub
End If
Dim a As Integer, b As Integer, i As Integer
a = Range("k2").End(xlDown).Row
For i = 3 To a
Range("a3:k" a).Select
If Range("j" i) = "Y" Or Range("j" i) = "y" Then
Rows(i).Delete
i = i - 1
b = b + 1
End If
If i a - b Then Exit For 'i´óÓÚɾ³ýºóÐÐÊýʱÍ˳ö
Next i
Range("A2").Select
'ThisWorkbook.Save '±£´æ
End Sub
vb用一个按钮如何做出停止和暂停
你运行过程中应该用到了Timer1控制地鼠出现的时间你暂停时把Timer1的Enabled 为 False就可以了。
暂停代码为:
Timer1.Enabled = False
继续运行代码为:
Timer1.Enabled = True
停止你只需要把开始运行的各种函数值重新赋予初始值就可以了。
分享题目:vb.net写打地鼠,vb打地鼠代码
网址分享:http://scjbc.cn/article/hogsso.html