Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.     REM
  2.     REM --- Tiny BASIC Interpreter and Compiler Project
  3.     REM --- Hunt the Wumpus Demonstration Game
  4.     REM
  5.     REM --- Released as Public Domain by Damian Gareth Walker 2019
  6.     REM --- Created: 08-Aug-2019
  7.     REM
  8.  
  9.     REM --- Variable List
  10.     REM
  11.     REM A - Bat 1 position
  12.     REM B - Bat 2 position
  13.     REM C - Player position
  14.     REM D - Destination to move or shoot
  15.     REM E - exit 1 from the current cave
  16.     REM F - exit 2 from the current cave
  17.     REM G - exit 3 from the current cave
  18.     REM H - Hole 1 (bottomless pit) position
  19.     REM I - Hole 2 (bottomless pit) position
  20.     REM J - Randomised position for player or hazard
  21.     REM K - origin location of arrow in motion (before L)
  22.     REM L - previous location of arrow in motion
  23.     REM M - menu option for move or shoot
  24.     REM N - range for arrow shot
  25.     REM P - parameter to the 'exits' routine
  26.     REM Q - number of arrows in quiver
  27.     REM R - random number
  28.     REM S - random number generator seed
  29.     REM W - Wumpus position
  30.  
  31.     REM --- Intialise the random number generator
  32.     PRINT "Think of a number"
  33.     INPUT S
  34.  
  35.     REM --- Initialise the player and hazard positions
  36.     LET A=0
  37.     LET B=0
  38.     LET C=0
  39.     LET H=0
  40.     LET I=0
  41.     LET W=0
  42.  
  43.     REM --- Fill the player's quiver
  44.     LET Q=5
  45.  
  46.     REM --- Distribute the player and hazards across the map
  47.     GOSUB 130
  48.     LET A=J
  49.     GOSUB 130
  50.     LET B=J
  51.     GOSUB 130
  52.     LET C=J
  53.     GOSUB 130
  54.     LET H=J
  55.     GOSUB 130
  56.     LET I=J
  57.     GOSUB 130
  58.     LET W=J
  59.  
  60.     REM --- Introductory text
  61.     PRINT "You enter the caves to Hunt the Wumpus!"
  62.  
  63.     REM --- Main Game Loop
  64.  30 PRINT "You are in room ",C
  65.     LET P=C
  66.     GOSUB 200
  67.     GOSUB 50
  68.     PRINT "Exits are ",E,",",F,",",G
  69.  35 PRINT "1:Move or 2:Shoot?"
  70.     INPUT M
  71.     IF M<1 THEN GOTO 35
  72.     IF M>2 THEN GOTO 35
  73.     IF M=1 THEN GOSUB 120
  74.     IF M=2 THEN GOSUB 150
  75.     GOTO 30
  76.  
  77.     REM --- Subroutine to check for hazards
  78.  
  79.     REM Has the player encountered a bat?
  80.  50 IF C<>A THEN IF C<>B THEN GOTO 60
  81.     PRINT "A bat swoops down and picks you up..."
  82.     GOSUB 100
  83.     PRINT "...and drops you down"
  84.     LET P=C
  85.     GOSUB 200
  86.  
  87.     REM Has the player fallen in a pit?
  88.  60 IF C<>H THEN IF C<>I THEN GOTO 65
  89.     PRINT "You fall down a bottomless hole into the abyss!"
  90.     END
  91.  
  92.     REM Has the player startled the wumpus?
  93.  65 IF C<>W THEN GOTO 70
  94.     PRINT "You stumble upon the wumpus!"
  95.     GOSUB 90
  96.     PRINT "The wumpus runs away!"
  97.  
  98.     REM Is there a pit nearby?
  99.  70 IF E<>H THEN IF F<>H THEN IF G<>H THEN GOTO 72
  100.     GOTO 73
  101.  72 IF E<>I THEN IF F<>I THEN IF G<>I THEN GOTO 75
  102.  73 PRINT "You feel a cold wind blowing from a nearby cavern."
  103.  
  104.     REM Is the wumpus nearby?
  105.  75 IF E<>W THEN IF F<>W THEN IF G<>W THEN GOTO 80
  106.     PRINT "You smell something terrible nearby."
  107.  
  108.     REM Is there a bat nearby?
  109.  80 IF E<>A THEN IF F<>A THEN IF G<>A THEN GOTO 82
  110.     GOTO 83
  111.  82 IF E<>B THEN IF F<>B THEN IF G<>B THEN GOTO 84
  112.  83 PRINT "You hear a loud squeaking and a flapping of wings."
  113.  84 RETURN
  114.  
  115.     REM --- Relocate the Wumpus
  116.  90 GOSUB 140
  117.     LET R=R-(R/4*4)
  118.     IF R=1 THEN LET W=E
  119.     IF R=2 THEN LET W=F
  120.     IF R=3 THEN LET W=G
  121.     IF W<>C THEN RETURN
  122.     PRINT "The wumpus eats you!"
  123.     END
  124.  
  125.     REM --- Relocate bat and player
  126. 100 GOSUB 140
  127.     LET R=R-(R/4*4)
  128.     IF R=0 THEN RETURN
  129.     LET P=C
  130.     GOSUB 200
  131.     IF R=1 THEN LET D=E
  132.     IF R=2 THEN LET D=F
  133.     IF R=3 THEN LET D=G
  134.     IF D<>A THEN IF D<>B THEN GOTO 110
  135.     GOTO 100
  136. 110 PRINT "...moves you to room ",D,"..."
  137.     IF A=C THEN LET A=D
  138.     IF B=C THEN LET B=D
  139.     LET C=D
  140.     GOTO 100
  141.  
  142.     REM --- Subroutine to move
  143. 120 PRINT "Where?"
  144.     INPUT D
  145.     IF D<>E THEN IF D<>F THEN IF D<>G THEN GOTO 120
  146.     LET C=D
  147.     RETURN
  148.  
  149.     REM -- Find a random unoccupied position
  150. 130 GOSUB 140
  151.     LET J=1+R-R/20*20
  152.     IF J<>A THEN IF J<>B THEN IF J<>C THEN GOTO 134
  153.     GOTO 130
  154. 134 IF J<>H THEN IF J<>I THEN IF J<>W THEN RETURN
  155.     GOTO 130
  156.  
  157.     REM --- Random number generator
  158. 140 LET S=5*S+35
  159.     LET S=S-S/4096*4096
  160.     LET R=S
  161.     RETURN
  162.  
  163.     REM --- Subroutine to shoot
  164. 150 PRINT "Shoot how far (1-5)?"
  165.     INPUT N
  166.     IF N<1 THEN GOTO 150
  167.     IF N>5 THEN GOTO 150
  168.     LET P=C
  169.     LET L=0
  170. 160 GOSUB 200
  171.     LET K=L
  172.     LET L=P
  173.     PRINT "Arrow is next to rooms ",E,",",F,",",G
  174. 164 PRINT "Shoot where?"
  175.     INPUT P
  176.     IF P<>E THEN IF P<>F THEN IF P<>G THEN GOTO 180
  177.     IF P=K THEN GOTO 185
  178.     IF P=W THEN GOTO 195
  179.     LET N=N-1
  180.     IF N>0 THEN GOTO 160
  181.     LET Q=Q-1
  182.     PRINT "The arrow startles the wumpus."
  183.     LET P=W
  184.     GOSUB 200
  185.     GOSUB 90
  186.     IF Q=0 THEN GOTO 190
  187.     PRINT "You have ",Q," arrows left."
  188.     RETURN
  189. 180 PRINT "The arrow can't reach there."
  190.     GOTO 164
  191. 185 PRINT "The arrow can't double back on itself."
  192.     GOTO 164
  193. 190 PRINT "You used your last arrow!"
  194.     PRINT "Your demise is now inevitable."
  195.     END
  196. 195 PRINT "You hit the wumpus!"
  197.     END
  198.  
  199.     REM --- Subroutine to set the exits
  200.     REM Input: P - current position
  201.     REM Outputs: E, F, G (exits)
  202. 200 IF P>=1 THEN IF P<=20 THEN GOTO 205
  203.     PRINT "Illegal position ",P
  204.     END
  205. 205 GOTO 200+10*((14+P)/10)
  206.  
  207.     REM --- Outer caves
  208. 210 LET E=P-1
  209.     IF E=0 THEN LET E=5
  210.     LET F=P+1
  211.     IF F=6 THEN LET F=1
  212.     LET G=4+2*P
  213.     RETURN
  214.  
  215.     REM --- Middle caves
  216. 220 LET E=P-1
  217.     IF E=5 THEN LET E=15
  218.     LET F=P+1
  219.     IF F=16 THEN LET F=6
  220.     IF P/2*2<>P THEN LET G=13+P/2
  221.     IF P/2*2=P THEN LET G=P/2-2
  222.     RETURN
  223.  
  224.     REM --- Inner caves
  225. 230 LET E=P-1
  226.     IF E=15 THEN LET E=20
  227.     LET F=P+1
  228.     IF F=21 THEN LET F=16
  229.     LET G=2*P-25
  230.     RETURN