).Enabled = False
End If
注释:判断用户输入了几位,如果输入了四位则确认按钮有效
If Num = 4 Then
Command2.Enabled = True
End If
注释:取得用户输入
Select Case Index
Case 0
UserEnter (0) 注释:调用UserEnter过程
Case 1 UserEnter (1)
Case 2 UserEnter (2)
Case 3 UserEnter (3)
Case 4 UserEnter (4)
Case 5 UserEnter (5)
Case 6 UserEnter (6)
Case 7 UserEnter (7)
Case 8 UserEnter (8)
Case 9 UserEnter (9)
End Select
End Sub
Private Sub Command2_Click()
注释:单击确定按钮时
注释:判断用户输入是否正确
Dim A, B As Integer
A = 0
B = 0
Degree = Degree + 1
If UserA = PcA Then
A = A + 1
ElseIf UserA = PcB Or UserA = PcC Or UserA = PcD Then
B = B + 1
用Visual BASIC 6.0 开发猜数字小游戏 End If
If UserB = PcB Then
A = A + 1
ElseIf UserB = PcA Or UserB = PcC Or UserD = PcD Then
B = B + 1
End If
If UserC = PcC Then
A = A + 1
ElseIf UserC = PcA Or UserC = PcB Or UserC = PcD Then
B = B + 1
End If
If UserD = PcD Then
A = A + 1
ElseIf UserD = PcA Or UserD = PcB Or UserC = PcC Then
B = B + 1
End If
注释:显示提示
Label1.Caption = A & “A" & B & “B"
List1.AddItem UserA & UserB & UserC & UserD & “ " & Label1.Caption
注释:初始化输入按钮
Command2.Enabled = False
For i = 0 To 9
Command1(i).Enabled = True
Next i
Num = 1
注释:判断输赢
If A = 4 Then
MsgBox “你猜对了!" & “你一共猜了" & Degree & “次"
For i = 0 To 9
Command1(i).Enabled = False
Next i
Command2.Enabled = False
End If
End Sub
Private Sub Command3_Click()
注释:单击取消按钮时
Num = 1
For i = 0 To 9
Command1(i).Enabled = True
Next i
Command2.Enabled = False
End Sub
Private Sub View_Click()
注释:显示
答案时
MsgBox “
答案是:" & PcA & PcB & PcC & PcD &“你答对了吗?"
End Sub
Private Sub End_Click()
注释:游戏结束时
End
End Sub
Sub UserEnter(i) 注释:取得用户输入
If Num = 1 Then
UserA = i
Num = Num + 1
ElseIf Num = 2 Then
UserB = i
Num = Num + 1
ElseIf Num = 3 Then
UserC = i
Num = Num + 1
ElseIf Num = 4 Then
UserD = i
Num = Num + 1
Else: MsgBox “四位数够了!"
End If
End Sub
运行
程序,选择新游戏,就可以开始玩你自己开发的游戏了。
上面
程序在Win95,VB6下运行通过。