home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming for Teens (2nd Edition) / 3DGPFT2E.iso / Source / Chapter02 / demo02-11.bb < prev    next >
Encoding:
Text File  |  2009-01-21  |  1.2 KB  |  39 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 will 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. ;set the beginning of loop label
  13. .loopbegin 
  14.        ;Find out the user's guess
  15.        guess = Input$("Guess a number ") 
  16.  
  17.        ;If player guesses outside of range, tell him to guess again
  18.        If guess > 100 Or guess < 1 
  19.               Print "Pick a number between 1 and 100, silly!"
  20.               ;Go back to the beginning
  21.               Goto loopbegin
  22.               
  23.        EndIf
  24. ;Add a guess to the guess counter
  25. numofguesses = numofguesses + 1  
  26.  
  27. ;If the guess is too low, go back to beginning
  28. If guess < numbertoguess Then 
  29.        Print "The number was too low."
  30.        Goto loopbegin
  31. ;If guess is too high, go back to the beginning
  32. Else If guess > numbertoguess Then 
  33.        Print "The number was too high."
  34. Goto loopbegin
  35. EndIf
  36. Print "You guessed the number " + numbertoguess + " in " + numofguesses  + " tries!" 
  37.  
  38. ;Wait five seconds
  39. Delay 5000