home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter02 / demo02-11.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  1.1 KB  |  41 lines

  1. ;demo02-11.bb - Try to guess the number
  2. Print "Welcome to the Guessing Game!"
  3. AppTitle "Guessing Game!"
  4. ;Seed the random generator...don't worry, it willl be explained later 
  5. SeedRnd MilliSecs() 
  6.  
  7. ;Pick a number between 1 and 100
  8. numbertoguess = Rand(1,100) 
  9.  
  10. ;The num of guesses the user has used
  11. numofguesses = 0
  12.  
  13. ;set the beginning of loop label
  14. .loopbegin 
  15.     ;Find out the user's guess
  16.     guess = Input$("Guess a number ") 
  17.  
  18.     ;If player guesses outside of range, tell him to guess again
  19.     If guess > 100 Or guess < 1 
  20.         Print "Pick a number between 1 and 100, silly!"
  21.         ;Go back to the beginning
  22.         Goto loopbegin
  23.         
  24.     EndIf
  25.     
  26.     ;Add a guess to the guess counter
  27.     numofguesses = numofguesses + 1  
  28.  
  29.     ;If the guess is too low, go back to beginning
  30.     If guess < numbertoguess Then 
  31.         Print "The number was too low."
  32.         Goto loopbegin
  33.     ;If guess is too high, go back to the beginning
  34.     Else If guess > numbertoguess Then 
  35.         Print "The number was too high."
  36.         Goto loopbegin
  37.     EndIf
  38.  
  39.  
  40. Print "You guessed the number " + numbertoguess + " in " + numofguesses  + " tries!." 
  41. WaitKey