home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a079 / 1.img / FMW.LZH / POPTRIS.PRG < prev    next >
Encoding:
Text File  |  1991-11-06  |  23.1 KB  |  1,344 lines

  1. *  ╥─┐──────┐  
  2. *  ╟─┘┌╥─┐o │  7/22/91
  3. *  ║╓╥┐║╥┐╥╓┐  
  4. *  ║║╟┘║║ ║╙╖  Copyright (c) 1991 Gerald F. Garcia, Jr.
  5. *  ╨╙╨ ╨╨ ╨└╜  
  6. *  └──v1.0──┘  All Rights Reserved
  7.  
  8. FUNCTION PopTris
  9.  
  10. parameters ;
  11.     nRow, nCol, nLvl, nHt
  12.  
  13. private                                              ;
  14.     cSavSetTalk,   cSavSetBlink,     cSavSetCursor,   ;
  15.     cSavSetEscape, nSavSetTypeahead, lSavSetCapsLock, ;
  16.     lSavSetNumLock
  17.  
  18.  
  19.  
  20.  
  21.  
  22. * SAVE AND SET ENVIRONMENT
  23.  
  24. if Set( "talk" ) = "ON"
  25.     set talk off
  26.     cSavSetTalk = "ON"
  27. else
  28.     cSavSetTalk = "OFF"
  29. endif
  30.  
  31. if ! ( "EGA" $ Sys( 2006 ) .or. "VGA" $ Sys( 2006 ) )
  32.     wait "Sorry, PopTris REQUIRES EGA/VGA" window
  33.     RETURN ( "" )
  34. endif
  35.  
  36. cSavSetBlink     = Set( "blink" )
  37. cSavSetCursor    = Set( "cursor" )
  38. cSavSetEscape    = Set( "escape" )
  39. nSavSetTypeahead = Set( "typeahead" )
  40. lSavSetCapsLock  = CapsLock()
  41. lSavSetNumLock   = NumLock()
  42.  
  43. set blink  off
  44. set cursor off
  45. set escape off
  46. set typeahead to 1
  47. = CapsLock( .t. )
  48. = NumLock( .t. )
  49.  
  50.  
  51. * CALIBRATE AND DEFINE WINDOWS
  52.  
  53. if Type( "nLvl" ) = "N"
  54.     nLvl = Iif( Between( nLvl, 0, 9 ), nLvl, 0 )
  55. else
  56.     nLvl = 0
  57. endif
  58.  
  59. if Type( "nHt" ) = "N"
  60.     nHt = Iif( Between( nHt, 0, 9 ), nHt, 0 )
  61. else
  62.     nHt = 0
  63. endif
  64.  
  65. nRow =                         ;
  66.     Iif( Type( "nRow" ) != "N", ;
  67.         ( SRows() - 22 ) / 2,    ;
  68.         Min( Abs( nRow ), SRows() - 22 ) )
  69.  
  70. nCol =                         ;
  71.     Iif( Type( "nCol" ) != "N", ;
  72.         ( SCols() - 32 ) / 2,    ;
  73.         Min( Abs( nCol ), SCols() - 32 ) )
  74.             
  75. define window wTetris                      ;
  76.     from nRow, nCol to nRow + 21, nCol + 31 ;
  77.     float shadow color n/w
  78.  
  79. define window wNoNext in window wTetris ;
  80.     from 07, 03 to 08, 06                ;
  81.     none color w/w
  82.  
  83. define window wNoStat in window wTetris ;
  84.     from 11, 01 to 19, 07                ;
  85.     none color w/w
  86.  
  87. define window wPause  in window wTetris ;
  88.     from 08, 11 to 11, 18 color r+/w
  89.     
  90. activate window wPause noshow
  91.  
  92. @ 00, 01 say "GAME"
  93. @ 01, 00 say "PAUSED"
  94.  
  95. activate window wTetris noshow
  96.  
  97. show window wNoNext
  98. show window wNoStat
  99.  
  100.  
  101. * DRAW PLAYFIELD
  102.  
  103. *                      1         2
  104. *            012345678901234567890123456789
  105. @ 00,00 say " Score    ░░░░░░░░░░  Level 0 " && 00
  106. @ 01,00 say "       0  ░░░░░░░░░░          " && 01
  107. @ 02,00 say "          ░░░░░░░░░░ ┌───────╖" && 02
  108. @ 03,00 say " Lines    ░░░░░░░░░░ │  OK   ║" && 03
  109. @ 04,00 say "       0  ░░░░░░░░░░ ╘═══════╝" && 04
  110. @ 05,00 say "          ░░░░░░░░░░ ┌───────╖" && 05
  111. @ 06,00 say " [ ] Next ░░░░░░░░░░ │Options║" && 06
  112. @ 07,00 say "          ░░░░░░░░░░ ╘═══════╝" && 07
  113. @ 08,00 say "          ░░░░░░░░░░ ┌───────╖" && 08
  114. @ 09,00 say "          ░░░░░░░░░░ │Restart║" && 09
  115. @ 10,00 say " [ ] Stat ░░░░░░░░░░ ╘═══════╝" && 10
  116. @ 11,00 say " ■        ░░░░░░░░░░    ┌─╖   " && 11
  117. @ 12,00 say " ■        ░░░░░░░░░░    │║   " && 12
  118. @ 13,00 say " ■        ░░░░░░░░░░    ╘═╝   " && 13
  119. @ 14,00 say " ■        ░░░░░░░░░░ ┌─╖┌─╖┌─╖" && 14
  120. @ 15,00 say " ■        ░░░░░░░░░░ │║│║│║" && 15
  121. @ 16,00 say " ■        ░░░░░░░░░░ ╘═╝╘═╝╘═╝" && 16
  122. @ 17,00 say " ■        ░░░░░░░░░░    ┌─╖   " && 17
  123. @ 18,00 say " ───────  ░░░░░░░░░░    │║   " && 18
  124. @ 19,00 say " Σ        ░░░░░░░░░░    ╘═╝   " && 19
  125. *            012345678901234567890123456789
  126. *                      1         2
  127.  
  128. @ 01, 02 fill to 01, 07 color w+/w
  129. @ 04, 02 fill to 04, 07 color bg+/w
  130. @ 00, 28 fill to 00, 28 color bg+/w
  131.  
  132. @ 03, 25 fill to 03, 25 color gr+/w
  133. @ 06, 22 fill to 06, 22 color gr+/w
  134. @ 09, 22 fill to 09, 22 color gr+/w
  135. @ 06, 05 fill to 06, 05 color gr+/w
  136. @ 10, 05 fill to 10, 05 color gr+/w
  137.  
  138. @ 11, 01 fill to 11, 01 color g/g*
  139. @ 12, 01 fill to 12, 01 color r+/g
  140. @ 13, 01 fill to 13, 01 color w+/bg
  141. @ 14, 01 fill to 14, 01 color r/gr*
  142. @ 15, 01 fill to 15, 01 color br/b
  143. @ 16, 01 fill to 16, 01 color n/r
  144. @ 17, 01 fill to 17, 01 color br/br*
  145.  
  146. @ 00, 10 fill to 19, 19 color n/n
  147.  
  148. activate window wTetris top
  149.  
  150. private                                                          ;
  151.     nScore,     nLines,     nStartLevel,  nLevel,     nHeight,    ;
  152.     nHiScore,   nHiLines,   nHiLevel,     nShapeTot,  nNextShape, ;
  153.     nNewShape,  lRestarted, lShowNext,    lShowStat,  nFactor,    ;
  154.     nKeyPress,  cKeyPress,  nOrientation, n1,         n,          ;
  155.     lReady2xit, lOk,        cDispNext,    cInitShape, cShowShape, ;
  156.     lObstructed
  157.  
  158. declare                                                  ;
  159.     anShapeCnt( 7 ),       anShapeRow( 4 ), anShapeCol( 4 ), ;
  160.     alPosFilled( 20, 10 ), anTmpRow( 4 ),   anTmpCol( 4 ),   ;
  161.     anDelayFactor( 10 ),   anOrientMax( 7 )
  162.  
  163. nScore       = 0
  164. nLines       = 0
  165. nStartLevel  = nLvl
  166. nLevel       = nStartLevel
  167. nHeight      = nHt
  168.  
  169. nHiScore     = 0
  170. nHiLines     = 0
  171. nHiLevel     = 0
  172.  
  173. anShapeRow   = 0
  174. anShapeCol   = 0
  175. anTmpRow     = 0
  176. anTmpCol     = 0
  177.  
  178. anShapeCnt   = 0
  179. nShapeTot    = 0
  180.  
  181. nNextShape   = 0
  182. nNewShape    = Int( Rand( -1 ) * 7 + 1 )
  183.  
  184. alPosFilled  = .f.
  185.  
  186. lRestarted   = .f.
  187.  
  188. lShowNext    = .f.
  189. lShowStat    = .f.
  190.  
  191. nFactor      = 0.06
  192.  
  193. nKeyPress    = 0    
  194. cKeyPress    = ""
  195.  
  196. nOrientation = 1
  197.  
  198. anOrientMax( 1 ) = 4
  199. anOrientMax( 2 ) = 4
  200. anOrientMax( 3 ) = 1
  201. anOrientMax( 4 ) = 2
  202. anOrientMax( 5 ) = 2
  203. anOrientMax( 6 ) = 2
  204. anOrientMax( 7 ) = 4
  205.  
  206. n1 = 10
  207.  
  208. for n = 1 to 10
  209.     anDelayFactor( n ) = n1 * nFactor
  210.     n1 = n1 - 1
  211. endfor
  212.  
  213. = _ShoLvl()
  214.  
  215. lReady2xit = .f.
  216.  
  217. do while !lReady2xit
  218.     if nHeight > 0
  219.         = _PlotHt()
  220.     endif
  221.  
  222.     lOk = .t.
  223.  
  224.     do while lOk
  225.         nNextShape = Int( Rand() * 7 + 1 )
  226.     
  227.         @ 07, 03 fill to 08, 06 color w/w
  228.  
  229.         cDispNext  = "_ShoNxt" + Str( nNextShape, 1 )
  230.         do ( cDispNext )
  231.     
  232.         cNewShape  = Str( nNewShape, 1 )
  233.         
  234.         anShapeCnt( nNewShape ) = anShapeCnt( nNewShape ) + 1
  235.         nShapeTot               = nShapeTot + 1
  236.     
  237.         @ 10 + nNewShape, 03 say anShapeCnt( nNewShape ) picture "99999"
  238.  
  239.         @ 19, 03 say nShapeTot picture "99999"
  240.         @ 01, 02 say nScore    picture "999999" color w+/w
  241.     
  242.         nRow = Iif( nNewShape = 3, 1, 0 )
  243.         nCol = Iif( nNewShape = 3, 5, 4 )
  244.     
  245.         nOrientation = 1
  246.         
  247.         cInitShape = "_IntSh" + cNewShape + "1"
  248.         do ( cInitShape )
  249.  
  250.         = _Tmp2Shp()
  251.     
  252.         cShowShape = "_ShoShp" + cNewShape
  253.         do ( cShowShape )
  254.     
  255.         if _OvrLapd()
  256.             = _EndGame()
  257.             = _Restart()
  258.         endif
  259.     
  260.         lObstructed = .f.
  261.             
  262.         = CapsLock( .t. )
  263.     
  264.         do while .not. lObstructed .and. lOk
  265.             nDelay = Seconds() + anDelayFactor( nLevel + 1 )
  266.     
  267.             do while Seconds() < nDelay
  268.                 nKeyPress = 0
  269.                 
  270.                 do while nKeyPress = 0 .and. Seconds() < nDelay
  271.                     nKeyPress = Inkey()
  272.                 enddo
  273.                 
  274.                 cKeyPress = LTrim( Str( nKeyPress, 2 ) )
  275.     
  276.                 if Seconds() < nDelay .and. ;
  277.                     ( "/" + cKeyPress + "/" ) $ ;
  278.                     "/4/5/13/19/24/27/32/50/52/53/54/56/75/76/78/79/80/82/83/"
  279.     
  280.                     do ( "_Key" + cKeyPress )
  281.                 endif    
  282.             enddo
  283.     
  284.             nRow = nRow + Iif( lRestarted, 0, 1 )
  285.             
  286.             do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  287.     
  288.             if _OvrLapd() .and. lOk
  289.                 lObstructed = .t.
  290.     
  291.                 for n = 1 to 4
  292.                     alPosFilled( anShapeRow( n ), anShapeCol( n ) ) = .t.
  293.                 endfor
  294.  
  295.                 nScore = nScore + nLevel
  296.             else
  297.                 = _DelShp()
  298.                 = _Tmp2Shp()
  299.                 
  300.                 do ( "_ShoShp" + cNewShape )
  301.             endif
  302.         enddo
  303.     
  304.         = _ChkLine()
  305.     
  306.         nNewShape  = nNextShape
  307.     enddo
  308.  
  309.     if lRestarted
  310.         = _ClrScrn()
  311.         lRestarted = .f.
  312.     endif
  313. enddo
  314.  
  315. if cSavSetBlink = "ON"
  316.     set blink on
  317. endif
  318.  
  319. if cSavSetCursor = "ON"
  320.     set cursor on
  321. endif
  322.  
  323. if cSavSetEscape = "ON"
  324.     set escape on
  325. endif
  326.  
  327. set typeahead to nSavSetTypeahead
  328.  
  329. = CapsLock( lSavSetCapsLock )
  330. = NumLock( lSavSetNumLock )
  331.  
  332. if cSavSetTalk = "ON"
  333.     set talk on
  334. endif
  335.  
  336. release window wTetris
  337.  
  338. RETURN ( "" )
  339.  
  340.  
  341.  
  342. FUNCTION _ChkLine
  343.  
  344. private ;
  345.     n1, n2, n3, n4, nLine
  346.  
  347. for n1 = 1 to 20
  348.     nLine = 0
  349.     
  350.     for n2 = 1 to 10
  351.         nLine = nLine + Iif( alPosFilled( n1, n2 ), 1, 0 )
  352.     endfor
  353.     
  354.     if nLine = 10
  355.         scroll 00, 10, n1 - 1, 19, -1
  356.         
  357.         @ 00, 10 fill to 00, 19 color n/n
  358.  
  359.         for n3 = n1 to 2 step -1
  360.             for n4 = 1 to 10
  361.                 alPosFilled( n3, n4 ) = alPosFilled( n3 - 1, n4 )
  362.             endfor
  363.         endfor
  364.         
  365.         for n4 = 1 to 10
  366.             alPosFilled( 1, n4 ) = .f.
  367.         endfor
  368.  
  369.         nLines = nLines + 1
  370.  
  371.         @ 04, 02 say nLines picture "999999" color bg+/w
  372.  
  373.         nScore = nScore + 10 + nLevel
  374.         
  375.         if ( nLevel < 9 ) .and. ( nLines >= ( ( nLevel + 2 ) * ( nLevel + 2 ) ) )
  376.             nLevel = nLevel + 1
  377.  
  378.             = _ShoLvl()
  379.         endif
  380.     endif
  381. endfor
  382.  
  383. RETURN ( "" )
  384.         
  385.     
  386.  
  387. FUNCTION _ClrScrn
  388.  
  389. @ 00, 10 fill to 19, 19 color n/n
  390.  
  391. RETURN ( "" )
  392.  
  393.  
  394.  
  395. FUNCTION _DelShp
  396.  
  397. private n
  398.  
  399. for n = 1 to 4
  400.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say " " color n/n
  401. endfor
  402.  
  403. RETURN ( "" )
  404.  
  405.  
  406.  
  407. FUNCTION _Drop
  408.  
  409. private lOk
  410.  
  411. lOk = .t.
  412.  
  413. do while lOk
  414.     nRow = nRow + 1
  415.     
  416.     do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  417.  
  418.     if _OvrLapd()
  419.         nRow = nRow - 1
  420.         lOk  = .f.
  421.     else
  422.         nScore = nScore + 0.5
  423.     endif
  424. enddo
  425.  
  426. do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  427.  
  428. = _DelShp()
  429. = _Tmp2Shp()
  430.             
  431. do ( "_ShoShp" + cNewShape )
  432.  
  433. RETURN ( "" )
  434.  
  435.  
  436.  
  437. FUNCTION _EndGame
  438.  
  439. private ;
  440.     n, nKeyPress, lOk
  441.  
  442. for n = 0 to 9
  443.     @ n, 10      say Replicate( "■", 10 ) color g/g*
  444.     @ 19 - n, 10 say Replicate( "■", 10 ) color g/g*
  445.     
  446.     nDelay = Seconds() + 0.06
  447.     
  448.     do while Seconds() < nDelay
  449.     enddo
  450. endfor
  451.  
  452. @ 09, 13 say "GAME" color w+/n
  453. @ 10, 13 say "OVER" color w+/n
  454.  
  455. lOk = .f.
  456.  
  457. nKeyPress = Inkey( 5 )
  458.  
  459. if nKeyPress = 0
  460.     lOk = .t.
  461.     
  462.     do while lOk
  463.         = _Title()
  464.         
  465.         nKeyPress = Inkey( 10 )
  466.         
  467.         if nKeyPress = 0
  468.             = _ShoHigh()
  469.  
  470.             nKeyPress = Inkey( 10 )
  471.             
  472.             lOk = ( nKeyPress = 0 )
  473.         else
  474.             lOk = .f.
  475.         endif
  476.     enddo
  477. endif
  478.  
  479. activate window wTetris
  480.  
  481. RETURN ( "" )
  482.  
  483.  
  484.  
  485. PROCEDURE _IntSh11
  486. private n
  487.  
  488. for n = 1 to 3
  489.     anTmpRow( n ) = nRow + 1
  490.     anTmpCol( n ) = nCol + n - 1
  491. endfor
  492.  
  493. anTmpRow( 4 ) = nRow + 2
  494. anTmpCol( 4 ) = nCol
  495. RETURN
  496.  
  497. PROCEDURE _IntSh12
  498. private n
  499.  
  500. for n = 1 to 3
  501.     anTmpRow( n ) = nRow + n - 1
  502.     anTmpCol( n ) = nCol + 1
  503. endfor
  504.  
  505. anTmpRow( 4 ) = nRow + 2
  506. anTmpCol( 4 ) = nCol + 2
  507. RETURN
  508.  
  509. PROCEDURE _IntSh13
  510. private n
  511.  
  512. for n = 1 to 3
  513.     anTmpRow( n ) = nRow + 1
  514.     anTmpCol( n ) = nCol + n - 1
  515. endfor
  516.  
  517. anTmpRow( 4 ) = nRow
  518. anTmpCol( 4 ) = nCol + 2
  519. RETURN
  520.  
  521. PROCEDURE _IntSh14
  522. private n
  523.  
  524. for n = 1 to 3
  525.     anTmpRow( n ) = nRow + n - 1
  526.     anTmpCol( n ) = nCol + 1
  527. endfor
  528.  
  529. anTmpRow( 4 ) = nRow
  530. anTmpCol( 4 ) = nCol
  531. RETURN
  532.  
  533. PROCEDURE _IntSh21
  534. private n
  535.  
  536. for n = 1 to 3
  537.     anTmpRow( n ) = nRow + 1
  538.     anTmpCol( n ) = nCol + n - 1
  539. endfor
  540.  
  541. anTmpRow( 4 ) = nRow + 2
  542. anTmpCol( 4 ) = nCol + 2
  543. RETURN
  544.  
  545. PROCEDURE _IntSh22
  546. private n
  547.  
  548. for n = 1 to 3
  549.     anTmpRow( n ) = nRow + n - 1
  550.     anTmpCol( n ) = nCol + 1
  551. endfor
  552.  
  553. anTmpRow( 4 ) = nRow
  554. anTmpCol( 4 ) = nCol + 2
  555. RETURN
  556.  
  557. PROCEDURE _IntSh23
  558. private n
  559.  
  560. for n = 1 to 3
  561.     anTmpRow( n ) = nRow + 1
  562.     anTmpCol( n ) = nCol + n - 1
  563. endfor
  564.  
  565. anTmpRow( 4 ) = nRow
  566. anTmpCol( 4 ) = nCol
  567. RETURN
  568.  
  569. PROCEDURE _IntSh24
  570. private n
  571.  
  572. for n = 1 to 3
  573.     anTmpRow( n ) = nRow + n - 1
  574.     anTmpCol( n ) = nCol + 1
  575. endfor
  576.  
  577. anTmpRow( 4 ) = nRow + 2
  578. anTmpCol( 4 ) = nCol
  579. RETURN
  580.  
  581. PROCEDURE _IntSh31
  582. private n
  583.  
  584. for n = 1 to 2
  585.     anTmpRow( n ) = nRow
  586.     anTmpCol( n ) = nCol + n - 1
  587. endfor
  588.  
  589. for n = 3 to 4
  590.     anTmpRow( n ) = nRow + 1
  591.     anTmpCol( n ) = nCol + n - 3
  592. endfor
  593. RETURN
  594.  
  595. PROCEDURE _IntSh41
  596. private n
  597.  
  598. for n = 1 to 4
  599.     anTmpRow( n ) = nRow + 1
  600.     anTmpCol( n ) = nCol + n - 1
  601. endfor
  602. RETURN
  603.  
  604. PROCEDURE _IntSh42
  605. private n
  606.  
  607. for n = 1 to 4
  608.     anTmpRow( n ) = nRow + n - 1
  609.     anTmpCol( n ) = nCol + 2
  610. endfor
  611. RETURN
  612.  
  613. PROCEDURE _IntSh51
  614. private n
  615.  
  616. for n = 1 to 2
  617.     anTmpRow( n ) = nRow + 1
  618.     anTmpCol( n ) = nCol + n
  619. endfor
  620.  
  621. for n = 3 to 4
  622.     anTmpRow( n ) = nRow + 2
  623.     anTmpCol( n ) = nCol + n - 3
  624. endfor
  625. RETURN
  626.  
  627. PROCEDURE _IntSh52
  628. private n
  629.  
  630. for n = 1 to 2
  631.     anTmpRow( n ) = nRow + n - 1
  632.     anTmpCol( n ) = nCol + 1
  633. endfor
  634.  
  635. for n = 3 to 4
  636.     anTmpRow( n ) = nRow + n - 2
  637.     anTmpCol( n ) = nCol + 2
  638. endfor
  639. RETURN
  640.  
  641. PROCEDURE _IntSh61
  642. private n
  643.  
  644. for n = 1 to 2
  645.     anTmpRow( n ) = nRow + 1
  646.     anTmpCol( n ) = nCol + n - 1
  647. endfor
  648.  
  649. for n = 3 to 4
  650.     anTmpRow( n ) = nRow + 2
  651.     anTmpCol( n ) = nCol + n - 2
  652. endfor
  653. RETURN
  654.  
  655. PROCEDURE _IntSh62
  656. private n
  657.  
  658. for n = 1 to 2
  659.     anTmpRow( n ) = nRow + n
  660.     anTmpCol( n ) = nCol
  661. endfor
  662.  
  663. for n = 3 to 4
  664.     anTmpRow( n ) = nRow + n - 3
  665.     anTmpCol( n ) = nCol + 1
  666. endfor
  667. RETURN
  668.  
  669. PROCEDURE _IntSh71
  670. private n
  671.  
  672. for n = 1 to 3
  673.     anTmpRow( n ) = nRow + 1
  674.     anTmpCol( n ) = nCol + n - 1
  675. endfor
  676.  
  677. anTmpRow( 4 ) = nRow + 2
  678. anTmpCol( 4 ) = nCol + 1
  679. RETURN
  680.  
  681. PROCEDURE _IntSh72
  682. private n
  683.  
  684. for n = 1 to 3
  685.     anTmpRow( n ) = nRow + n - 1
  686.     anTmpCol( n ) = nCol + 1
  687. endfor
  688.  
  689. anTmpRow( 4 ) = nRow + 1
  690. anTmpCol( 4 ) = nCol + 2
  691. RETURN
  692.  
  693. PROCEDURE _IntSh73
  694. private n
  695.  
  696. for n = 1 to 3
  697.     anTmpRow( n ) = nRow + 1
  698.     anTmpCol( n ) = nCol + n - 1
  699. endfor
  700.  
  701. anTmpRow( 4 ) = nRow
  702. anTmpCol( 4 ) = nCol + 1
  703. RETURN
  704.  
  705. PROCEDURE _IntSh74
  706. private n
  707.  
  708. for n = 1 to 3
  709.     anTmpRow( n ) = nRow + n - 1
  710.     anTmpCol( n ) = nCol + 1
  711. endfor
  712.  
  713. anTmpRow( 4 ) = nRow + 1
  714. anTmpCol( 4 ) = nCol
  715. RETURN
  716.  
  717.  
  718.  
  719. PROCEDURE _Key4
  720. = _Right()
  721. RETURN
  722.  
  723. PROCEDURE _Key5
  724. = _Up()
  725. RETURN
  726.  
  727. PROCEDURE _Key13
  728. = _Drop()
  729. RETURN
  730.  
  731. PROCEDURE _Key19
  732. = _Left()
  733. RETURN
  734.  
  735. PROCEDURE _Key24
  736. = _Drop()
  737. RETURN
  738.  
  739. PROCEDURE _Key27
  740. lOk        = .f.
  741. lReady2xit = .t.
  742. RETURN
  743.  
  744. PROCEDURE _Key32
  745. = _Drop()
  746. RETURN
  747.  
  748. PROCEDURE _Key50
  749. = _Drop()
  750. RETURN
  751.  
  752. PROCEDURE _Key52
  753. = _Left()
  754. RETURN
  755.  
  756. PROCEDURE _Key53
  757. = _Rotate()
  758. RETURN
  759.  
  760. PROCEDURE _Key54
  761. = _Right()
  762. RETURN
  763.  
  764. PROCEDURE _Key56
  765. = _Up()
  766. RETURN
  767.  
  768. PROCEDURE _Key76
  769. = _Rotate()
  770. RETURN
  771.  
  772. PROCEDURE _Key78
  773. = _TglNext()
  774. RETURN
  775.  
  776. PROCEDURE _Key75
  777. lOk        = .f.
  778. lReady2xit = .t.
  779. RETURN
  780.  
  781. PROCEDURE _Key79
  782. = _Option()
  783. = _Restart()
  784. RETURN
  785.  
  786. PROCEDURE _Key80
  787. = _Pause()
  788. RETURN
  789.  
  790. PROCEDURE _Key82
  791. = _Restart()
  792. RETURN
  793.  
  794. PROCEDURE _Key83
  795. = _TglStat()
  796. RETURN
  797.  
  798.  
  799.  
  800. FUNCTION _Left
  801.  
  802. nCol = nCol - 1
  803.  
  804. do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  805.  
  806. if _OvrLapd()
  807.     nCol = nCol + 1
  808. else
  809.     = _DelShp()
  810.     = _Tmp2Shp()
  811.     
  812.     do ( "_ShoShp" + cNewShape )
  813. endif
  814.  
  815. RETURN ( "" )
  816.  
  817.     
  818.  
  819. FUNCTION _Option
  820.  
  821. private ;
  822.     nPos, nRow, nCol, n, lOk, nKeyPress
  823.  
  824. *             1
  825. *             0123456789
  826. @ 00, 10 say "Level:    " color w+/n
  827. @ 01, 10 say "┌─┬─┬─┬─┬─" color w/n
  828. @ 02, 10 say "│0│1│2│3│4" color w/n
  829. @ 03, 10 say "├─┼─┼─┼─┼─" color w/n
  830. @ 04, 10 say "│5│6│7│8│9" color w/n
  831. @ 05, 10 say "└─┴─┴─┴─┴─" color w/n
  832. @ 06, 10 say "          " color w/n
  833. @ 07, 10 say "Height:   " color w+/n
  834. @ 08, 10 say "┌─┬─┬─┬─┬─" color w/n
  835. @ 09, 10 say "│0│1│2│3│4" color w/n
  836. @ 10, 10 say "├─┼─┼─┼─┼─" color w/n
  837. @ 11, 10 say "│5│6│7│8│9" color w/n
  838. @ 12, 10 say "└─┴─┴─┴─┴─" color w/n
  839. @ 13, 10 say "          " color w/n
  840. @ 14, 10 say "         " color w+/n
  841. @ 15, 10 say " Select" color w+/n
  842. @ 16, 10 say "         " color w+/n
  843. @ 17, 10 say "          " color w/n
  844. @ 18, 10 say "─┘ Choose" color w+/n
  845. @ 19, 10 say "          " color w/n
  846.  
  847. nPos = nStartLevel
  848.  
  849. for n = 1 to 2
  850.     lOk = .f.
  851.     
  852.     do while !lOk
  853.         nRow = Iif( n = 1, Iif( nPos > 4, 4, 2 ), Iif( nPos > 4, 11, 9 ) )
  854.         nCol = ( Iif( nPos > 4, ( nPos - 5 ), nPos ) + 1 ) * 2 + 9
  855.     
  856.         @ nRow, nCol fill to nRow, nCol color bg/w*
  857.     
  858.         nKeyPress = Inkey( 0 )
  859.         
  860.         do case
  861.         case nKeyPress =  5 .or. nKeyPress = 56
  862.             nPos = Iif( nPos > 4, nPos - 5, nPos + 5 )
  863.         case nKeyPress = 24 .or. nKeyPress = 50
  864.             nPos = Iif( nPos > 4, nPos - 5, nPos + 5 )
  865.         case nKeyPress = 19 .or. nKeyPress = 52
  866.             nPos = Iif( nPos = 0, 9, nPos - 1 )
  867.         case nKeyPress =  4 .or. nKeyPress = 54
  868.             nPos = Iif( nPos = 9, 0, nPos + 1 )
  869.         case nKeyPress = 13 .or. nKeyPress = 53
  870.             lOk = .t.
  871.         endcase
  872.  
  873.         if !lOk
  874.             @ nRow, nCol fill to nRow, nCol color w/n
  875.         endif
  876.     enddo
  877.  
  878.     if n = 1
  879.         store nPos to nLevel, nStartLevel
  880.     else
  881.         nHeight = nPos
  882.     endif
  883.     
  884.     nPos = nHeight
  885. endfor
  886.  
  887. @ 00, 28 say nLevel picture "9" color bg+/w
  888.  
  889. RETURN ( "" )
  890.  
  891.  
  892.  
  893. FUNCTION _OvrLapd
  894.  
  895. private ;
  896.     lOverLapped, n
  897.  
  898. lOverLapped = .f.
  899.  
  900. for n = 1 to 4
  901.     if Between( anTmpRow( n ), 1, 20 ) .and. ;
  902.         Between( anTmpCol( n ), 1, 10 )
  903.  
  904.         if alPosFilled( anTmpRow( n ), anTmpCol( n ) )
  905.             lOverLapped = .t.
  906.             exit
  907.         endif
  908.     else
  909.         lOverLapped = .t.
  910.         exit
  911.     endif
  912. endfor
  913.  
  914. RETURN ( lOverLapped )
  915.  
  916.  
  917.  
  918. FUNCTION _Pause
  919.  
  920. show window wPause
  921.  
  922. = Inkey( 0 )
  923.  
  924. hide window wPause
  925.  
  926. RETURN ( "" )
  927.  
  928.  
  929.  
  930. FUNCTION _PlotHt
  931.  
  932. private ;
  933.     n, nCount, nTmp, nColor
  934.     
  935. store 0 to ;
  936.     n, nCount, nTmp, nColor
  937.  
  938. for n = 20 to ( 21 - nHeight ) step -1
  939.     nCount = 0
  940.     
  941.     do while nCount < 4
  942.         nTmp = Int( Rand() * 10 + 1 )
  943.             
  944.         if !alPosFilled( n, nTmp )
  945.             alPosFilled( n, nTmp ) = .t.
  946.             nCount = nCount + 1
  947.             
  948.             nColor = Int( Rand() * 7 + 1 )
  949.             
  950.             do case
  951.             case nColor = 1
  952.                 @ n - 1, nTmp + 9 say "■" color g/g*
  953.             case nColor = 2
  954.                 @ n - 1, nTmp + 9 say "■" color r+/g
  955.             case nColor = 3
  956.                 @ n - 1, nTmp + 9 say "■" color w+/bg
  957.             case nColor = 4
  958.                 @ n - 1, nTmp + 9 say "■" color r/gr*
  959.             case nColor = 5
  960.                 @ n - 1, nTmp + 9 say "■" color br/b
  961.             case nColor = 6
  962.                 @ n - 1, nTmp + 9 say "■" color n/r
  963.             case nColor = 7
  964.                 @ n - 1, nTmp + 9 say "■" color br/br*
  965.             endcase
  966.         endif
  967.     enddo
  968. endfor
  969.  
  970. RETURN ( "" )
  971.  
  972.  
  973.  
  974. FUNCTION _Restart
  975.  
  976. lOk         = .f.
  977. alPosFilled = .f.
  978. lRestarted  = .t.
  979.  
  980. if nScore > nHiScore
  981.     nHiScore = nScore
  982.     nHiLines = nLines
  983.     nHiLevel = nLevel
  984. endif
  985.  
  986. nScore    = 0
  987. nLines    = 0
  988. nLevel    = nStartLevel
  989. nNewShape = Int( Rand( -1 ) * 7 + 1 )
  990. nNewShape = Int( Rand( -1 ) * 7 + 1 )
  991.  
  992. store 0 to anShapeCnt, nShapeTot
  993.  
  994. = _ShoLvl()
  995.  
  996. @ 11, 02 fill to 17, 07 color w/w
  997. @ 19, 02 fill to 19, 07 color w/w
  998.  
  999. @ 02, 02 say nHiScore picture "999999" color n+/w
  1000. @ 05, 02 say nHiLines picture "999999" color n+/w
  1001. @ 01, 28 say nHiLevel picture "9"      color n+/w
  1002. @ 04, 02 say nLines   picture "999999" color bg+/w
  1003.  
  1004. RETURN ( "" )
  1005.  
  1006.  
  1007.  
  1008. FUNCTION _Right
  1009.  
  1010. nCol = nCol + 1
  1011.  
  1012. do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  1013.  
  1014. if _OvrLapd()
  1015.     nCol = nCol - 1
  1016. else
  1017.     = _DelShp()
  1018.     = _Tmp2Shp()
  1019.     
  1020.     do ( "_ShoShp" + cNewShape )
  1021. endif
  1022.  
  1023. RETURN ( "" )
  1024.  
  1025.  
  1026.  
  1027. FUNCTION _Rotate
  1028.  
  1029. nOrientation = ;
  1030.     Iif( nOrientation = anOrientMax( nNewShape ), ;
  1031.         1, ;
  1032.         nOrientation + 1 )
  1033.                             
  1034. do ( "_IntSh" + cNewShape + Str( nOrientation, 1 ) )
  1035.  
  1036. if _OvrLapd()
  1037.     nOrientation = ;
  1038.         Iif( nOrientation = 1, ;
  1039.             anOrientMax( nNewShape ), ;
  1040.             nOrientation - 1 )
  1041. else
  1042.     = _DelShp()
  1043.     = _Tmp2Shp()
  1044.     
  1045.     do ( "_ShoShp" + cNewShape )
  1046. endif
  1047.  
  1048. RETURN ( "" )
  1049.  
  1050.  
  1051.  
  1052. FUNCTION _ShoHigh
  1053.  
  1054. activate window wTetris
  1055.  
  1056. if nScore > nHiScore
  1057.     nHiScore = nScore
  1058.     nHiLines = nLines
  1059.     nHiLevel = nLevel
  1060. endif
  1061.  
  1062. @ 00, 10 say "          " color n/bg
  1063. @ 01, 10 say "          " color n/bg
  1064. @ 02, 10 say "          " color n/bg
  1065. @ 03, 10 say "          " color n/bg
  1066. @ 04, 10 say "High Score" color n/bg
  1067. @ 05, 10 say nHiScore picture "    999999" color w+/bg
  1068. @ 06, 10 say "          " color n/bg
  1069. @ 07, 10 say "          " color n/bg
  1070. @ 08, 10 say "          " color n/bg
  1071. @ 09, 10 say "Lines     " color n/bg
  1072. @ 10, 10 say nHiLines picture "    999999" color w+/bg
  1073. @ 11, 10 say "          " color n/bg
  1074. @ 12, 10 say "          " color n/bg
  1075. @ 13, 10 say "          " color n/bg
  1076. @ 14, 10 say "Level     " color n/bg
  1077. @ 15, 10 say nHiLevel picture "         9" color w+/bg
  1078. @ 16, 10 say "          " color n/bg
  1079. @ 17, 10 say "          " color n/bg
  1080. @ 18, 10 say "          " color n/bg
  1081. @ 19, 10 say "          " color n/bg
  1082.  
  1083. = Inkey( 2 )
  1084.  
  1085. = _Twinkle( 05, 11 )
  1086. = _Twinkle( 10, 11 )
  1087. = _Twinkle( 15, 11 )
  1088.  
  1089. RETURN ( "" )
  1090.  
  1091.  
  1092.  
  1093. FUNCTION _ShoLvl
  1094.  
  1095. @ 00, 28 say nLevel picture "9" color bg+/w
  1096.  
  1097. RETURN ( "" )
  1098.  
  1099.  
  1100.  
  1101. PROCEDURE _ShoNxt1
  1102. @ 7, 3 say "■■■"  color g/g*
  1103. @ 8, 3 say "■"    color g/g*
  1104. RETURN
  1105.  
  1106. PROCEDURE _ShoNxt2
  1107. @ 7, 3 say "■■■"  color r+/g
  1108. @ 8, 5 say   "■"  color r+/g
  1109. RETURN
  1110.  
  1111. PROCEDURE _ShoNxt3
  1112. @ 7, 3 say "■■"   color w+/bg
  1113. @ 8, 3 say "■■"   color w+/bg
  1114. RETURN
  1115.  
  1116. PROCEDURE _ShoNxt4
  1117. @ 8, 3 say "■■■■" color r/gr*
  1118. RETURN
  1119.  
  1120. PROCEDURE _ShoNxt5
  1121. @ 7, 4 say  "■■"  color br/b
  1122. @ 8, 3 say "■■"   color br/b
  1123. RETURN
  1124.  
  1125. PROCEDURE _ShoNxt6
  1126. @ 7, 3 say "■■"   color n/r
  1127. @ 8, 4 say  "■■"  color n/r
  1128. RETURN
  1129.  
  1130. PROCEDURE _ShoNxt7
  1131. @ 7, 3 say "■■■"  color br/br*
  1132. @ 8, 4 say  "■"   color br/br*
  1133. RETURN
  1134.  
  1135.  
  1136.  
  1137. PROCEDURE _ShoShp1
  1138. private n
  1139.  
  1140. for n = 1 to 4
  1141.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color g/g*
  1142. endfor
  1143. RETURN
  1144.  
  1145. PROCEDURE _ShoShp2
  1146. private n
  1147.  
  1148. for n = 1 to 4
  1149.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color r+/g
  1150. endfor
  1151. RETURN
  1152.  
  1153. PROCEDURE _ShoShp3
  1154. private n
  1155.  
  1156. for n = 1 to 4
  1157.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color w+/bg
  1158. endfor
  1159. RETURN
  1160.  
  1161. PROCEDURE _ShoShp4
  1162. private n
  1163.  
  1164. for n = 1 to 4
  1165.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color r/gr*
  1166. endfor
  1167. RETURN
  1168.  
  1169. PROCEDURE _ShoShp5
  1170. private n
  1171.  
  1172. for n = 1 to 4
  1173.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color br/b
  1174. endfor
  1175. RETURN
  1176.  
  1177. PROCEDURE _ShoShp6
  1178. private n
  1179.  
  1180. for n = 1 to 4
  1181.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color n/r
  1182. endfor
  1183. RETURN
  1184.  
  1185. PROCEDURE _ShoShp7
  1186. private n
  1187.  
  1188. for n = 1 to 4
  1189.     @ anShapeRow( n ) - 1, anShapeCol( n ) + 9 say "■" color br/br*
  1190. endfor
  1191. RETURN
  1192.  
  1193.  
  1194.  
  1195. FUNCTION _TglNext
  1196.  
  1197. lShowNext = !lShowNext
  1198.  
  1199. if lShowNext
  1200.     hide window wNoNext
  1201.     @ 6, 2 say "X"
  1202. else
  1203.     show window wNoNext
  1204.     @ 6, 2 say " "
  1205. endif
  1206.  
  1207. RETURN ( "" )
  1208.  
  1209.  
  1210.  
  1211. FUNCTION _TglStat
  1212.  
  1213. lShowStat = !lShowStat
  1214.  
  1215. if lShowStat
  1216.     hide window wNoStat
  1217.     @ 10, 02 say "X"
  1218. else
  1219.     show window wNoStat
  1220.     @ 10, 02 say " "
  1221. endif
  1222.  
  1223. RETURN ( "" )
  1224.  
  1225.  
  1226.  
  1227. FUNCTION _Title
  1228.  
  1229. private ;
  1230.     n, nDelay
  1231.  
  1232. activate window wTetris
  1233.  
  1234. declare acTitle( 20 )
  1235.  
  1236. acTitle( 01 ) = "          "
  1237. acTitle( 02 ) = "╥─┐──────┐"
  1238. acTitle( 03 ) = "╟─┘┌╥─┐o │"
  1239. acTitle( 04 ) = "║╓╥┐║╥┐╥╓┐"
  1240. acTitle( 05 ) = "║║╟┘║║ ║╙╖"
  1241. acTitle( 06 ) = "╨╙╨ ╨╨ ╨└╜"
  1242. acTitle( 07 ) = "└──v1.0──┘"
  1243. acTitle( 08 ) = "          "
  1244. acTitle( 09 ) = "    by    "
  1245. acTitle( 10 ) = "          "
  1246. acTitle( 11 ) = "  Gerald  "
  1247. acTitle( 12 ) = "  Garcia, "
  1248. acTitle( 13 ) = "    Jr.   "
  1249. acTitle( 14 ) = "          "
  1250. acTitle( 15 ) = "          "
  1251. acTitle( 16 ) = " (C) 1991 "
  1252. acTitle( 17 ) = "          "
  1253. acTitle( 18 ) = "All Rights"
  1254. acTitle( 19 ) = " Reserved "
  1255. acTitle( 20 ) = "          "
  1256.   
  1257. for n = 10 to 1 step -1
  1258.     do case
  1259.     case n = 7
  1260.         @ n - 1, 10 say acTitle( n )  color w/n
  1261.     case Between( n, 4, 6 )
  1262.         @ n - 1, 10 say acTitle( n )  color bg+/n
  1263.     case n = 3
  1264.         @ n - 1, 10 say Left( acTitle( n ), 9 ) color bg+/n
  1265.         @ n - 1, 19 say Right( acTitle( n ), 1 ) color w/n
  1266.     case n = 2
  1267.         @ n - 1, 10 say Left( acTitle( n ), 3 ) color bg+/n
  1268.         @ n - 1, 13 say Right( acTitle( n ), 7 ) color w/n
  1269.     otherwise
  1270.         @ n - 1, 10 say acTitle( n )  color w+/n
  1271.     endcase
  1272.  
  1273.     do case
  1274.     case Between( 21 - n, 16, 19 )
  1275.         @ 20 - n, 10 say acTitle( 21 - n ) color w/n
  1276.     otherwise
  1277.         @ 20 - n, 10 say acTitle( 21 - n ) color w+/n
  1278.     endcase
  1279.  
  1280.     nDelay = Seconds() + 0.06
  1281.     
  1282.     do while Seconds() < nDelay
  1283.     enddo
  1284. endfor
  1285.  
  1286. = Inkey( 2 )
  1287.  
  1288. = _Twinkle( 02, 17 )
  1289.  
  1290. RETURN ( "" )
  1291.  
  1292.  
  1293.  
  1294. FUNCTION _Tmp2Shp
  1295.  
  1296. private n
  1297.  
  1298. for n = 1 to 4
  1299.     anShapeRow( n ) = anTmpRow( n )
  1300.     anShapeCol( n ) = anTmpCol( n )
  1301. endfor
  1302.  
  1303. RETURN ( "" )
  1304.  
  1305.  
  1306.  
  1307. FUNCTION _Twinkle
  1308.  
  1309. parameters ;
  1310.     nRow, nCol
  1311.     
  1312. private ;
  1313.     cTwinkle, n
  1314.  
  1315. cTwinkle = "·∙"
  1316.  
  1317. define window wTwinkle in window wTetris ;
  1318.     from nRow, nCol to nRow, nCol none    ;
  1319.     color w+/n
  1320.     
  1321. activate window wTwinkle
  1322.  
  1323. for n = 1 to Len( cTwinkle )
  1324.     @ 00, 00 say SubStr( cTwinkle, n, 1 )
  1325.         
  1326.     nDelay = Seconds() + 0.075
  1327.     
  1328.     do while Seconds() < nDelay
  1329.     enddo
  1330. endfor
  1331.  
  1332. deactivate window wTwinkle
  1333.  
  1334. RETURN ( "" )
  1335.  
  1336.  
  1337.  
  1338. FUNCTION _Up
  1339.  
  1340. nLevel = nLevel + Iif( nLevel < 9, 1, 0 )
  1341.  
  1342. @ 00, 28 say nLevel picture "9" color bg+/w
  1343.  
  1344. RETURN ( "" )