【VB】猜数字

经典小游戏:猜数字
附工程链接
可执行程序

Public Function calc() As Long
    Randomize
    calc = Int(Rnd * 100) + 1
End Function

Private Sub guess_Click()
  '  If Val(redo.Tag) = 0 Then result.Caption = "快去重置吧!"
    Dim tmp As Long
    tmp = Val(read.Text)
    read.Text = ""
    guess.Tag = Str(Val(guess.Tag) + 1)
    If tmp < redo.Tag Then
        result.Caption = "Small!"
        mini.Caption = Str(tmp)
        'If tmp > Val(mini.Caption) Then
    ElseIf tmp > redo.Tag Then
        result.Caption = "Big!"
        maxi.Caption = Str(tmp)
       ' If tmp < Val(maxi, Caption) Then
    Else
        result.Caption = "Congratulations!" + Chr(10) + "答案是" + Str(tmp) + Chr(10) + "你只用了" + Str(guess.Tag) + "次机会就猜到了!"
        redo.Tag = 0
    End If
End Sub

Private Sub redo_Click()
    guess.Tag = "0": mini.Caption = "1": maxi.Caption = "100"
    Label1.Caption = "~": result.Caption = "": read.Text = ""
    redo.Tag = Str(calc())
    Do While Val(redo.Tag) < 1 Or Val(redo.Tag) > 100
        redo.Tag = Str(calc())
    Loop
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值