vb猜数字游戏编程 要求:让电脑猜一个0-100的数字(由玩家想好) 直到猜对为止 要用
发布网友
发布时间:2022-05-12 05:43
我来回答
共2个回答
热心网友
时间:2023-11-22 22:47
Dim state As Integer '状态 0表示没开始 1表示已开始
Dim min As Integer '最小值
Dim max As Integer '最大值
Dim now As Integer '中值
Dim c As Integer '猜的次数
Private Sub Command1_Click() '开始
state = 1
Guess
End Sub
Private Sub Command2_Click() '小了
If state = 0 Then MsgBox "还没开始呢!": Exit Sub
min = now
Guess
End Sub
Private Sub Command3_Click() '大了
If state = 0 Then MsgBox "还没开始呢!": Exit Sub
max = now
Guess
End Sub
Private Sub Command4_Click() '正确
If state = 0 Then MsgBox "还没开始呢!": Exit Sub
state = 0
MsgBox "哇哇,我太厉害了,才猜" & c & "次就猜中了!"
End Sub
Private Sub Form_Load()
state = 0
min = 0
max = 100
c = 0
End Sub
Function GetMid() As Integer '取得中值
GetMid = (max - min) / 2 + min
End Function
Sub Guess() '电脑猜测
now = GetMid
c = c + 1
MsgBox "我猜是" & now & "!"
End Sub
热心网友
时间:2023-11-22 22:47
哪个SB设计的给电脑玩的游戏 这应该是给人玩的把 。。。。 给电脑玩不是一秒就能出答案么?