home *** CD-ROM | disk | FTP | other *** search
/ Explore the World of Soft…ids, Adults, Educational / RocelcoInc-ExploreTheWorldOfSoftware-KidsAdultsEducational-Vol2-Shareware.iso / educate / disk061 / frog.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1986-08-10  |  6.0 KB  |  194 lines

  1. 10  '             F R O G . B A S          8/10/86 11:21 PM
  2. 20  '
  3. 30  '    HELP THE FROGGY generates random mazes for a child to solve
  4. 40  '    by guiding a frog to the lily pad at the end of the maze.
  5. 50  '    The size of the maze may be set to a 5x5, 6x6, or 7x7 maze by changing
  6. 60  '    the value for the variable SIZE in line 120 below.
  7. 70  '
  8. 80  '    Converted for IBM-PC Screen 1.
  9. 90  '
  10. 100  ' **      Algorithm for generic maze generator by Dan Rollins, 04/25/83
  11. 110  ' **      Rest of program by Rob Robinson 12/28/85
  12. 120  '
  13. 130  '    Initialize all variables.
  14. 140  '
  15. 150  DEFINT A-R,T-Z
  16. 160  SCREEN 1 : COLOR 1,0 : CLS
  17. 170  LOCATE 2,13 : PRINT "HELP THE FROGGY"
  18. 180  LOCATE 24,1 : PRINT "  copyright 1985, Computing Specialties";
  19. 190  '
  20. 200  '
  21. 210  '         Poke subroutine ALOAD into memory.
  22. 220  '
  23. 230  DEF SEG : ALOAD!= 48000
  24. 240  FOR IB=0 TO  95 : READ BYTE : POKE ALOAD!+IB,BYTE : NEXT IB
  25. 250  DATA &H55, &H8B, &HEC, &H8B, &H5E, &H0A, &H8A, &H0F, &HB5, &H00, &H8B, &H77
  26. 260  DATA &H01, &H8B, &H5E, &H08, &H8B, &H07, &H8E, &HC0, &HBF, &H00, &H00, &HA4
  27. 270  DATA &HE2, &HFD, &HB0, &H00, &HAA, &H1E, &H06, &H1F, &H07, &HB0, &H00, &HB4
  28. 280  DATA &H3D, &HBA, &H00, &H00, &HCD, &H21, &H72, &H24, &H8B, &HD8, &HB9, &H07
  29. 290  DATA &H00, &HBA, &H00, &H00, &HB4, &H3F, &HCD, &H21, &H3B, &HC1, &H74, &H05
  30. 300  DATA &HB8, &H0D, &H00, &H75, &H0F, &HBE, &H05, &H00, &H8B, &H0C, &HB4, &H3F
  31. 310  DATA &HBA, &H00, &H00, &HCD, &H21, &HB8, &H00, &H00, &H8B, &H7E, &H06, &H26
  32. 320  DATA &H89, &H05, &HB4, &H3E, &HCD, &H21, &H06, &H1F, &H5D, &HCA, &H06, &H00
  33. 330  '
  34. 340  '           Load the title picture onto the screen.
  35. 350  '
  36. 360  SEG2%=&HB800 : BERR%=0 : FILE$="FROG1.PIC" : CALL ALOAD!(FILE$,SEG2%,BERR%)
  37. 370  SIZE=7
  38. 380  DIM T(5),MZ(100,100)
  39. 390  DIM YD(3),XD(3) : YD(0)=-1 : XD(1)=1 : YD(2)=1 : XD(3)=-1
  40. 400  DIM PWR2(3) : PWR2(0)=1 : PWR2(1)=2 : PWR2(2)=4 : PWR2(3)=8
  41. 410  RANDOMIZE TIMER
  42. 420  DIM FROGGY(250),PAD(250)
  43. 430  '
  44. 440  '   Load the title picture onto the screen and fill the graphics arrays.
  45. 450  '
  46. 460  LOCATE 25,7
  47. 470  GET (41,20)-(71,36),FROGGY
  48. 480  GET (236,150)-(285,165),PAD
  49. 490  '
  50. 500  '   Generate a random maze.
  51. 510  '
  52. 520  H=SIZE-1 : V=SIZE-1 : TH=H*30+3 : TV=V*20+30
  53. 530  X=INT(RND*H) : Y=INT(RND*V)
  54. 540  GOSUB 710
  55. 550  MZ(0,0)=MZ(0,0)+1
  56. 560  '
  57. 570  '   Display the maze on the screen.
  58. 580  '
  59. 590  GOSUB 940
  60. 600  '
  61. 610  '   Solve the maze.
  62. 620  '
  63. 630  GOSUB 1130
  64. 640  '
  65. 650  '   Go back for another maze.
  66. 660  '
  67. 670  GOTO 420
  68. 680  '
  69. 690  '           Subroutine to generate a randome maze.
  70. 700  '
  71. 710  FOR J=0 TO H : FOR K=0 TO V : MZ(J,K)=0 : NEXT : NEXT
  72. 720  LS=1
  73. 730  RC=0 : TR=(H+1)*(V+1)-1
  74. 740  Q=0 : IF RC=TR THEN RETURN
  75. 750  IF PLAY(0)<4 THEN GOSUB 1820
  76. 760  IF Y>0 THEN IF MZ(X,Y-1)=0 THEN Q=Q+1 : T(Q)=0
  77. 770  IF X<H THEN IF MZ(X+1,Y)=0 THEN Q=Q+1 : T(Q)=1
  78. 780  IF Y<V THEN IF MZ(X,Y+1)=0 THEN Q=Q+1 : T(Q)=2
  79. 790  IF X>0 THEN IF MZ(X-1,Y)=0 THEN Q=Q+1 : T(Q)=3
  80. 800  IF Q=0 GOTO 880
  81. 810  D=INT(RND*Q)+1 : DIR=T(D)
  82. 820  MZ(X,Y)=MZ(X,Y)+PWR2(DIR)
  83. 830  Y=Y+YD(DIR) : X=X+XD(DIR)
  84. 840  ND=DIR-2 : IF ND<0 THEN ND=4+ND
  85. 850  MZ(X,Y)=MZ(X,Y)+PWR2(ND)
  86. 860  RC=RC+1
  87. 870  GOTO 740
  88. 880  Y=Y+1 : IF Y>V THEN Y=0 : X=X+1 : IF X>H THEN X=0
  89. 890  IF MZ(X,Y)=0 THEN 880
  90. 900  GOTO 740
  91. 910  '
  92. 920  '           Subroutine to display the maze on the screen.
  93. 930  '
  94. 940  CLS : LOCATE 25,7
  95. 950  PRINT "H E L P   T H E   F R O G G Y";
  96. 960  DX=30 : DY=20 : PX=DX : PY=DY : CL=3
  97. 970  FOR Y=0 TO V
  98. 980    FOR X=0 TO H
  99. 990      IF INT(MZ(X,Y)/2)=MZ(X,Y)/2 THEN LINE (PX,PY)-(PX+DX,PY),CL : PX=PX+DX : GOTO 1010
  100. 1000      PX=PX+DX
  101. 1010    NEXT X : PX=DX
  102. 1020    FOR X=0 TO H
  103. 1030      IF MZ(X,Y)>7 THEN PX=PX+DX : GOTO 1050
  104. 1040      LINE(PX,PY)-(PX,PY+DY),CL : PX=PX+DX
  105. 1050    NEXT X : LINE(PX,PY)-(PX,PY+DY),CL : PX=DX : PY=PY+DY
  106. 1060  NEXT Y
  107. 1070  FOR X=0 TO H-1
  108. 1080  LINE (PX,PY)-(PX+DX,PY),CL : PX=PX+DX
  109. 1090  NEXT X
  110. 1100  RETURN
  111. 1110  '
  112. 1120  '           Subroutine to solve the maze.
  113. 1130  '          Set up variables for playing
  114. 1140  '
  115. 1150  PX=DX+1 : PY=DY+1 : MOVES=0
  116. 1160  BLANK=0 : RED=2 : BLUE=1
  117. 1170  NUL$=CHR$(0) : UP$=NUL$+CHR$(72) : DN$=NUL$+CHR$(80)
  118. 1180  RT$=NUL$+CHR$(77) : LT$=NUL$+CHR$(75) : STIME$=TIME$
  119. 1190  PUT (PX*(V+1)-8,PY*(V+2)+8),PAD,PSET
  120. 1200  PUT (PX,PY),FROGGY,XOR
  121. 1210  C$=INKEY$ : IF C$=CHR$(27) THEN RUN"menu"
  122. 1220  IF C$<>"" THEN 1210
  123. 1230  '
  124. 1240  '           Wait until a key is pressed, then compute the direction desired
  125. 1250  '
  126. 1260  C$=INKEY$ : IF C$="" THEN 1260
  127. 1270  DX=0 : DY=0 : TX=0 : TY=0
  128. 1280  IF C$=CHR$(27) THEN RUN "menu"
  129. 1290  IF C$=UP$ AND PY>21 THEN DY=-20 : TY=-1
  130. 1300  IF C$=DN$ AND PY<TV THEN DY=20 : TY=+19
  131. 1310  IF C$=RT$ AND PX<TH THEN DX=30 : TX=+29
  132. 1320  IF C$=LT$ AND PX>31 THEN DX=-30 : TX=-1
  133. 1330  IF DX=0 AND DY=0 THEN 1260
  134. 1340  '
  135. 1350  '           Check to see if a maze wall is blocking the desired path.
  136. 1360  '
  137. 1370  S=POINT (PX+TX,PY+TY)
  138. 1380  IF S<>BLANK AND S<>RED AND S<>BLUE THEN 1260
  139. 1390  '
  140. 1400  '           Move the froggy to the new spot.
  141. 1410  '
  142. 1420  S=POINT(PX+DX+15,PY+DY+10)
  143. 1430  PUT (PX,PY),FROGGY,XOR
  144. 1440  SOUND  37,4 :SOUND  88,2
  145. 1450  '
  146. 1460  '           If the frog moved backwards, erase the red line.
  147. 1470  '           If it moved forward, plot a red line showing the path.
  148. 1480  '
  149. 1490  IF S=RED THEN LINE (PX+15,PY+10)-(PX+DX+15,PY+DY+10),BLANK ELSE LINE (PX+15,PY+10)-(PX+DX+15,PY+DY+10),RED
  150. 1500  '
  151. 1510  '           Update the coordinates and the number of moves.
  152. 1520  '
  153. 1530  PX=PX+DX : PY=PY+DY : MOVES=MOVES+1
  154. 1540  LOCATE 24,1 : PRINT MOVES;" moves";
  155. 1550  '
  156. 1560  '           If the frog isn't on the pad yet, go back for another move.
  157. 1570  '
  158. 1580  IF PX>TH-30 AND PY>TV THEN 1630 ELSE 1200
  159. 1590  '
  160. 1600  '           The frog is on the pad, give him a fly to catch and eat.
  161. 1610  '           then go back for another game with a new maze.
  162. 1620  '
  163. 1630  PUT (PX,PY),FROGGY,PSET : LOCATE 1,1
  164. 1640  FL=PX+50 : FR=PX+75 : FT=PY : FB=PY+15 : FX=FR : FY=FB
  165. 1650  FOR I=1 TO 50
  166. 1660    PSET (FX,FY),0 : FX=INT(RND*6-3)+FX : FY=INT(RND*6-3)+FY
  167. 1670    PSET (FX,FY),3
  168. 1680    SOUND 37+RND*25,0.25
  169. 1685    FOR J=1 TO 10 : NEXT J
  170. 1690  NEXT I
  171. 1700  LINE (PX+28,PY+6)-(FX,FY),RED
  172. 1710  SOUND 1050,0.5
  173. 1720  LINE (PX+28,PY+6)-(FX,FY),0
  174. 1730  FOR I=1 TO 25 : SOUND 97,0.02
  175. 1740  LINE (PX+23,PY+6)-(PX+28,PY+6),1 : LINE (PX+23,PY+6)-(PX+28,PY+6),0
  176. 1750  FOR J=1 TO 100 : NEXT J
  177. 1760  NEXT I
  178. 1770  PSET (PX+23,PY+6),1 : PSET (PX+24,PY+5),0
  179. 1780  T$=INKEY$ : IF T$="" THEN 1810
  180. 1790  IF T$=CHR$(27) THEN RUN"MENU"
  181. 1800  GOTO 1780
  182. 1810  GOTO 520
  183. 1820  '
  184. 1830  '          SUBROUTINE TO PLAY "FROGGY WENT A COURTIN"
  185. 1840  '
  186. 1850  ON LS GOTO 1860,1880,1900
  187. 1860  PLAY "MBMST200O1C4F8F8F8F8F8F8A4 G4 D4MLC4F2F4C4F2F4P4"
  188. 1870  GOTO 1910
  189. 1880  PLAY "MSA8>C8C8C8C8C8D4C4<A4 F4"
  190. 1890  GOTO 1910
  191. 1900  PLAY "  MST200G4F4F4MLF8G8MSA4F4D4MLC4F2F4C4F4F2"
  192. 1910  LS=LS+1 : IF LS=4 THEN LS=1
  193. 1920  RETURN
  194.