VB6.0麻烦看一下,怎么在这个猜数字游戏里做一个计

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:06:02
Dim guess As Integer
Dim magic As Integer
Dim score As Integer
Dim limit As Integer
Private Sub Command1_Click()
guess = Val(Text1.Text)
Select Case guess
Case magic
Label7.Caption = Str(guess) + " 完全正确!" + Chr(13) + Chr(10) + "换下一个数了!" + Chr(13) + Chr(10) + "猜猜看吧!"
score = score + 1
magic = Int(Rnd() * 101)
Case Is > magic
Label7.Caption = Str(guess) + "太大了," + Chr(13) + Chr(10) + "再想想吧!"
Case Is < magic
Label7.Caption = Str(guess) + "太小了," + Chr(13) + Chr(10) + "再想想吧!"
End Select
Text1.Text = ""
Label8.Caption = Str(score)
End Sub

Private Sub Command2_Click()
score = 0
limit = Val(Text2.Text)
magic = Int(Rnd() * 101)
Label7.Caption = "计时开始了!" + Chr(10) + Chr(13) + "猜猜看吧!"
Command1.Enabled = True
Text1.Locked = False
Text

其他不变,只增加几行代码:

Private Sub Command2_Click()
score = 0
limit = Val(Text2.Text)
Randomize
magic = Int(Rnd() * 101)
Do While (magic Mod 2) = 0 '修改部分
DoEvents
magic = Int(Rnd() * 101)
Loop
Label7.Caption = "计时开始了!" + Chr(10) + Chr(13) + "猜猜看吧!"
Command1.Enabled = True
Text1.Locked = False
Text1.SetFocus
Label8.Caption = Str(score)
Timer1.Interval = 1000 '修改部分
Timer1.Tag = "begin"
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Static seconds As Integer
If Timer1.Tag = "begin" Then seconds = 0: Timer1.Tag = "" '修改部分
label10 = seconds '修改部分
If seconds >= limit Then
Label7.Caption = "时间到!" + Chr(13) + Chr(10) + "这个数是" + Str(magic)
Timer1.Enabled = False
Text1.Locked = True
Command1.Enabled = False
seconds = 0
End If
seconds = seconds +