Skip to content

Invite the explorer

Add the accepted title and explain the expedition before it starts.

  • Sinclair ZX Spectrum
  • BASIC

The expedition now has its rules and ending. Put its instructions before the first move so someone new can understand the objective, controls and escape warning.

Add lines 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130.

changes.bas
  20 PRINT AT 3,8; INK 5;"THE CAVERNS"
  30 PRINT AT 6,2;"Find three lost treasures."
  40 PRINT AT 8,2;"Bring them to the entrance."
  50 PRINT AT 10,2;"N S E W: move. SPACE: wait."
  60 PRINT AT 12,2;"Read the signs by each exit."
  70 PRINT AT 14,2;"If it arrives, leave at once!"
  80 PRINT AT 17,2;"R restarts. Q quits."
  90 PRINT AT 20,2; INK 6;"S enters the cave."
 100 GO SUB 9000
 110 LET k$=INKEY$: IF k$="" THEN GO TO 110
 120 IF k$="q" OR k$="Q" THEN GO TO 8000
 130 IF k$<>"s" AND k$<>"S" THEN GO TO 110

RUN the changed program.

Complete source at this checkpoint
caverns.bas
  10 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
  20 PRINT AT 3,8; INK 5;"THE CAVERNS"
  30 PRINT AT 6,2;"Find three lost treasures."
  40 PRINT AT 8,2;"Bring them to the entrance."
  50 PRINT AT 10,2;"N S E W: move. SPACE: wait."
  60 PRINT AT 12,2;"Read the signs by each exit."
  70 PRINT AT 14,2;"If it arrives, leave at once!"
  80 PRINT AT 17,2;"R restarts. Q quits."
  90 PRINT AT 20,2; INK 6;"S enters the cave."
 100 GO SUB 9000
 110 LET k$=INKEY$: IF k$="" THEN GO TO 110
 120 IF k$="q" OR k$="Q" THEN GO TO 8000
 130 IF k$<>"s" AND k$<>"S" THEN GO TO 110
 200 DIM m(12,4): DIM a$(12,24): DIM b$(12,28): DIM t(12): DIM c(8)
 210 RESTORE 9500
 220 FOR i=1 TO 12: READ a$(i),b$(i): FOR j=1 TO 4: READ m(i,j): NEXT j: NEXT i
 230 RESTORE 9800: FOR i=1 TO 8: READ c(i): NEXT i
 240 LET t(6)=1: LET t(10)=1: LET t(12)=1
 250 LET rm=1: LET pit=7: LET ci=3: LET cr=c(ci): LET found=0: LET turns=0
 260 LET d$="NSEW": LET e$="nsew": LET h$="Find treasure. Return here."
 270 GO SUB 1000
 300 GO SUB 9000
 310 LET k$=INKEY$: IF k$="" THEN GO TO 310
 320 IF k$="q" OR k$="Q" THEN GO TO 8000
 330 IF k$="r" OR k$="R" THEN GO TO 200
 340 LET dir=0: FOR j=1 TO 4: IF k$=d$(j) OR k$=e$(j) THEN LET dir=j
 350 NEXT j
 360 IF dir=0 AND k$<>" " THEN GO TO 300
 370 LET dest=rm
 380 IF dir>0 THEN LET dest=m(rm,dir)
 390 IF dest=0 THEN PRINT AT 18,2; INK 6;"No tunnel in that direction. ": GO TO 300
 400 LET turns=turns+1: LET h$="Your footsteps fade away."
 410 IF dest=pit THEN LET rm=dest: LET ending=1: GO TO 5000
 420 IF dest=cr THEN LET rm=dest: LET ending=2: GO TO 5000
 430 LET rm=dest
 440 IF t(rm)=1 THEN LET t(rm)=0: LET found=found+1: LET h$="You recover a lost treasure."
 450 IF rm=1 AND found=3 THEN LET ending=3: GO TO 5000
 460 LET ci=ci+1: IF ci=9 THEN LET ci=1
 470 LET cr=c(ci)
 480 IF cr=rm THEN LET h$="It arrives! Leave next turn!"
 490 GO TO 270
