2016-08-21 7 views
1

だから私は少し紛失している。私は、クラスのための "数字の推測"ゲームのためにこのスクリプトに取り組んでおり、今まで私は成功しています。今度は、ユーザーがあまりにも高いか低いかを推測すると、どれだけ離れているかについてのより良い手がかりを与えなければならないという課題があります。VBScript数字を推測する

たとえば、ユーザーが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 

答えて

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() 
関連する問題