home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 15 / 015.d81 / lk.higher-lower < prev    next >
Text File  |  2022-08-26  |  2KB  |  78 lines

  1. 0010 //higher-lower game -- written in
  2. 0020 //comal by joel ellis rea for
  3. 0030 //the comal corner section of
  4. 0040 //loadstar -- july, 1985
  5. 0050 //
  6. 0060 title'and'instructions
  7. 0070 repeat 
  8. 0080 number#:=rnd(0,999)
  9. 0090 tries#:=0
  10. 0100 repeat 
  11. 0110 guess#:=get'guess#
  12. 0120 tries#:+1
  13. 0130 case sgn(number#-guess#) of
  14. 0140 when -1
  15. 0150 too'high(guess#)
  16. 0160 when 0
  17. 0170 just'right(guess#,tries#)
  18. 0180 when 1
  19. 0190 too'low(guess#)
  20. 0200 endcase 
  21. 0210 until number#=guess#
  22. 0220 until not play'again#
  23. 0230 //
  24. 0240 proc title'and'instructions closed
  25. 0250 print chr$(147), //clear screen
  26. 0260 print "higher-lower game"
  27. 0270 print "by joel ellis rea"
  28. 0280 print 
  29. 0290 print "i will think of a number between 0 and"
  30. 0300 print "999, and you try to guess it.  after"
  31. 0310 print "each guess, i  will tell you if you"
  32. 0320 print "are too high or too low.  it should"
  33. 0330 print "take you no more than 12 guesses!"
  34. 0340 print 
  35. 0350 endproc title'and'instructions
  36. 0360 //
  37. 0370 func get'guess# closed
  38. 0380 repeat 
  39. 0390 input "your guess? ": guess#
  40. 0400 if guess#<0 or guess#>999 then
  41. 0410 print guess#;"isn't between 0 and 999!"
  42. 0420 print 
  43. 0430 endif 
  44. 0440 until guess#>=0 and guess#<=999
  45. 0450 return guess#
  46. 0460 endfunc get'guess#
  47. 0470 //
  48. 0480 proc too'high(guess#) closed
  49. 0490 print guess#;"is too high!  try a lower number."
  50. 0500 print 
  51. 0510 endproc too'high
  52. 0520 //
  53. 0530 proc too'low(guess#) closed
  54. 0540 print guess#;"is too low!  try a higher number."
  55. 0550 print 
  56. 0560 endproc too'low
  57. 0570 //
  58. 0580 proc just'right(guess#,tries#) closed
  59. 0590 print guess#;"is my number!  it took you";tries#;"tries!"
  60. 0600 print 
  61. 0610 endproc just'right
  62. 0620 //
  63. 0630 func play'again# closed
  64. 0640 dim key'press$ of 1
  65. 0650 print "do you want to play again?";
  66. 0660 repeat 
  67. 0670 key'press$:=key$
  68. 0680 until key'press$ in "YyNn"
  69. 0690 if key'press$ in "Yy" then
  70. 0700 print "yeah!"
  71. 0710 return true
  72. 0720 else 
  73. 0730 print "nope."
  74. 0740 return false
  75. 0750 endif 
  76. 0760 endfunc play'again#
  77. 0770 //
  78.