1000 CLS
1010 PRINT AT 0,8; INK 5;"THE CAVERNS"
1020 PRINT AT 2,2; INK 6;"TREASURE ";found;"/3    TURNS ";turns
1030 INK 1: PLOT 16,148: DRAW 223,0
1040 PRINT AT 5,2; INK 5;a$(rm)
1050 PRINT AT 7,2; INK 7;b$(rm)
1060 PRINT AT 9,2; INK 6;"TUNNELS       NEARBY SIGNS"
1070 FOR j=1 TO 4
1080 LET v=m(rm,j): LET y=10 +j
1090 PRINT AT y,2; INK 7;d$(j);"  --"
1100 IF v=0 THEN GO TO 1160
1110 PRINT AT y,2; INK 7;d$(j);"  Open"
1120 IF v=pit THEN PRINT AT y,15; INK 6;"Cold draught"
1130 IF v=cr THEN PRINT AT y,15; INK 6;"Footsteps"
1140 IF t(v)=1 THEN PRINT AT y,15; INK 4;"Glint"
1150 IF v=cr AND t(v)=1 THEN PRINT AT y,15; INK 6;"Steps + glint"
1160 NEXT j
1170 IF cr=rm THEN PRINT AT 16,2; INK 6;"IT IS HERE. MOVE NOW."
1180 IF cr<>rm THEN PRINT AT 16,2; INK 7;"No creature in this room."
1190 PRINT AT 18,2; INK 5;h$
1200 PRINT AT 20,2; INK 7;"N S E W / SPACE waits"
1210 PRINT AT 21,2; INK 7;"R: restart   Q: quit"
1220 RETURN
5000 IF ending=1 THEN LET h$="The cold tunnel hid a pit."
5010 IF ending=2 THEN LET h$="The creature catches you."
5020 IF ending=3 THEN LET h$="All three treasures are safe."
5030 GO SUB 1000
5040 PRINT AT 16,2; INK 6;"                            "
5050 IF ending=3 THEN PRINT AT 16,2; INK 6;"YOU ESCAPED THE CAVERNS."
5060 IF ending<>3 THEN PRINT AT 16,2; INK 6;"YOUR EXPEDITION ENDS."
5070 PRINT AT 20,2; INK 7;"R: try again   Q: quit       ": PRINT AT 21,2;"                            "
5080 GO SUB 9000
5090 LET k$=INKEY$: IF k$="" THEN GO TO 5090
5100 IF k$="q" OR k$="Q" THEN GO TO 8000
5110 IF k$="r" OR k$="R" THEN GO TO 200
5120 GO TO 5090
8000 PRINT AT 21,2; INK 7;"The Caverns finished.       ": STOP
9000 IF INKEY$<>"" THEN GO TO 9000
9010 RETURN
9500 DATA "The entrance","Daylight rims the stone.",0,5,2,0
9510 DATA "Split passage","Two worn paths meet here.",0,6,3,1
9520 DATA "Echo gallery","Every step returns twice.",0,7,4,2
9530 DATA "High ledge","A narrow shelf bends south.",0,8,0,3
9540 DATA "Root chamber","Roots grip the damp ceiling.",1,9,6,0
9550 DATA "Old camp","A torn pack lies in dust.",2,10,7,5
9560 DATA "The black shaft","The floor vanishes below.",3,11,8,6
9570 DATA "Dripping stair","Water counts the seconds.",4,12,0,7
9580 DATA "Still pool","Your lamp trembles in water.",5,0,10,0
9590 DATA "Buried shrine","Carved faces watch the path.",6,0,11,9
9600 DATA "Low arch","You stoop beneath the rock.",7,0,12,10
9610 DATA "Crystal hollow","Crystals catch the lamplight.",8,0,0,11
9800 DATA 2,3,4,8,12,11,10,6

RUN should show the title. S enters the cave; Q quits. The expedition itself is the same one you just built, with the same fixed map, treasure and patrol.

Separate the invitation from the expedition

Lines 20–90 explain the goal, directions, waiting, clues and the arrival rule. The title loop releases the previous key, then listens for S or Q. An unrelated key keeps it at the title.

The game setup still begins at 200. That is also R’s destination from play or a result, so replay can rebuild the expedition without showing the title every time. RUN starts at 10 and shows the invitation again.

The release routine matters across this boundary. S is both “start” on the title and “south” during play. The title’s S must not immediately spend a movement turn. The main input loop waits for its release before accepting the next action.

Explain what the player can rely on

The cave is fixed. A restart restores the same map, pit, treasure positions and creature phase. This makes experimentation meaningful: change your action and compare its consequences from the same opening.

The creature moves after valid actions, not while the player reads. Space deliberately waits; an invalid key or blocked exit does not. If it arrives, the next valid action must leave. These details are worth explaining because they determine whether the player can make a considered choice.

Why should R jump to line 200 instead of line 270?

Show the explanation

270 draws the current state. It does not restore treasure, reset the turn count or move the creature back to the start. 200 begins the setup that does all of those jobs.

Try Q from the title, during exploration and after a result. Use RUN to begin again. Start, move a few rooms, collect treasure, restart and check that the expedition really is fresh. The finished game remains silent; its room names, clue table and messages carry all the information needed to play.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 5, chapter 13, chapter 18.

Run it here

This unit's program, built for you.

Program
caverns.tap
Machine
ZX Spectrum 48K (PAL)

Download caverns.tap