home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / screen / snake.prg < prev    next >
Text File  |  1992-04-01  |  3KB  |  124 lines

  1. // "Snake" - A screen Saver for Clipper V5.
  2. //
  3. // This is approximetely the same snake that we can see on a Netware 386
  4. // console file server, I think for such kind of network, users are used
  5. // to see the "Snake" on the file server, so it's a good idea to get the
  6. // same thing on each user screen.
  7. // You've only to modify getsys for calling snake after x seconds and
  8. // to modify also prompt and menu design system (I'll give you all that
  9. // stuff if you need it...)
  10. //
  11. //      Patrick Imbault
  12. //      6 Rue de l'Ecluse
  13. //      77000 MELUN
  14. //      FRANCE
  15. //      CIS:100012,1450
  16. //
  17. //  call SNAKE() to use it, it returns always .T.
  18. //  compile CLIPPER snake /N /W
  19. //
  20. //
  21.  
  22. #Define SPEED   .1
  23. #Define LMAX   15
  24. #Define FRAC(x)  (x-INT(x))
  25. #Define S_SNAKE(x) (SUBSTR(CHR(176)+CHR(177)+CHR(178)+CHR(219),x,1))
  26. #Define SIGN(x) IIF(x>0,1,IIF(x<0,-1,0))
  27.  
  28. STATIC seed
  29.  
  30. FUNCTION SNAKE
  31. LOCAL i,nXd:=0,nYd:=0,nLon,nDiff,nAvis,nForm,nLon2,nP,nP2
  32. LOCAL cSc,nrow:=row(),ncol:=col(),anc_cu
  33. seed:=FRAC(seconds()/1000)
  34. nP:=ARRAY(LMAX,2)
  35. nP[1,1]:=40
  36. nP[1,2]:=12
  37. nAvis:=MAX(5,alea(LMAX))
  38. nForm:=MAX(5,alea(LMAX))
  39. cDir(@nXd,@nYd)
  40. nLon:=MAX(4,alea(10))
  41. nLon2:=nLon
  42. FOR i:=2 TO nLon
  43.   nP[i,1]:=nP[1,1]
  44.   nP[i,2]:=nP[1,2]-(i-1)
  45. NEXT i
  46.  
  47. cSc:=savescreen(0,0,maxrow(),maxcol())
  48. CLEAR SCREEN
  49. anc_cu:=setcursor(0)
  50. sdisp(nP,nLon)
  51. DO WHILE inkey(SPEED)==0
  52.   if nAvis--<0
  53.      nAvis:=MAX(5,alea(LMAX))
  54.      cdir(@nXd,@nYd)
  55.   endif
  56.  
  57.   if nForm--<0
  58.      nForm:=MAX(5,alea(LMAX))
  59.      nLon2:=MAX(4,alea(10))
  60.   ENDIF
  61.   sundisp(nP,nLon)
  62.   nDiff:=nLon2-nLon
  63.   cPos(@nP,@nXd,@nYd,nLon,nDiff>0)
  64.   nLon+=SIGN(nDiff)
  65.   sdisp(nP,nLon)
  66. ENDDO
  67. restscreen(0,0,maxrow(),maxcol(),cSc)
  68. setcursor(anc_cu)
  69. setpos(nrow,ncol)
  70. RETURN .T.
  71.  
  72. FUNCTION sundisp(nP,nLon)
  73. LOCAL j
  74.  
  75. FOR j:=1 TO nLon
  76.   @ nP[j,2],nP[j,1] say "  "
  77. NEXT j
  78.  
  79. RETURN NIL
  80.  
  81. FUNCTION sdisp(nP,nLon)
  82. LOCAL i:=1,j
  83.  
  84. FOR j:=nLon TO 1 STEP -1
  85.   @ nP[j,2],nP[j,1] say REPLICATE(S_SNAKE(INT(i)),2)
  86.   i+=(4/nLon)
  87. NEXT j
  88.  
  89. RETURN NIL
  90.  
  91.  
  92. FUNCTION cpos(nPa,nXd,nYd,nLon,inc)
  93. LOCAL i,x,y
  94. x:=nPa[1,1]+nXd
  95. y:=nPa[1,2]+nYd
  96. DO WHILE x<0 .OR. x> MAXCOL() .OR. y<0 .OR. y>MAXROW()
  97.   cdir(@nXd,@nYd)
  98.   x:=nPa[1,1]+nXd
  99.   y:=nPa[1,2]+nYd
  100. ENDDO
  101. FOR i:=nLon+IIF(inc<>NIL .AND. inc,1,0) TO 2 STEP -1
  102.    nPa[i,1]:=nPa[i-1,1]
  103.    nPa[i,2]:=nPa[i-1,2]
  104. NEXT i
  105. nPa[1,1]:=x
  106. nPa[1,2]:=y
  107. RETURN NIL
  108.  
  109. FUNCTION cdir(x,y)
  110. x:=alea(3)-1
  111. y:=alea(3)-1
  112. DO WHILE x=0 .AND. y=0
  113.   x:=alea(3)-1
  114.   y:=alea(3)-1
  115. ENDDO
  116. RETURN NIL
  117.  
  118.  
  119. FUNCTION alea(nX)
  120.  
  121. seed:=FRAC(seed*9821+.211327)
  122. RETURN INT(seed*nX)
  123.  
  124.