1.如何用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 IntegerIf (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。
2.求vb打地鼠游戏的设计
'窗口中就一个LABEL,名称:lblInfo'这个带有动画Option ExplicitDim lZQ As LongDim lCW As LongDim dStart As Double '开始时间Dim dStop As Double '停止时间Dim iNum As Integer '字数Dim lTime As Long 'Dim iTime As IntegerDim iCode As IntegerDim iScorce As Integer '分数Dim bOK As BooleanPrivate Sub Form_DblClick() '开始 Me.Timer1.Enabled = True dStart = TimeEnd SubPrivate Sub Form_Resize() Me.lblInfo.Top = Me.Height - 1000End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If dStart <> 0 Then If KeyCode = iCode Or KeyCode = iCode - 32 Then' If iCode <= 90 And Shift <> 2 Then '大写' Beep' lCW = lCW + 1' Else lZQ = lZQ + 1 iScorce = iScorce + 1' End If Else Beep lCW = lCW + 1 iScorce = iScorce - 1 End If End If bOK = True lTime = 0 iTime = 0 If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce '" ' , "统计" Call Timer1_TimerEnd SubPrivate Sub Form_Load() Me.Timer1.Interval = 50 Me.Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer() Static i As Integer Static j As Integer Static k As Integer Static l As Integer Me.AutoRedraw = True Me.KeyPreview = True If lTime * Me.Timer1.Interval / 1000 >= 500 Then '规定500秒任务 GoTo OVER End If If ((iTime * Me.Timer1.Interval) Mod 5000 = 0) Or bOK = True Then '每个字规定最多显示5秒钟 If iTime <> 0 Then lCW = lCW + 1 iScorce = iScorce - 1 If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce '" ' , "统计" End If iTime = 0 bOK = False Me.Cls Randomize i = Int(Rnd() * Me.ScaleWidth - 500) j = Int(Rnd() * Me.ScaleHeight - 500) k = Int(Rnd() * 90) + 10 '字号 l = Int(Rnd() * 26) '产生52个字母的其中一个 'l = Int(Rnd() * 53) '产生52个字母的其中一个 If l <= 25 Then '大写 l = 65 + l Else l = 97 + l - 26 End If iCode = l '记录 Me.CurrentX = i Me.CurrentY = j Me.FontSize = k Me.Print Chr(l) iNum = iNum + 1 l = 0 Else Me.Cls l = l + 1 If i - 100 * l < 100 Then l = 0 Me.CurrentX = Me.Width - 500 i = Me.Width - 500 Else Me.CurrentX = i - l * 100 End If Me.CurrentY = j Me.FontSize = k Me.Print Chr(iCode) End If If iNum >= 100 Then GoTo OVER iTime = iTime + 1 lTime = lTime + 1 Exit SubOVER: Me.Timer1.Enabled = False dStop = Time If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总耗时:" & Round((dStop - dStart) * 24 * 3600, 2) & "秒," & vbCrLf & "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce lTime = 0 iTime = 0 iNum = 0End Sub。
3.求助,一个基于labview的打地鼠游戏设计
基于Labview的打地鼠游戏程序VI,打开可直接使用。
程序图:
二、方案论证
1.地鼠部分
方案一:运用事件,实现点击的确认,并利用随机来判定哪个口有地鼠。
方案二:调用ActiveX控件,采用更简单的语句编写,例如Flash。
鉴于此次想要练习Labview的应用,选用了方案一。
2.LABVIEW程序设计
初步的设计并不理想,不能实现地鼠自动消失以及乱点鼠标的惩罚。
经过多次调整方案,最后采用了对于事件进行详尽分类,将地鼠的出现与消失编入事件,后来加入开始结束按键以后,问题变得更加复杂,于是在调用子VI的基础上,又增加了“等待开始”与“失败”两个事件,在此基础上重新调整了每一个参数在不同事件中的传递以及累计运算,最后实现了数据的统计。
在等待地鼠出现的事件中加入了难度的递增判断。对于同类数据隐藏,并把相同分类的编入簇处理,以简化框图。
3.界面美化
初步美化界面,个性化了按键,对于某些按键加入特效。最终加入音效。
4.求vb打地鼠游戏的设计
'窗口中就一个LABEL,名称:lblInfo'这个带有动画 Option Explicit Dim lZQ As Long Dim lCW As Long Dim dStart As Double '开始时间 Dim dStop As Double '停止时间 Dim iNum As Integer '字数 Dim lTime As Long ' Dim iTime As Integer Dim iCode As Integer Dim iScorce As Integer '分数 Dim bOK As Boolean Private Sub Form_DblClick() '开始 Me.Timer1.Enabled = True dStart = Time End Sub Private Sub Form_Resize() Me.lblInfo.Top = Me.Height - 1000 End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If dStart <> 0 Then If KeyCode = iCode Or KeyCode = iCode - 32 Then' If iCode <= 90 And Shift <> 2 Then '大写' Beep' lCW = lCW + 1' Else lZQ = lZQ + 1 iScorce = iScorce + 1' End If Else Beep lCW = lCW + 1 iScorce = iScorce - 1 End If End If bOK = True lTime = 0 iTime = 0 If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce '" ' , "统计" Call Timer1_Timer End Sub Private Sub Form_Load() Me.Timer1.Interval = 50 Me.Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Static i As Integer Static j As Integer Static k As Integer Static l As Integer Me.AutoRedraw = True Me.KeyPreview = True If lTime * Me.Timer1.Interval / 1000 >= 500 Then '规定500秒任务 GoTo OVER End If If ((iTime * Me.Timer1.Interval) Mod 5000 = 0) Or bOK = True Then '每个字规定最多显示5秒钟 If iTime <> 0 Then lCW = lCW + 1 iScorce = iScorce - 1 If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce '" ' , "统计" End If iTime = 0 bOK = False Me.Cls Randomize i = Int(Rnd() * Me.ScaleWidth - 500) j = Int(Rnd() * Me.ScaleHeight - 500) k = Int(Rnd() * 90) + 10 '字号 l = Int(Rnd() * 26) '产生52个字母的其中一个 'l = Int(Rnd() * 53) '产生52个字母的其中一个 If l <= 25 Then '大写 l = 65 + l Else l = 97 + l - 26 End If iCode = l '记录 Me.CurrentX = i Me.CurrentY = j Me.FontSize = k Me.Print Chr(l) iNum = iNum + 1 l = 0 Else Me.Cls l = l + 1 If i - 100 * l < 100 Then l = 0 Me.CurrentX = Me.Width - 500 i = Me.Width - 500 Else Me.CurrentX = i - l * 100 End If Me.CurrentY = j Me.FontSize = k Me.Print Chr(iCode) End If If iNum >= 100 Then GoTo OVER iTime = iTime + 1 lTime = lTime + 1 Exit Sub OVER: Me.Timer1.Enabled = False dStop = Time If iScorce < 0 Then iScorce = 0 Me.lblInfo.Caption = "总耗时:" & Round((dStop - dStart) * 24 * 3600, 2) & "秒," & vbCrLf & "总字数:" & iNum & ";正确数量:" & lZQ & ";错误数量:" & lCW & ";正确率:" & Round(lZQ / iNum * 100, 2) & "%;得分:" & iScorce lTime = 0 iTime = 0 iNum = 0 End Sub。
5.c语言中怎么写打地鼠的游戏
在一个二维数组中,存放标记。
设置难度:分:
一次只显示一个
一次只显示二个
一次只显示三个
对应产生2*N个随机数,对应(x,y),设置为1,其它空的设置为0.
大概的游戏流程循环:
结束条件: 打到M个停止。
1,产生随机数,且不相同
2,在对应的坐标中,画出地鼠,
在N秒内,没有击中,地鼠消失;击中,加分。
(击中的坐标,要与用户点的坐标想比较即可,在这个范围就得分)
转载请注明出处众文网 » 打地鼠游戏设计毕业论文