home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_shufl.prg < prev    next >
Text File  |  1993-10-14  |  4KB  |  155 lines

  1. /*
  2.  File......: GT_SHUFL.prg
  3.  Author....: Phillip Hamlyn
  4.  BBS.......: The Dark Knight Returns
  5.  Net/Node..: 050/069
  6.  User Name.: Phillip Hamlyn
  7.  Date......: 03/03/93
  8.  Revision..: 1.0
  9.  
  10.  This is an original work by Phillip Hamlyn and is placed in the
  11.  public domain.
  12.  
  13.  Modification history:
  14.  ---------------------
  15.  
  16.  Rev 1.0 03/03/93
  17.  Initial revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_SHUFL()
  23.  *  $CATEGORY$
  24.  *      Screen Saver
  25.  *  $ONELINER$
  26.  *      Shuffles screen in blocks of four characters
  27.  *  $SYNTAX$
  28.  *      GT_Shufl(<nSeconds>) -> NIL
  29.  *  $ARGUMENTS$
  30.  *      <nSeconds> This is the amount of seconds to pause between 'shuffles'
  31.  *                 Defaults to 0 seconds
  32.  *  $RETURNS$
  33.  *      NIL
  34.  *  $DESCRIPTION$
  35.  *      Screen saver for any Clipper application. This screen saver shuffles
  36.  *      blocks of 4 characters around the screen, it goes quite fast so a
  37.  *      parameter is included to slow the thing down a bit.
  38.  *  $EXAMPLES$
  39.  *      GT_Shufl(0.2) -> NIL
  40.  *  $SEEALSO$
  41.  *
  42.  *  $INCLUDE$
  43.  *
  44.  *  $END$
  45.  */
  46.  
  47. #include "gt_lib.ch"
  48.  
  49. * * * * * * * * *
  50. FUNCTION GT_Shufl (nSeconds)
  51. * * * * * * * * *
  52. #define NORTH 1
  53. #define SOUTH 2
  54. #define EAST 3
  55. #define WEST 4
  56.  
  57. local nDirection := NORTH, bInterrupt, nTimeout
  58. local nRand := 0, f := 0
  59. // possible directions...
  60. local nNewDirs := { {SOUTH,EAST,WEST} ,;
  61.                     {NORTH,WEST,EAST} ,;
  62.                     {WEST ,SOUTH,NORTH},;
  63.                     {NORTH,EAST,SOUTH} }
  64.  
  65. local nX := 0 , nY := 0
  66. local nX1, nY1
  67. local cCharAttrib
  68. local cSwapChar
  69. local cOldScreen
  70. default nSeconds to 0
  71.  
  72. // m_csroff() // Turn off your mouse here
  73.  
  74. bInterrupt := GT_Interrupt()
  75.  
  76. cOldScreen := savescreen(0,0,maxrow(),maxcol())
  77.  
  78. do while TRUE // LOOP until interrupt is given.
  79.    nTimeOut := seconds()
  80.  
  81.    // Now check the keyboard etc.
  82.    if eval(bInterrupt)
  83.       exit
  84.    endif
  85.  
  86.    // Does the worm change direction ?
  87.    nRand := val(right(str(seconds(),8,2),1))
  88.    // Force this if the shuffle is going off the screen
  89.  
  90.    do while TRUE // till we get a valid direction ...
  91.  
  92.       do case
  93.          case nDirection == NORTH .and. nX == 0
  94.             nRand := 10 // impossible to get normaly !
  95.          case nDirection == SOUTH .and. nX >= maxrow() -6
  96.             nRand := 10 // impossible to get normaly !
  97.          case nDirection == EAST .and.  nY == 0
  98.             nRand := 10 // impossible to get normaly !
  99.          case nDirection == WEST .and.  nY >= maxCOL() -6
  100.             nRand := 10 // impossible to get normaly !
  101.       endcase
  102.  
  103.       if nRand > 7
  104.          nRand := val(right(str(seconds(),8,2),1))
  105.  
  106.          // we need to change direction.
  107.          // Make Rand itself /3 so we get a 1,2,3 number
  108.          nRand := round(nRand / 3,0)
  109.          nRand := max(nRand,1)
  110.          nRand := min(3,nRand)
  111.          // Ok should be itself / 3 and either 1,2,3
  112.          // probably not totaly random but who cares ?
  113.          nDirection := nNewDirs[nDirection][nRand]
  114.       else
  115.          exit // found a valid direction
  116.       endif
  117.  
  118.    enddo // till we get a valid direction
  119.  
  120.    // Now weve sorted out whether to change direction, we can shuffle the
  121.    // screen elements a bit.
  122.  
  123.    // Move the point a bit
  124.    nY1 := nY
  125.    nX1 := nX
  126.  
  127.    do case
  128.       case nDirection == NORTH
  129.          nX1 := nX -3
  130.       case nDirection == SOUTH
  131.          nX1 := nX + 3
  132.       case nDirection == EAST
  133.          nY1 := nY -3
  134.       case nDirection == WEST
  135.          nY1 := nY + 3
  136.    endcase
  137.  
  138.    cCharAttrib := savescreen(nX ,nY ,nX+2,nY+2)
  139.    cSwapChar := savescreen(nX1,nY1, nX1+2,nY1+2)
  140.  
  141.    restscreen(nX,nY,nX+2,nY+2,cSwapChar)
  142.    restscreen(nX1,nY1,nX1+2,nY1+2,cCharAttrib)
  143.    nX := nX1
  144.    nY := nY1
  145.  
  146.    // now pause for a moment to let the user see the effects
  147.    do while Seconds() - nTimeOut < nSeconds ; enddo
  148.  
  149. enddo
  150.  
  151. restscreen(0,0,maxrow(),maxcol(),cOldScreen)
  152. // m_csron() // Turn on your mouse cursor
  153.  
  154. RETURN NIL
  155.