VBScript猜一个数字

时间:2016-08-21 00:43:42

标签: vbscript

所以我有点失落。我一直在为这个剧本编写一个“Guess a Number”游戏,到目前为止我已经成功了。现在,分配要求当用户猜到太高或太低时,它应该给他们更好的线索,告诉他们有多远。

例如,如果用户距离50个数字,则应通知他们感冒。如果他们是30个数字,他们是温暖的,10个数字,他们是热...

我无法理解那部分。

非常感谢任何帮助。

Initialization Section

Option Explicit

Const cGreetingMsg = "Pick a number between 1 - 100"

Dim intUserNumber, intRandomNo, strOkToEnd, intNoGuesses

intNoGuesses = 0

'Main Processing Section

'Generate a random number
Randomize
intRandomNo = FormatNumber(Int((100 * Rnd) + 1))

'Loop until either the user guesses correctly or the user clicks on     Cancel
Do Until strOkToEnd = "yes"

  'Prompt user to pick a number
  intUserNumber = InputBox("Type your guess:",cGreetingMsg)
  intNoGuesses = intNoGuesses + 1

  'See if the user provided an answer
  If Len(intUserNumber) <> 0 Then

    'Make sure that the player typed a number
    If IsNumeric(intUserNumber) = True Then

      'Test to see if the user's guess was correct
      If FormatNumber(intUserNumber) = intRandomNo Then
        MsgBox "Congratulations! You guessed it. The number was " & _
          intUserNumber & "." & vbCrLf & vbCrLf & "You guessed it " & _
          "in " & intNoGuesses & " guesses.", ,cGreetingMsg
        strOkToEnd = "yes"
      End If

      'Test to see if the user's guess was too low
      If FormatNumber(intUserNumber) < intRandomNo Then
        MsgBox "Your guess was too low. Try again", ,cGreetingMsg
        strOkToEnd = "no"
      End If

      'Test to see if the user's guess was too high
      If FormatNumber(intUserNumber) > intRandomNo Then
        MsgBox "Your guess was too high. Try again", ,cGreetingMsg
        strOkToEnd = "no"
      End If

    Else
      MsgBox "Sorry. You did not enter a number. Try again.", ,     cGreetingMsg
    End If

  Else
    MsgBox "You either failed to type a value or you clicked on Cancel.     " & _
      "Please play again soon!", , cGreetingMsg
    strOkToEnd = "yes"
  End If

Loop

1 个答案:

答案 0 :(得分:0)

您的问题可能不适合S.O.无论如何我会给你一个提示,因为我曾经穿过你的鞋子......

这会响铃吗?

coldThresHold = 20

If userNumber = intRandomNo + coldThresHold Then YouGuessed()
Else If userNumber > intRandomNo + coldThresHold Then YouAreCold()
Else If userNumber > intRandomNo Then YouAreHot()
Else If userNumber < intRandomNo - coldThresHold Then YouAreCold()
Else userNumber < intRandomNo Then YouAreHot()