home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0950.lha / BBDoors / BBDoors65.lha / rexxDoors / Number_Guesser.rexx < prev    next >
OS/2 REXX Batch file  |  1993-08-08  |  5KB  |  194 lines

  1. /*            The WORLD FAMOUS ARexx Number Guesser v2.2c
  2.      Written by Charles Johnston of CrazySoft Inc. Prescott,AZ (03-08-93)
  3.             FREELY DISTRIBUTABLE as long as this notice remains 
  4.     Comments may be sent to Charles (Sysop) Crazy Train BBS (602)771-8971*/
  5.  
  6. CR="0D"x
  7. CALL TIME('R')
  8. SIGNAL ON BREAK_C
  9. SIGNAL ON BREAK_E
  10. CLS=d2c(12)
  11.  
  12.  PARSE arg Username winnings . colorflag  secs .
  13.  IF ~DATATYPE(secs,'N') THEN secs=3600
  14.  def=''
  15.  red=''
  16.  grn=''
  17.  yel=''  /*Turns off ANSI codes but then checks users colorflag below*/
  18.  blu=''
  19.  mag=''
  20.  cyn=''
  21.  wht=''
  22.  
  23.  IF colorflag=1 THEN    /* let's see some color!*/
  24.    DO
  25.      def=''
  26.      red=''
  27.      grn=''
  28.      yel=''
  29.      blu=''
  30.      mag=''
  31.      cyn=''
  32.      wht=''
  33.    END
  34.  
  35. bbspath=GETCLIP('BBS_path')      /*retrieve  bbs path so our prg is generic*/
  36. filename=bbspath'rexxDoors/data/top10'
  37. If ~exists(filename) then
  38. do 
  39.  call open('top10',filename,'w')
  40.   do 10
  41.    line = '9 Charles_Johnston'
  42.    call writeln('top10',line)
  43.    end
  44.  call close('top10')
  45. end
  46.  
  47.  
  48.  
  49.  
  50.  
  51. call message cls
  52. say ''||CR
  53. IF OPEN('top10',filename,'r') THEN
  54.    DO
  55.       DO m = 1 TO 10 UNTIL EOF('top10')
  56.          line.m = readln('top10')
  57.       END
  58.       CALL CLOSE('top10')
  59.       m = m - 1
  60.    END
  61. name = UPPER(username)
  62. call message cls
  63. say ''||CR
  64. options prompt mag'Would you like to see the TOP TEN scores' name'?'
  65. pull answer
  66.  
  67. say ''||CR
  68. if answer ~='Y' then call start
  69. if answer = 'Y' then CALL Showtop10()
  70.  
  71.  say ''||CR
  72.  options prompt yel'Are you ready to play' name'? (Y/N)'
  73.  pull answer
  74.  if answer ~='Y' then call OUT
  75.  else call start
  76.  
  77.  
  78. start:
  79. call message cls
  80. answer = random(1,1000,time(s))
  81. say wht'   ---------------------------------------------------------------------'||CR
  82. say wht'    |                                                                 |'||CR
  83. say wht'    |'red' -----=====>>>>>' wht'  N U M B E R   G U E S S E R 'red ' <<<<<=====-----'wht' |'||CR
  84. say wht'    |                                                                 |'||CR
  85. say wht'    |'yel'  Ver 2.2c -'grn' Written for Baud Bandit BBS'yel' - by Charles Johnston'wht'   |'||CR
  86. say wht'    |'mag'              CrazySoft Inc.'cyn'     Prescott,Arizona'wht'                |'||CR
  87. say wht'    |                                                                 |'||CR
  88. say wht'   ---------------------------------------------------------------------'||CR
  89. say ''||CR
  90. say yel'     I am thinking of a number between 1 and 1000....You get 10 turns!'||CR          
  91.  do number = 1 to 10 until guess = answer
  92.    CALL checkBBS()
  93.    say ''||CR
  94.    Options prompt mag'     Q=Quit'wht' OR 'red' Enter Your Guess => '
  95.    pull guess
  96.    remaining = 11 - (number+1)
  97.    if guess = 'Q' then call OUT
  98.    if answer > guess then                          
  99.    say yel'     'guess''wht' is just a little bit too'grn' LOW!....'yel''remaining''wht' turns left'||CR
  100.    else if answer < guess then                    
  101.    say yel'     'guess''wht' is just a little bit too 'mag'HIGH!...'yel''remaining''wht' turns left'||CR
  102.  end
  103.  
  104. if guess ~= answer then 
  105.   do
  106.     say ''||CR
  107.     say red'     You used all'mag' 10'red' turns!'||CR
  108.     say wht'     Better luck'yel' NEXT'wht' time!'||CR
  109.     say grn'     The'yel' correct'grn' number was'yel'' answer '!'||CR    
  110.   end
  111. else
  112.   do
  113.     say ''||CR
  114.     say wht'     You got it in'red'' number ''wht'turns!'||CR
  115.     call delay(200)
  116.  
  117.    /* Sort and add to list only if it is better than 10th score */ 
  118.    IF number < number.10 & number < 10 THEN 
  119.       DO
  120.          line.10 = number' 'name 
  121.          CALL is(1, m)
  122.          CALL Showtop10()
  123.          CALL DELETE(filename)
  124.          CALL OPEN('top10',filename,'w')
  125.          DO i = 1 TO m
  126.             CALL WRITELN('top10',line.i)
  127.          END
  128.          call close('top10')
  129.       END
  130.  
  131.   END
  132. say ''||CR
  133. Options prompt cyn'     Would you like to try again?'grn' > '
  134. pull again
  135. if again = 'Y' then call start
  136. if again ~= 'Y' then call OUT
  137. else
  138. BREAK_C:
  139. BREAK_E:
  140. exit
  141.  
  142.  
  143. checkBBS:
  144. IF ADDRESS()~='BAUD' THEN RETURN 0
  145. IF TIME('E')>secs THEN SIGNAL OUT
  146. dcd
  147. IF RC=0 THEN EXIT
  148. temp=secs-TIME('E')
  149. IF temp<120 THEN SAY '*** Only' temp 'seconds left! ***'CR 
  150. RETURN 0
  151.  
  152.  
  153. /* Insertion Sort */
  154. /* line s list to be sorted, start should be 1, end is max number of lines */
  155. /* line is a compound variable from line.1 to line.end  */
  156. is:
  157.    DO i = 2 to m
  158.       x = line.i
  159.       j = i - 1
  160.       DO WHILE j > 0 & x < line.j
  161.          k = j + 1
  162.          line.k = line.j
  163.          j = j - 1
  164.       END
  165.       k = j + 1
  166.       line.k = x
  167.    END
  168. RETURN
  169.         
  170. Showtop10:
  171.   say'0C'x
  172.   say mag CENTER(' *******************************************',75)||CR
  173.   say ''||CR
  174.   say wht CENTER('        N U M B E R    G U E S S E R      ',75)||CR
  175.   say ''||CR
  176.   SAY mag CENTER(' ********** Top'yel' TEN'mag' Hall of Fame ********',75)||def||CR
  177.   say ''||CR
  178.   DO i = 1 TO m 
  179.      PARSE VAR line.i number.i name.i
  180.      name.i = COPIES(' ',24)name.i
  181.      number = COPIES(' ',52)number.i
  182.      SAY''OVERLAY(name.i, number)''cr
  183.   END
  184. RETURN
  185.  
  186. message:
  187. parse arg string
  188. say string||CR
  189. return
  190.  
  191. out:
  192.  call message cls
  193.  say mag' Now returning to BBS.....'
  194.  exit