Skip to content
Game 14 Unit 3 of 6 1 hr learning time

The Draft

Hide a pit somewhere in the cave and sense it without seeing it — a reusable adjacency check turns the graph into a warning when danger is one room away.

50% of The Caverns

The cave is empty and safe. Now put something deadly in it that you can never see — a bottomless pit hidden in a random room. The second new idea of The Caverns is hidden state: the pit is a single number the player is never shown, and the only way to know it is near is the clue it leaves in the room next door. A cold draft means "step carefully".

  10 BORDER 0: PAPER 1: INK 7: CLS
 100 RANDOMIZE
 110 DIM n(20): DIM s(20): DIM e(20): DIM w(20)
 120 RESTORE 1010
 130 FOR i = 1 TO 20
 140 READ n(i), s(i), e(i), w(i)
 150 NEXT i
 160 LET rm = 1
 170 LET pit = INT (RND * 19) + 2
 270 CLS
 280 LET a$ = "*** THE CAVERNS ***": LET y = 0: GO SUB 9000
 300 PRINT AT 3, 2; "You are in room "; rm; "."
 310 PRINT AT 5, 2; "Exits: ";
 320 IF n(rm) > 0 THEN PRINT "N ";
 330 IF s(rm) > 0 THEN PRINT "S ";
 340 IF e(rm) > 0 THEN PRINT "E ";
 350 IF w(rm) > 0 THEN PRINT "W ";
 360 PRINT AT 14, 2; "Pit: "; pit
 370 LET clue = 0
 380 LET chk = pit: GO SUB 740
 390 IF adj = 1 THEN PRINT AT 7, 2; "You feel a cold draft...": LET clue = 1
 470 IF clue = 0 THEN PRINT AT 7, 2; "All quiet."
 480 INPUT "Direction (N/S/E/W): "; d$
 490 LET dest = 0
 500 IF d$ = "N" OR d$ = "n" THEN LET dest = n(rm)
 510 IF d$ = "S" OR d$ = "s" THEN LET dest = s(rm)
 520 IF d$ = "E" OR d$ = "e" THEN LET dest = e(rm)
 530 IF d$ = "W" OR d$ = "w" THEN LET dest = w(rm)
 540 IF dest = 0 THEN PRINT AT 12, 2; "You can't go that way!": PAUSE 30: GO TO 270
 550 LET rm = dest
 570 IF rm = pit THEN GO TO 800
 730 GO TO 270
 740 REM --- Is chk adjacent? ---
 750 LET adj = 0
 760 IF n(rm) = chk OR s(rm) = chk OR e(rm) = chk OR w(rm) = chk THEN LET adj = 1
 770 RETURN
 800 CLS: LET a$ = "*** THE CAVERNS ***": LET y = 6: GO SUB 9000
 810 PRINT AT 9, 4; INK 2; "You fell into the pit!"
 820 BEEP 0.5, -15: PAUSE 0: STOP
1000 REM --- Room map: N,S,E,W ---
1010 DATA 0,5,2,0
1020 DATA 0,0,3,1
1030 DATA 0,7,4,2
1040 DATA 0,8,0,3
1050 DATA 1,0,6,0
1060 DATA 0,10,7,5
1070 DATA 3,11,0,6
1080 DATA 4,12,0,0
1090 DATA 0,13,10,0
1100 DATA 6,0,11,9
1110 DATA 7,15,12,10
1120 DATA 8,0,0,11
1130 DATA 9,17,14,0
1140 DATA 0,18,0,13
1150 DATA 11,19,16,0
1160 DATA 0,20,0,15
1170 DATA 13,0,18,0
1180 DATA 14,0,19,17
1190 DATA 15,0,20,18
1200 DATA 16,0,0,19

9000 PRINT AT y, (32 - LEN a$) / 2; BRIGHT 1; a$
9010 RETURN
ZX Spectrum The Caverns: a room display with the warning 'You feel a cold draft...' and a Pit debug readout
A cold draft warns the pit is one room away — sensed through the graph, never seen. (The Pit readout is a build-time aid.)

Adjacency as a subroutine

Line 170 hides the pit: LET pit = INT(RND * 19) + 2 — a random room from 2 to 20, never room 1 where you start. The clue depends on one question: is the pit next door? Lines 740–770 answer it as a GO SUB — given a room number in chk, set adj = 1 if any of the current room's four exits leads to it: IF n(rm) = chk OR s(rm) = chk OR e(rm) = chk OR w(rm) = chk. Walking a room's four links to test for a neighbour is the graph version of Sonar's grid sweep, and writing it once as a subroutine matters because the creature and the treasures will all ask the same question.

Sensing, not seeing

Line 380 sets chk = pit and calls the check; line 390 prints You feel a cold draft... when the pit is adjacent. The player never sees the pit's room number — only the draft. And line 570 makes it real: IF rm = pit THEN GO TO 800 — walk into the pit's room and you fall. So the draft is the one warning you get, and the game becomes a chain of careful deductions: a draft to the south means the pit is one of the rooms south leads toward, so go another way. While you build, line 360 prints the pit's room so you can check the clue fires correctly; the finished game removes it.

Next: a second danger, and this one moves.