怎样用VB编写打字小游戏?

组件:对象:属性:属性值:form1coption游戏设置startUpPosition2-屏幕中心Label1AutoSizeTruecoption请设置游戏的速度和难... 组件:
对象: 属性: 属性值:
form1 coption 游戏设置
startUpPosition 2-屏幕中心
Label1 AutoSize True
coption 请设置游戏的速度和难度
Font 幼园,粗体,小四
ForeColor 红色
Command1 coption 确定
Command2 coption 推出
Frame1 coption 速度
font 宋体,小四
forecolor 蓝色
Frame2 coption 难度
font 宋体,小四
forecolor 蓝色
option1 coption 低速
option2 coption 中速
option3 coption 高速
option4 coption 小写字母
option5 coption 大写字母
option6 coption 所有混合(全盘只要有ASCII的都要)

form2 coption 运指如飞
startUpPosition 2-屏幕中心
Label2 AutoSize True
coption 你现在得分:
Font 宋体,粗体,小四
ForeColor 红色
Label3 AutoSize True
coption ""(置空)
Font 宋体,粗体,小四
ForeColor 黑色
timer1 Interval 100
Image1 Stretch True

大致上就是这样了..运行确定按钮后,字母或数字其他的就由上面掉下来.
然后要是在键盘上点击中该键的ASCII之后图片就会在该点出现.然后释放按键时就触发了键盘的KeyUp事件.Image1.Visible=False
展开
 我来答
井慕诗V9
2009-06-10 · TA获得超过155个赞
知道小有建树答主
回答量:321
采纳率:0%
帮助的人:125万
展开全部
我2年前写的,有点幼稚。别见笑
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
Caption = "打字游戏 小游戏而已"
ClientHeight = 4800
ClientLeft = 60
ClientTop = 750
ClientWidth = 5610
LinkTopic = "Form1"
ScaleHeight = 4800
ScaleWidth = 5610
StartUpPosition = 1 '所有者中心
Begin VB.Timer Timer1
Left = 0
Top = 3600
End
Begin VB.Label Label1
Caption = "Label1"
Height = 735
Index = 0
Left = 1320
TabIndex = 0
Top = 600
Width = 855
End
Begin VB.Menu MenuGame
Caption = "数量 (&N)"
Index = 0
End
Begin VB.Menu MenuGame
Caption = "速度 (&P)"
Index = 1
End
Begin VB.Menu MenuGame
Caption = "重置 (&R)"
Index = 2
End
Begin VB.Menu MenuGame
Caption = "开始 (&S)"
Index = 3
End
Begin VB.Menu MenuGame
Caption = "输赢 (&W)"
Index = 4
End
Begin VB.Menu MenuGame
Caption = "帮助 (&H)"
Index = 5
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim StartPause As Boolean
Dim n As Integer
Dim Speed As Integer
Dim Down As Integer, Hit As Integer
Dim DownLost As Integer, HitWin As Integer

Rem 自定义函数效率不高啊。。。

Private Sub Form_Initialize()
Speed = 10
DownLost = 100
HitWin = 100
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Randomize
For Index = 0 To n
If Chr(KeyCode) = Label1(Index).Caption Then
With Label1(Index)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
Hit = Hit + 1
Me.Caption = "打字游戏 " & "掉落: " & Down & " 命中: " & Hit

End If
Next Index
End Sub

Private Sub Form_Load()
On Error Resume Next

Timer1.Interval = 10
Timer1.Enabled = False
Randomize
With Label1(0)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
.Left = Rnd * (Me.ScaleWidth - Label1(0).Width)
.FontSize = 30
.BackStyle = 0
End With

For Index = 1 To n
Load Label1(Index)
With Label1(Index)
.Visible = True
.FontSize = 30
.BackStyle = 0
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
Next Index
End Sub

Private Sub MenuGame_Click(Index As Integer)
On Error Resume Next

Select Case Index
Case 0
n = Int(InputBox("输入数量,建议输入1至5,如果输入0或者按取消,将会去缺省值1", "输入数量") - 1)
Form_Load
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 1
Speed = Int(Val(InputBox("输入速度参数,建议5-20,如果输入0或按取消,将会取缺省值0,就是不会移动", "输入速度参数")))
Timer1.Enabled = False
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 2
Hit = 0
Down = 0
Form_Load
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 3
StartPause = Not StartPause
If StartPause = True Then
MenuGame(3).Caption = "暂停 (&P)"
Timer1.Enabled = True
ElseIf StartPause = False Then
MenuGame(3).Caption = "开始 (&S)"
Timer1.Enabled = False
End If
Case 4
HitWin = Int(InputBox("输入数字,当命中数等于该数时即为胜利。", "输入数字"))
DownLost = Int(InputBox("输入数字,当掉落数等于该数时即为胜利。", "输入数字"))
Case 5
MsgBox "目前没有编辑帮助"
End Select
End Sub

Private Sub Timer1_Timer()
Randomize
For Index = 0 To n
Label1(Index).Top = Label1(Index).Top + Speed
If Label1(Index).Top >= Me.ScaleHeight Then
With Label1(Index)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End With
Down = Down + 1
Me.Caption = "打字游戏 " & "掉落 " & Down & " 命中 " & Hit

End If
Next Index

If Down >= DownLost Then MsgBox "你输啦!", vbOKOnly, "You lost": End
If Hit >= HitWin Then MsgBox "你赢啦!", vbOKOnly, "You Win": End
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式