Put a treasure in the Old camp, Buried shrine and Crystal hollow. The player sees a glint beside a tunnel when the next room still contains one. We are adding information that changes independently of the cave’s connections.
Replace lines 200, 250, 260, 1020, 1060.
Add lines 240, 440, 1140.
200 DIM m(12,4): DIM a$(12,24): DIM b$(12,28): DIM t(12)
240 LET t(6)=1: LET t(10)=1: LET t(12)=1
250 LET rm=1: LET found=0: LET turns=0
260 LET d$="NSEW": LET e$="nsew": LET h$="Find three lost treasures."
440 IF t(rm)=1 THEN LET t(rm)=0: LET found=found+1: LET h$="You recover a lost treasure."
1020 PRINT AT 2,2; INK 6;"TREASURE ";found;"/3 TURNS ";turns
1060 PRINT AT 9,2; INK 6;"TUNNELS NEARBY SIGNS"
1140 IF t(v)=1 THEN PRINT AT y,15; INK 4;"Glint"RUN the changed program.
Complete source at this checkpoint
10 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
200 DIM m(12,4): DIM a$(12,24): DIM b$(12,28): DIM t(12)
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
240 LET t(6)=1: LET t(10)=1: LET t(12)=1
250 LET rm=1: LET found=0: LET turns=0
260 LET d$="NSEW": LET e$="nsew": LET h$="Find three lost treasures."
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."
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."
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"
1140 IF t(v)=1 THEN PRINT AT y,15; INK 4;"Glint"
1160 NEXT j
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
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,11From the entrance press S, then E. The east tunnel from the Root chamber should show Glint; entering the Old camp raises the count to 1. Go west and east again. The count must remain 1 and the glint must have disappeared.
A flag for each room
DIM t(12) creates twelve zeros. We put 1 in t(6), t(10) and t(12). Each value is a flag: a small value with an agreed meaning. One means an uncollected treasure; zero means none remains. The map does not change when a treasure is picked up.
After a valid action changes rm, line 440 checks t(rm). When it is 1, the line sets it to zero, increases found and selects the discovery message. Clearing the flag is essential: without it, waiting in the room or coming back would collect the same treasure again.
The caption h$ holds the latest message. Ordinary actions replace it with the footsteps message; a discovery then replaces that with the treasure message. Drawing the room uses whichever message the action produced.
Ask about the destination, not this room
The tunnel loop already puts each destination in v. Line 1140 checks t(v), so its clue refers to the next room. t(rm) would answer a different question: whether treasure remains where you are standing.
Zero links skip the rest of that tunnel’s work before the array lookup. t(0) is not a valid element. The earlier wall representation therefore matters to the clue routine too.
What should happen if you press Space just after collecting a treasure?
Show the explanation
The turn count rises, but found does not. t(rm) is already zero. The room’s name and map links stay the same too.
You can find all three treasures at this checkpoint, but there is no winning rule yet. Returning to the entrance also keeps the program running. We will make that return meaningful after adding danger and its warnings.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 12, chapter 13.
Run it here
This unit's program, built for you.
- Program
- caverns.tap
- Machine
- ZX Spectrum 48K (PAL)