10 REM >CASTLE40
20 REM ESCAPE FROM THE CASTLE - a text adventure
30 REM for the BBC Microcomputer Model B
40 REM 40 room edition
50 MODE 7
60 PROCsetup
70 PROCtitle
80 REPEAT
90 PROCturn
100 UNTIL FINISHED%=1
110 PRINT
120 PRINT "Thanks for playing!"
130 END
200 DEF PROCsetup
210 DIM RM$(40),EXN(40),EXS(40),EXE(40),EXW(40)
220 DIM OBJ$(5),OBJLOC(5)
230 FOR I%=1 TO 40
240 READ RM$(I%)
250 NEXT I%
260 FOR I%=1 TO 40
270 READ EXN(I%),EXS(I%),EXE(I%),EXW(I%)
280 NEXT I%
290 FOR I%=1 TO 5
300 READ OBJ$(I%),OBJLOC(I%)
310 NEXT I%
320 ROOM%=40
330 DOORLOCKED%=1
340 FINISHED%=0
350 MOV%=0
360 ENDPROC
400 DEF PROCtitle
410 CLS
420 PRINT "*** ESCAPE FROM THE CASTLE ***"
430 PRINT
440 PRINT "You have been thrown into the dungeons"
442 PRINT "of a great castle."
450 PRINT
460 PRINT "Find the Royal Seal and reach the main"
462 PRINT "gate to prove who you are and win your"
464 PRINT "freedom."
470 PRINT
480 PRINT "Type HELP at any time for a list of"
482 PRINT "commands."
490 PRINT
500 ENDPROC
600 DEF PROCturn
610 PROClook
620 REPEAT
630 INPUT "> "A$
640 UNTIL A$<>""
650 SP%=INSTR(A$," ")
660 IF SP%=0 THEN VERB$=A$ ELSE VERB$=LEFT$(A$,SP%-1)
670 IF SP%=0 THEN NOUN$="" ELSE NOUN$=MID$(A$,SP%+1,LEN(A$)-SP%)
680 PROCupper(VERB$)
690 PROCupper(NOUN$)
700 IF VERB$="N" OR VERB$="NORTH" THEN PROCmove("N"):ENDPROC
705 IF VERB$="S" OR VERB$="SOUTH" THEN PROCmove("S"):ENDPROC
710 IF VERB$="E" OR VERB$="EAST" THEN PROCmove("E"):ENDPROC
715 IF VERB$="W" OR VERB$="WEST" THEN PROCmove("W"):ENDPROC
720 IF VERB$="LOOK" OR VERB$="L" THEN ENDPROC
725 IF VERB$="GET" OR VERB$="TAKE" THEN PROCget(NOUN$):ENDPROC
730 IF VERB$="DROP" THEN PROCdrop(NOUN$):ENDPROC
735 IF VERB$="INV" OR VERB$="INVENTORY" OR VERB$="I" THEN PROCinv:ENDPROC
740 IF VERB$="HELP" OR VERB$="?" THEN PROChelp:ENDPROC
742 IF VERB$="OUT" THEN PROCtryexit:ENDPROC
744 IF VERB$="QUIT" THEN PRINT "You abandon your escape and resign":PRINT "yourself to the dungeon.":FINISHED%=1:ENDPROC
746 PRINT "I don't understand that."
748 PRINT "Type HELP for a list of commands."
750 ENDPROC
800 DEF PROCmove(D$)
805 LOCAL T%
810 IF D$="N" THEN T%=EXN(ROOM%)
815 IF D$="S" THEN T%=EXS(ROOM%)
820 IF D$="E" THEN T%=EXE(ROOM%)
825 IF D$="W" THEN T%=EXW(ROOM%)
830 IF T%=0 THEN PRINT "You can't go that way.":ENDPROC
835 IF T%=1 AND DOORLOCKED%=1 THEN PROCtrygate:ENDPROC
840 IF T%>=36 AND OBJLOC(2)<>0 THEN PRINT "It's pitch dark that way - you need a":PRINT "light source.":ENDPROC
845 ROOM%=T%
850 MOV%=MOV%+1
855 ENDPROC
900 DEF PROCtrygate
905 IF OBJLOC(1)<>0 THEN PRINT "The portcullis is jammed fast. Perhaps":PRINT "a key would help.":ENDPROC
910 PRINT "You turn the rusty key in the lock and"
912 PRINT "the portcullis grinds upward."
915 DOORLOCKED%=0
920 ROOM%=1
925 MOV%=MOV%+1
930 ENDPROC
1000 DEF PROClook
1010 PRINT
1020 PROCprintwrapped(RM$(ROOM%))
1030 PROClistobjects
1040 ENDPROC
1050 DEF PROClistobjects
1060 LOCAL I%,N%
1070 N%=0
1080 FOR I%=1 TO 5
1090 IF OBJLOC(I%)=ROOM% THEN N%=N%+1
1100 NEXT I%
1110 IF N%=0 THEN ENDPROC
1120 PRINT "You can see: ";
1130 FOR I%=1 TO 5
1140 IF OBJLOC(I%)=ROOM% THEN PRINT OBJ$(I%);" ";
1150 NEXT I%
1160 PRINT
1170 ENDPROC
1200 DEF PROCget(N$)
1210 LOCAL I%,F%
1220 IF N$="" THEN PRINT "Get what?":ENDPROC
1230 F%=0
1240 FOR I%=1 TO 5
1250 IF OBJ$(I%)=N$ AND OBJLOC(I%)=ROOM% THEN F%=I%
1260 NEXT I%
1270 IF F%=0 THEN PRINT "I don't see that here.":ENDPROC
1280 IF FNcarried>=4 THEN PRINT "You are carrying as much as you can":PRINT "manage.":ENDPROC
1290 OBJLOC(F%)=0
1300 PRINT "You pick up the ";OBJ$(F%);"."
1310 ENDPROC
1400 DEF FNcarried
1410 LOCAL I%,C%
1420 C%=0
1430 FOR I%=1 TO 5
1440 IF OBJLOC(I%)=0 THEN C%=C%+1
1450 NEXT I%
1460 =C%
1500 DEF PROCdrop(N$)
1510 LOCAL I%,F%
1520 IF N$="" THEN PRINT "Drop what?":ENDPROC
1530 F%=0
1540 FOR I%=1 TO 5
1550 IF OBJ$(I%)=N$ AND OBJLOC(I%)=0 THEN F%=I%
1560 NEXT I%
1570 IF F%=0 THEN PRINT "You are not carrying that.":ENDPROC
1580 OBJLOC(F%)=ROOM%
1590 PRINT "You drop the ";OBJ$(F%);"."
1600 ENDPROC
1700 DEF PROCinv
1710 LOCAL I%,N%
1720 N%=0
1730 PRINT "You are carrying: ";
1740 FOR I%=1 TO 5
1750 IF OBJLOC(I%)=0 THEN PRINT OBJ$(I%);" ";:N%=N%+1
1760 NEXT I%
1770 IF N%=0 THEN PRINT "nothing";
1780 PRINT
1790 ENDPROC
1800 DEF PROChelp
1810 PRINT "Commands understood:"
1820 PRINT "N S E W     - move that direction"
1822 PRINT "LOOK        - look around again"
1824 PRINT "GET <item>  - pick up an item"
1826 PRINT "DROP <item> - put down an item"
1828 PRINT "INV         - list what you carry"
1830 PRINT "OUT         - leave through the gate"
1832 PRINT "QUIT        - give up, end the game"
1840 ENDPROC
1900 DEF PROCtryexit
1910 IF ROOM%<>1 THEN PRINT "You are not at the main gate.":ENDPROC
1920 IF OBJLOC(3)<>0 THEN PRINT "The guard blocks your path. Without the":PRINT "Royal Seal he will not let you pass.":ENDPROC
1930 PRINT
1940 PRINT "You show the guard the Royal Seal and"
1942 PRINT "he waves you through the gate!"
1944 PRINT "*** YOU HAVE ESCAPED! ***"
1946 PRINT "You made your escape in ";MOV%;" moves."
1950 FINISHED%=1
1960 ENDPROC
2000 DEF PROCupper(S$)
2010 LOCAL I%,C%,B$
2020 B$=""
2030 FOR I%=1 TO LEN(S$)
2040 C%=ASC(MID$(S$,I%,1))
2050 IF C%>=97 AND C%<=122 THEN C%=C%-32
2060 B$=B$+CHR$(C%)
2070 NEXT I%
2080 S$=B$
2090 ENDPROC
2100 DEF PROCprintwrapped(S$)
2110 LOCAL P%,SEG$
2120 REPEAT
2130 P%=INSTR(S$,"|")
2140 IF P%=0 THEN PRINT S$:S$="" ELSE SEG$=LEFT$(S$,P%-1):PRINT SEG$:S$=MID$(S$,P%+1)
2150 UNTIL S$=""
2160 ENDPROC
9000 DATA "You are in the gatehouse. The great|castle doors are barred, but a way out|beckons if you can prove who you are."
9010 DATA "A narrow guard post overlooks the|courtyard. A rusted portcullis blocks|the passage west."
9020 DATA "You are in a small watch room, arrow|slits letting in thin light."
9030 DATA "Racks of old weapons line this cramped|armoury."
9040 DATA "A stone stairwell winds upward from|this landing."
9050 DATA "You are in a smoky castle kitchen,|pots hanging from the rafters."
9060 DATA "A cramped pantry, its shelves mostly|bare."
9070 DATA "The scullery is damp and smells of old|dishwater."
9080 DATA "You are in the great dining hall, long|tables stretching into shadow."
9090 DATA "A cluttered buttery, barrels stacked|against the walls."
9100 DATA "A small chapel, candles guttering in|the draft."
9110 DATA "You are in a quiet stone cloister, a|rusty dagger stuck in a crack in the|wall."
9120 DATA "Dusty shelves line this abandoned|library."
9130 DATA "A cluttered study, papers scattered|across an old desk."
9140 DATA "A comfortable solar, its tapestries|faded with age."
9150 DATA "You are in a bare guardroom, a table|scattered with papers."
9160 DATA "Rows of bunks fill this cramped|barracks."
9170 DATA "An armoury store, crates of arrows|stacked to the ceiling."
9180 DATA "A room lined with empty weapon racks."
9190 DATA "You are at the base of a watch tower,|a heavy key ring hanging on a hook."
9200 DATA "You are in the castle treasury, an|ornate royal seal resting on a velvet|cushion."
9210 DATA "A counting room, ledgers piled on a|long table."
9220 DATA "A narrow antechamber before a heavy|vault door."
9230 DATA "You are in the strongroom, its shelves|long since emptied."
9240 DATA "A small coin store, dust thick on the|floor."
9250 DATA "A spiral stairwell twists up into the|dark."
9260 DATA "You are on a windswept tower landing."
9270 DATA "A narrow battlement walk, wind howling|through the gaps in the stone."
9280 DATA "A cramped lookout room with a view of|the courtyard below."
9290 DATA "You are in a storage nook. A coil of|old rope hangs from a peg."
9300 DATA "A dank passage, water trickling down|the walls."
9310 DATA "You are in a cold guard cell block,|iron bars lining the corridor."
9320 DATA "A narrow cell corridor, echoing with|distant drips."
9330 DATA "A rat-infested tunnel twists ahead of|you."
9340 DATA "You stand before a heavy, iron-bound|door."
9350 DATA "Your lantern lights a bare stone|passage, chains hanging from the|walls."
9360 DATA "An adjoining cell, empty save for a|pile of old straw."
9370 DATA "A cramped dungeon passage, the air|thick and stale."
9380 DATA "A flooded cell, water pooling around|your ankles."
9390 DATA "You are locked in a cold dungeon cell.|A guttering torch on the wall gives|just enough light to see by."
9400 DATA 0,6,2,0
9410 DATA 0,7,3,1
9420 DATA 0,8,4,2
9430 DATA 0,9,5,3
9440 DATA 0,10,0,4
9450 DATA 1,11,7,0
9460 DATA 2,12,8,6
9470 DATA 3,13,9,7
9480 DATA 4,14,10,8
9490 DATA 5,15,0,9
9500 DATA 6,16,12,0
9510 DATA 7,17,13,11
9520 DATA 8,18,14,12
9530 DATA 9,19,15,13
9540 DATA 10,20,0,14
9550 DATA 11,21,17,0
9560 DATA 12,22,18,16
9570 DATA 13,23,19,17
9580 DATA 14,24,20,18
9590 DATA 15,25,0,19
9600 DATA 16,26,22,0
9610 DATA 17,27,23,21
9620 DATA 18,28,24,22
9630 DATA 19,29,25,23
9640 DATA 20,30,0,24
9650 DATA 21,31,27,0
9660 DATA 22,32,28,26
9670 DATA 23,33,29,27
9680 DATA 24,34,30,28
9690 DATA 25,35,0,29
9700 DATA 26,36,32,0
9710 DATA 27,37,33,31
9720 DATA 28,38,34,32
9730 DATA 29,39,35,33
9740 DATA 30,40,0,34
9750 DATA 31,0,37,0
9760 DATA 32,0,38,36
9770 DATA 33,0,39,37
9780 DATA 34,0,40,38
9790 DATA 35,0,0,39
9800 DATA "KEY",20
9810 DATA "LANTERN",40
9820 DATA "SEAL",21
9830 DATA "ROPE",30
9840 DATA "DAGGER",12
