home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1994 October / SOFM_Oct1994.bin / pc / os2 / uguess / uguessit.cmd < prev    next >
OS/2 REXX Batch file  |  1994-03-29  |  14KB  |  661 lines

  1. /*REXX*/
  2.  
  3.   signal on HALT    name HaltExit
  4.   /***
  5.   signal on ERROR   name ErrorExit
  6.   signal on FAILURE name FailureExit
  7.   signal on SYNTAX  name SyntaxExit
  8.   ***/
  9.  
  10. main:
  11. parse arg p1
  12.   fPDInit  = 'N'
  13.   fDebug   = 'N'
  14.   fDispStax= 'N'
  15.   fDispHelp= 'N'
  16.   fUnique  = 'N'
  17.   fWav     = 0
  18.   fWavEnable = 'Y'
  19.   fQuiet   = 'N'
  20.   fGDay    = 'N'
  21.   iUGUPanelRow=1
  22.  
  23.   CALL rParseParms p1
  24.  
  25.   if fDebug = 'Y' then
  26.    do
  27.     trace ?r
  28.    end
  29.  
  30.   if fDispStax = 'Y' then
  31.    do
  32.     CALL rDispSyntax 0, 0
  33.    end
  34.  
  35.   if fDispHelp = 'Y' then
  36.    do
  37.     CALL rDispSyntax 1, 0
  38.    end
  39.  
  40.   /* Actual routine */
  41.   rc = rWinInit(p1)
  42.   if rc <> 0 then
  43.    do
  44.     exit rc
  45.    end
  46.  
  47.   do while 0 = rUGuessIt()
  48.   end /*do while 0 = rUGuessIt()*/
  49.  
  50.   rc = rWinTerm()
  51.  
  52.   exit 0
  53.  
  54. rUGuessIt:
  55.   akey = ''
  56.   do iUGUPanelRow = 1 to 10
  57.    rc = rUGuessItPanel(iUGUPanelRow)
  58.    select
  59.     when rc = 0 then
  60.      do
  61.       iterate                          /* U Missed it */
  62.      end
  63.     when rc = 4 then
  64.      do
  65.       return 0                         /* U Guessed it */
  66.      end
  67.     when rc = 8 then
  68.      do
  69.       return 8                         /* U Guessed it */
  70.      end
  71.     otherwise
  72.      do
  73.       return rc                        /* U Quit it */
  74.      end
  75.    end /* select */
  76.   end /* do iUGUPanelRow = 1 to 10 */
  77.   return 0;
  78.  
  79. rUGuessItPanel:
  80. parse arg iUGUPanelRow
  81.   sPnlNdx = RIGHT(iUGUPanelRow,4,'0')
  82.   akey = ''
  83.   do while akey <> ZENTER
  84.    do i = 1 to 4
  85.     iG.i = ''
  86.    end
  87.    iGuess = FORMAT(iUGUPanelRow,2)
  88.    akey = ZESC
  89.    do while akey = ZESC
  90.     akey = rxPDDisplay(bid,'UGIT'sPnlNdx)
  91.     if akey = Z_S_A then
  92.      do
  93.       if fWavEnable = 'N' then
  94.        do
  95.         fWavEnable = 'Y'
  96.        end
  97.       else
  98.        do
  99.         fWavEnable = 'N'
  100.        end
  101.       akey = ZESC
  102.       iterate      /* continue */
  103.      end
  104.    end /* do while akey = ZESC */
  105.    if akey = Z_U_A then
  106.     do
  107.      if fUnique = 'Y' then
  108.       do
  109.        fUnique = 'N'
  110.       end
  111.      else
  112.       do
  113.        fUnique = 'Y'
  114.       end
  115.      Call rWinReset
  116.      return 4                          /* Restart */
  117.     end
  118.    if akey = ZF1 then
  119.     do
  120.      svid = rxPDSaveScreen(bid)
  121.      Call rxPDDisplay bid, 'HELP001'
  122.      rc = rxPDRestoreScreen(bid,svid)
  123.      akey = ''
  124.      iterate      /* continue */
  125.     end
  126.    if akey = ZF3 then
  127.     do
  128.      return 8
  129.     end
  130.   end /*do while akey <> 'ESC' & akey <> 'F3'*/
  131.  
  132.   return rWinEnter(iUGUPanelRow)
  133.  
  134. rWinInit:
  135. parse arg p1
  136.  
  137.   mrc = rLoadFuncs('SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs')
  138.   if mrc <> 0 then
  139.    do
  140.     Call BEEP 882, 40
  141.     say 'UGUESSIT.CMD - Unable to initialize "SysLoadFuncs/RexxUtil"'
  142.     return mrc
  143.    end
  144.  
  145.   mrc = rLoadFuncs('rxPDLoadFuncs', 'HSSPD', 'rxPDLoadFuncs')
  146.   if mrc <> 0 then
  147.    do
  148.     Call BEEP 882, 40
  149.     say 'UGUESSIT.CMD - Unable to initialize "RXPD system"'
  150.     return mrc
  151.    end
  152.  
  153.   bid = rxPDInit('UGUESSIT',,,,,25,80)
  154.   if c2d(bid) = 0 then
  155.    do
  156.     Call BEEP 882, 40
  157.     say 'UGUESSIT.CMD - Unable to initialize "Panel Display SubSystem"'
  158.     return rc
  159.    end
  160.   fPDInit='Y'
  161.  
  162.   Call rxPDZVarDefine
  163.  
  164.   if fQuiet = 'Y' then
  165.    do
  166.     fWavEnable = 'N'
  167.    end
  168.   do i = 1 to 4
  169.    iG.i = ''
  170.    sScrlMsg.i = ''
  171.    iM.i = ''
  172.   end
  173.   do i = 1 to 2
  174.    iA.i = ''
  175.   end
  176.  
  177.   mrc = rmciRxInit()
  178.   if mrc = 0 then
  179.    do
  180.     mrc=rMciStrng('open waveaudio shareable alias wDev wait')
  181.     if mrc = 0 then
  182.      do
  183.        mrc=rMciStrng('capability wDev can play wait')
  184.        if mrc = 0 then
  185.         do
  186.          fWav=1
  187.          mrc = rMciStrng('close wDev wait')
  188.         end
  189.        else
  190.         do
  191.          mrc = rMciStrng('close wDev wait')
  192.         end
  193.      end
  194.    end
  195.   else
  196.    do
  197.     fWavEnable = 'N'
  198.    end
  199.   Call rxPDDisplay bid, 'UGITINIT'
  200.   CALL rWinReset
  201.   return 0
  202.  
  203. rWinEnter:
  204. parse arg iUGUPanelRow
  205.   do i = 1 to 4
  206.    kval.i = iG.i
  207.   end /* do i = 1 to 4 */
  208.   gotit = rWinTest(iUGUPanelRow,kval.1,kval.2,kval.3,kval.4)
  209.   parse var gotit hit_ctr almost_ctr
  210.   if hit_ctr = 4 then
  211.    do
  212.     sTellNum = kval.1||kval.2||kval.3||kval.4
  213.   /*svid = rxPDSaveScreen(bid)*/
  214.     akey = rxPDDisplay(bid,'UGITUWON')
  215.   /*rc = rxPDRestoreScreen(bid,svid)*/
  216.     if akey = ZENTER then
  217.      do
  218.       CALL rWinReset
  219.       return 4
  220.      end
  221.     else
  222.      do
  223.       return 8
  224.      end
  225.    end
  226.   if iUGUPanelRow < 10 then
  227.    do
  228.     return 0
  229.    end
  230.   else
  231.    do
  232.     sTellNum = iM.1||iM.2||iM.3||iM.4
  233.   /*svid = rxPDSaveScreen(bid)*/
  234.     akey = rxPDDisplay(bid,'UGITULOSE')
  235.   /*rc = rxPDRestoreScreen(bid,svid)*/
  236.     if akey = ZENTER then
  237.      do
  238.       CALL rWinReset
  239.       return 4
  240.      end
  241.     else
  242.      do
  243.       return 8
  244.      end
  245.    end
  246.   return 0
  247.  
  248. rWinTest:
  249. parse arg iUGUPanelRow, gval1, gval2, gval3, gval4
  250.   sPnlHitNdx = RIGHT(iUGUPanelRow,4,'0')
  251.   do i = 1 to 4; itest = iM.i; end;/*TEST*/
  252.   hit_ctr = 0
  253.   almost_ctr = 0
  254.   num_1_hit = 0
  255.   num_2_hit = 0
  256.   num_3_hit = 0
  257.   num_4_hit = 0
  258.   num_1_almost = 0
  259.   num_2_almost = 0
  260.   num_3_almost = 0
  261.   num_4_almost = 0
  262.   if gval1 = iM.1 then
  263.    do
  264.     hit_ctr = hit_ctr + 1
  265.     num_1_hit = 1
  266.    end
  267.   if gval2 = iM.2 then
  268.    do
  269.     hit_ctr = hit_ctr + 1
  270.     num_2_hit = 1
  271.    end
  272.   if gval3 = iM.3 then
  273.    do
  274.     hit_ctr = hit_ctr + 1
  275.     num_3_hit = 1
  276.    end
  277.   if gval4 = iM.4 then
  278.    do
  279.     hit_ctr = hit_ctr + 1
  280.     num_4_hit = 1
  281.    end
  282.  
  283.   if num_1_hit = 0 then
  284.    do
  285.     if gval1 = iM.2 & num_2_hit = 0 then
  286.      do
  287.       almost_ctr = almost_ctr + 1
  288.       num_2_almost = 1
  289.      end
  290.     else
  291.      do
  292.       if gval1 = iM.3 & num_3_hit = 0 then
  293.        do
  294.         almost_ctr = almost_ctr + 1
  295.         num_3_almost = 1
  296.        end
  297.       else
  298.        do
  299.         if gval1 = iM.4 & num_4_hit = 0 then
  300.          do
  301.           almost_ctr = almost_ctr + 1
  302.           num_4_almost = 1
  303.          end
  304.        end
  305.      end
  306.    end
  307.  
  308.   if num_2_hit = 0 then
  309.    do
  310.     if gval2 = iM.1 & num_1_hit = 0 then
  311.      do
  312.       almost_ctr = almost_ctr + 1
  313.       num_1_almost = 1
  314.      end
  315.     else
  316.      do
  317.       if gval2 = iM.3 & num_3_hit = 0 & num_3_almost = 0 then
  318.        do
  319.         almost_ctr = almost_ctr + 1
  320.         num_3_almost = 1
  321.        end
  322.       else
  323.        do
  324.         if gval2 = iM.4 & num_4_hit = 0 & num_4_almost = 0 then
  325.          do
  326.           almost_ctr = almost_ctr + 1
  327.           num_4_almost = 1
  328.          end
  329.        end
  330.      end
  331.    end
  332.  
  333.   if num_3_hit = 0 then
  334.    do
  335.     if gval3 = iM.1 & num_1_hit = 0 & num_1_almost = 0 then
  336.      do
  337.       almost_ctr = almost_ctr + 1
  338.       num_1_almost = 1
  339.      end
  340.     else
  341.      do
  342.       if gval3 = iM.2 & num_2_hit = 0 & num_2_almost = 0 then
  343.        do
  344.         almost_ctr = almost_ctr + 1
  345.         num_2_almost = 1
  346.        end
  347.       else
  348.        do
  349.         if gval3 = iM.4 & num_4_hit = 0 & num_4_almost = 0 then
  350.          do
  351.           almost_ctr = almost_ctr + 1
  352.           num_4_almost = 1
  353.          end
  354.        end
  355.      end
  356.    end
  357.  
  358.   if num_4_hit = 0 then
  359.    do
  360.     if gval4 = iM.1 & num_1_hit = 0 & num_1_almost = 0 then
  361.      do
  362.       almost_ctr = almost_ctr + 1
  363.       num_1_almost = 1
  364.      end
  365.     else
  366.      do
  367.       if gval4 = iM.2 & num_2_hit = 0 & num_2_almost = 0 then
  368.        do
  369.         almost_ctr = almost_ctr + 1
  370.         num_2_almost = 1
  371.        end
  372.       else
  373.        do
  374.         if gval4 = iM.3 & num_3_hit = 0 & num_3_almost = 0 then
  375.          do
  376.           almost_ctr = almost_ctr + 1
  377.           num_3_almost = 1
  378.          end
  379.        end
  380.      end
  381.    end
  382.  
  383.   iA.1 = hit_ctr
  384.   iA.2 = almost_ctr
  385.   Call rxPDDisplay bid, 'UGITHIT'||sPnlHitNdx
  386.   CALL rWinScroll "Guess # "iUGUPanelRow"; "hit_ctr" in correct position, "almost_ctr" in incorrect position;"
  387.  
  388.   if iUGUPanelRow = 5 & hit_ctr <> 4 then
  389.    do
  390.     mrc = rMciPlay('UGITHRRY')
  391.     CALL rWinScroll "Better hurry, you've only got 5 guesses left!"
  392.    end
  393.  
  394.   if iUGUPanelRow = 9 & hit_ctr <> 4 then
  395.    do
  396.     mrc = rMciPlay('UGITGWIN')
  397.     CALL rWinScroll "I'm gonna win! You've only got 1 guess left!"
  398.    end
  399.  
  400.   if iUGUPanelRow = 10 & hit_ctr <> 4 then
  401.    do
  402.     mrc = rMciPlay('UGITHAHA')
  403.    end
  404.  
  405.   if hit_ctr = 4 then
  406.    do
  407.     CALL rWinScroll "Congratulations! You've guessed it!"
  408.     CALL rWinScroll "  "||gval1||gval2||gval3||gval4" is correct!"
  409.     CALL rWinScroll "   (Pure luck if you ask me.) |:-("
  410.     mrc = rMciPlay('UGITLDOG', 'WAIT')
  411.    end
  412.   return hit_ctr almost_ctr
  413.  
  414. rWinScroll:
  415. parse arg sMsg
  416.   do i = 2 to 4
  417.    j = i - 1
  418.    sScrlMsg.j = sScrlMsg.i
  419.   end /* do i = 2 to 4 */
  420.   sScrlMsg.4 = sMsg
  421.   Call rxPDDisplay bid, 'UGITSCROLL'
  422.   return
  423.  
  424. rWinReset:
  425.   if fUnique = 'N' then
  426.    sWinTitle = CENTER('UGuessIt - (Not Necessarily Unique Digits)',80,' ')
  427.   else
  428.    sWinTitle = CENTER('UGuessIt - (Unique Digits)',80,' ')
  429.   iGuess = ' 1'
  430.   Call rxPDDisplay bid, 'UGITRESET'
  431.   if fUnique = 'N' then
  432.    do
  433.     cRandom = 'not necessarily unique'
  434.    end
  435.   else
  436.    do
  437.     cRandom = 'unique'
  438.    end
  439.   CALL rWinScroll "Ok, I'm thinking of a 4 digit number where each digit is "
  440.   CALL rWinScroll " "cRandom". Your mission is to guess the number"
  441.   CALL rWinScroll "  within ten tries otherwise I win."
  442.   CALL rWinScroll "I *LIKE* winning! I *HATE* quitters!"
  443.   if fUnique = 'N' then
  444.    do
  445.     secret = RANDOM(9999)
  446.     secret = RIGHT(secret,4,'0')
  447.     iM.1 = substr(secret,1,1)
  448.     iM.2 = substr(secret,2,1)
  449.     iM.3 = substr(secret,3,1)
  450.     iM.4 = substr(secret,4,1)
  451.    end
  452.   else
  453.    do
  454.     testit = 'N'
  455.     do while testit = 'N'
  456.      secret = RANDOM(9999)
  457.      secret = RIGHT(secret,4,'0')
  458.      iM.1 = substr(secret,1,1)
  459.      iM.2 = substr(secret,2,1)
  460.      iM.3 = substr(secret,3,1)
  461.      iM.4 = substr(secret,4,1)
  462.      if iM.1 <> iM.2 & iM.1 <> iM.3 & iM.1 <> iM.4 & iM.2 <> iM.3 & iM.2 <> iM.4 & iM.3 <> iM.4 then testit = 'Y'
  463.     end
  464.    end
  465.   if fGDay = 'N' then
  466.    do
  467.     mrc = rMciPlay('UGITGDAY')
  468.     fGDay = 'Y'
  469.    end
  470.   return
  471.  
  472. rWinTerm:
  473.   if fWav = 1 then
  474.    do
  475.     mrc = rMciPlay('UGITQUIT', 'WAIT')
  476.     fWav = 0
  477.    end
  478.  
  479.   rc=rxPDTerm(bid)
  480.  
  481.   return 0
  482.  
  483. rMciRxInit:
  484.   rxrc = RxFuncAdd('mciRxInit', 'MCIAPI', 'mciRxInit')
  485.   signal on syntax name xmciRxInit
  486.   mrc = mciRxInit()
  487.   return 0
  488.  
  489. xMciRxInit:
  490.   return 127
  491.  
  492. rMciPlay:
  493. parse arg pwave, asynchQ
  494.   if fWav = 1 & fWavEnable = 'Y' then
  495.    do
  496.     sPWaveFlSpec=SysSearchPath('DPATH',pwave'.wav')
  497.     rc = rMciStrng('play 'sPWaveFlSpec' wait')
  498.     if rc <> 0 then
  499.      do
  500.       pwave = '"'pwave'"'
  501.       sMCIErr = '"'sMCIErr'"'
  502.       Call rSiren 8, 3
  503.       if fPDInit = 'Y' then
  504.        do
  505.         svid = rxPDSaveScreen(bid)
  506.         akey = rxPDDisplay(bid,'UGITWAVERR')
  507.         rc = rxPDRestoreScreen(bid,svid)
  508.        end
  509.       else
  510.        do
  511.         say 'Unable to play ''.WAV'' file 'pwave
  512.         say 'MCI Error Message:'
  513.         say sMCIErr
  514.         '@pause'
  515.        end
  516.       fWavEnable = 'N'
  517.      end
  518.    end
  519.   return 0
  520.  
  521. rMciStrng:
  522. parse arg ctext
  523.    mrc = mciRxSendString(ctext, 'retstr', '0', '0')
  524.    if mrc <> 0 then
  525.     do
  526.      erc = mrc
  527.      sMCIErr = 'RC='erc';'
  528.      mrc = mciRxGetErrorString(erc, 'errstr')
  529.      sMCIErr = sMCIErr errstr';'
  530.      mrc = erc
  531.     end
  532.    return mrc
  533.  
  534. rLoadFuncs:
  535. parse arg sRtn, sDll
  536.   rxrc = RxFuncAdd(sRtn, sDll, sRtn)
  537.   signal on syntax name xLoadFuncs
  538.   interpret 'Call 'sRtn
  539.   return 0
  540.  
  541. xLoadFuncs:
  542.   return 127
  543.  
  544. HaltExit:
  545.   if fPDInit = 'Y' then
  546.    do
  547.     rc = rxPDTerm(bid)
  548.    end
  549.   Call BEEP 882, 40
  550.   Call BEEP 882, 40
  551.   say ''
  552.   say 'UGUESSIT processing halted by request;'
  553.   exit 0
  554.  
  555. ErrorExit:
  556.   Call BEEP 882, 40
  557.   Call BEEP 882, 40
  558.   say 'UGUESSIT processing failed due to unknown error;'
  559.   exit 24
  560.  
  561. FailureExit:
  562.   Call BEEP 882, 40
  563.   Call BEEP 882, 40
  564.   say 'UGUESSIT processing failed due to unknown failure;'
  565.   exit 32
  566.  
  567. SyntaxExit:
  568.   Call BEEP 882, 40
  569.   Call BEEP 882, 40
  570.   say 'UGUESSIT processing failed due to syntax error;'
  571.   exit 64
  572.  
  573. rParseParms:
  574. parse arg p1
  575.  
  576.   do Forever
  577.    w1 = word(p1,1)
  578.    parse var w1 with "/" f1 ":" v1
  579.    select
  580.     when (w1 = '') then
  581.      do
  582.       return 0
  583.      end
  584.     when 0 <> ABBREV('/SHHHHHHHH',TRANSLATE(w1),3) then
  585.      do
  586.       fQuiet='Y'
  587.       p1 = SUBWORD(p1,2)
  588.      end
  589.     when 0 <> ABBREV('/UNIQUE',TRANSLATE(w1),3) then
  590.      do
  591.       fUnique='Y'
  592.       p1 = SUBWORD(p1,2)
  593.      end
  594.     when TRANSLATE(w1) = '/DEBUG' then
  595.      do
  596.       fDebug='Y'
  597.       p1 = SUBWORD(p1,2)
  598.      end
  599.     when TRANSLATE(f1) = 'D' then
  600.      do
  601.       fDebug = TRANSLATE(v1)
  602.       p1 = SUBWORD(p1,2)
  603.      end
  604.     when TRANSLATE(f1) = '?' then
  605.      do
  606.       fDispStax='Y'
  607.       fDispHelp='N'
  608.       p1 = SUBWORD(p1,2)
  609.      end
  610.     when TRANSLATE(f1) = 'H' then
  611.      do
  612.       fDispStax='N'
  613.       fDispHelp='Y'
  614.       p1 = SUBWORD(p1,2)
  615.      end
  616.     otherwise
  617.      do
  618.       Call rSiren 8, 1
  619.       say 'UGUESSIT - Invalid parm specified; Parm "'w1'" unknown;'
  620.       CALL rDispSyntax 0 8
  621.      end
  622.    end
  623.   end
  624.  
  625.   return 0
  626.  
  627. rDispSyntax: Procedure
  628. parse upper arg iHelp iExit
  629.  
  630.   say ' Syntax  : UGUESSIT {<options>} '
  631.   say '           UGUESSIT {/?|/h}'
  632.   if iHelp > 0 then
  633.    do
  634.     CALL rDispHelp
  635.    end
  636.  
  637.   exit iExit
  638.  
  639. rDispHelp: Procedure
  640.  
  641.   say ' Options : /?         - Display command syntax.'
  642.   say '           /h         - Display this help info.'
  643.   say '           /shhh      - No sounds please.'
  644.   say '           /unique    - Guesses to use all unique digits.'
  645.   say ' Examples:'
  646.   say '    UGUESSIT /h'
  647.   say ' '
  648.   say '    UGUESSIT'
  649.  
  650.   return ''
  651.  
  652. /* rSiren: does the siren bit by running the scale based upon a       */
  653. /*    frequency specified by the caller.                              */
  654. rSiren: Procedure
  655.    Parse Arg freq, cycle
  656.    do j = 1 to cycle
  657.     call beep 524*freq,250 /* hold each note for a 1/4 second */
  658.     call beep 262*freq,250 /* hold each note for a 1/4 second */
  659.    end j
  660.    Return
  661.