VB制作小游戏源代码

 我来答
卓7358
2010-11-11
知道答主
回答量:4
采纳率:0%
帮助的人:0
展开全部
猜数字
建一个文本文档,输入以下代码,后缀改为.frm用vb打开就可以了
以下是程序源码:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "猜数游戏"
ClientHeight = 3900
ClientLeft = 45
ClientTop = 435
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3900
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "重新开始"
Height = 615
Left = 2640
TabIndex = 2
Top = 2760
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "确定"
Height = 615
Left = 840
TabIndex = 1
Top = 2760
Width = 1095
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 0
Top = 2040
Width = 2055
End
Begin VB.Label Label9
Caption = "戏"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 615
Left = 3720
TabIndex = 11
Top = 240
Width = 615
End
Begin VB.Label Label8
Caption = "游"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00808080&
Height = 615
Left = 3240
TabIndex = 10
Top = 240
Width = 615
End
Begin VB.Label Label7
Caption = "数"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FFFF&
Height = 495
Left = 2760
TabIndex = 9
Top = 240
Width = 615
End
Begin VB.Label Label6
Caption = "猜"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF00FF&
Height = 495
Left = 2280
TabIndex = 8
Top = 240
Width = 735
End
Begin VB.Label Label5
Caption = "入"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 615
Left = 1800
TabIndex = 7
Top = 240
Width = 855
End
Begin VB.Label Label4
Caption = "进"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FF00&
Height = 735
Left = 1320
TabIndex = 6
Top = 240
Width = 735
End
Begin VB.Label Label3
Caption = "迎"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFF00&
Height = 735
Left = 840
TabIndex = 5
Top = 240
Width = 735
End
Begin VB.Label Label2
Caption = "欢"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 615
Left = 360
TabIndex = 4
Top = 240
Width = 495
End
Begin VB.Label Label1
Caption = "我这儿有1~10的整数,你猜猜看他是多少......"
Height = 375
Left = 480
TabIndex = 3
Top = 1320
Width = 3855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim x As Integer, y As Integer, z As Integer
Dim cishu As Integer
Private Sub Command1_Click()

If cishu = 3 Then MsgBox "已经猜3次了,这个数是" & x: Exit Sub
y = Val(Text1.Text)

If Text1.Text = "" Or Not IsNumeric(Text1.Text) Then
MsgBox "输入有误!请重新输入数字", 48
Text1.Text = ""
Text1.SetFocus
Exit Sub

End If

cishu = cishu + 1
Select Case x - y
Case Is < 0
z = MsgBox("你猜数大了,请重猜。注意:你只有三次机会", 48 + 1)
Text1.Text = ""
Text1.SetFocus
Case Is > 0
z = MsgBox("你猜数小了,请重猜。注意:你只有三次机会", 48 + 1)
Text1.Text = ""
Text1.SetFocus
Case Else
z = MsgBox("恭喜你猜中了!", 1)
End Select

End Sub

Private Sub Command2_Click()

cishu = 0
Randomize Timer
x = Int((Rnd * 10) + 1)
End Sub

Private Sub Form_Load()

cishu = 0
Randomize Timer
x = Int((Rnd * 10) + 1)
End Sub
代码结束
http://hi.baidu.com/卓7358/
欢迎来我空间
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式