home *** CD-ROM | disk | FTP | other *** search
/ Millennium Time Capsule / AC2000.BIN / disks / ac6_disk / tutorial.s / hbasic3.tut / explain.txt < prev    next >
Encoding:
Text File  |  1997-06-12  |  3.1 KB  |  103 lines

  1.  
  2. This text file explains what the source code does, line by line.
  3.  
  4. REM $option k10
  5. REM $option y+,v+,u+,[,]
  6. REM $option fNUMGAME.TOS
  7.  
  8. These three lines set the options flags. The k option tells HBASIC how 
  9. much memory to give to the program. The y+ is to get rid of the main 
  10. window, v+ to check variables, u+ to underlines in variables, the "[" 
  11. to select array warnings and "]" to allow undefined sub-programs. The 
  12. 'f' option sets the name of the output file when compiling.
  13.  
  14. DEF FNgen
  15. STATIC y
  16.  
  17. DO
  18. y=CINT(RND*1000)
  19. LOOP UNTIL y<1000 AND y>0
  20. FNgen=y
  21.  
  22. END DEF
  23.  
  24. Our function called gen. This routines makes sure that a number 
  25. generated with RND (which is always below 1, so it's multiplied by 
  26. 1000 to get a decent number, and rounded off with the CINT function) 
  27. is put into y. This routines makes sure the number is below 1000 but 
  28. above 0.
  29.  
  30. SUB game
  31. STATIC num,low,high,turn,a,a$
  32.  
  33. RANDOMIZE
  34.  
  35. The RND function would normally give the same number all the time, but 
  36. this RANDOMIZE function gives a new lot of numbers for the RND to use.
  37.  
  38. num=FNgen
  39.  
  40. turn=0
  41. low=1
  42. high=999
  43.  
  44. Get our generated number and put it in num, also, make sure the 
  45. options here (turn is the number of turns, low is the lowest number 
  46. range and high is the highest number range).
  47.  
  48. DO
  49. INCR turn
  50. PRINT "Turn:";turn
  51. PRINT "The number is between";low;"and";high
  52. PRINT
  53.  
  54. Display our info on turn number, low and high ranges.
  55.  
  56. INPUT "What do you think the number is? ",a
  57.  
  58. IF a>999 THEN STOP
  59. IF a<num THEN PRINT "The number is greater than";a : IF a>low THEN low=a
  60. IF a>num THEN PRINT "The number is below";a : IF a<high THEN high=a
  61. IF a=num THEN
  62.     PRINT
  63.     PRINT "Congratulations! The number was";num;"and you guessed correctly in";turn;"turns!" : a=1000
  64.     PRINT
  65. END IF
  66.  
  67. The the user's number and put it into a. Then we have a check to see 
  68. if the number is above/below the generated one. If the generated 
  69. number is greater than a, the program will check to see if the user's 
  70. number is above the lowest range, and if it is it will change the 
  71. lowest to that number. It also checks the number for the highest too. 
  72. If you get the right number, it tells you congratulations and tells 
  73. you the number and how many turns it took.
  74.  
  75. PRINT 
  76. LOOP UNTIL a>999
  77.  
  78. PRINT "Would you like another game?"
  79.  
  80. DO
  81. a$=UCASE$(INKEY$)
  82. LOOP UNTIL a$="Y" OR a$="N"
  83.  
  84. IF a$="Y" THEN CALL game
  85.  
  86. END SUB
  87.  
  88. Once finished a game, the computer displays "Would you like another 
  89. game?". The above code involving the INKEY$ gets a key from the 
  90. keyboard. The UCASE$ turns this code into upper case, if I pressed 'y' 
  91. then the computer would turn this to 'Y'. If the answer is yes, it 
  92. will call the routine again.
  93.  
  94. PRINT "Paul's number guessing game. "+CHR$(189)+" Copyright to Paul Jones and Atari Computing"
  95. PRINT "1997. Example program using SUB/FUNCTIONS and maths functions as in"
  96. PRINT "tutorial #3."
  97.  
  98. CALL game
  99. STOP -1
  100.  
  101. Displays information at the start of the program, and then calls the 
  102. main game sub routine. The STOP -1 tells the program to quit (once the 
  103. main game has finished).