
Part three is the game. Each section from here adds a piece to DRIFT, and at the end of each one you save the game so far, ADV1, ADV2 and on, and load it again at the start of the next.
A text adventure starts with a map: which rooms there are, and which way you can go from each. DRIFT has four.
BRIDGE
|
CRYO BAY -- CORRIDOR -- ENGINEERING
Each room has a number - the cryo bay is 1, the corridor 2, engineering 3, the bridge 4 - and each direction has a number too: north 1, east 2, south 3, west 4. Then the whole map fits in a two-dimensional array, E%(room,direction): the room you reach by going that way, or 0 if you cannot.
E%(2,1) is 4, because north from the corridor is the bridge. E%(1,1) is 0: there is no way north from the cryo bay.
The map is written as DATA, one line per room: its name, then its exits north, east, south and west.
3010 DATA CORRIDOR,4,3,0,1
reads "the corridor: north to 4, east to 3, no way south, west to 1".
DRIFT is going to grow to about two hundred lines, so it is laid out in blocks from the start, with room between:
| Lines | What |
|---|---|
| 10-130 | the main program - a handful of lines that call everything else |
| 1000 up | procedures: setting up, looking, moving, carrying |
| 2000 up | the tools: wrapping text, making capitals, finding words |
| 3000 up | the DATA - the map, and later the descriptions, objects and words |
Every procedure is defined after the END in line 130, as S17 said they must be.
This is the first stage. Type it all:
10 REM DRIFT - A TEXT ADVENTURE
20 MODE 0:PROCSETUP
40 PROCLOOK
130 END
1000 DEF PROCSETUP
1010 DIM ROOM$(4),E%(4,4),DIR$(4)
1020 RESTORE 3000:FOR R%=1 TO 4:READ ROOM$(R%),E%(R%,1),E%(R%,2),E%(R%,3),E%(R%,4):NEXT
1025 FOR R%=1 TO 4:READ DIR$(R%):NEXT
1060 R%=1
1090 ENDPROC
1100 DEF PROCLOOK
1110 COLOUR 11:PRINT ROOM$(R%):COLOUR 15
1130 PROCEXITS
1150 ENDPROC
1200 DEF PROCEXITS
1210 LOCAL D%,X$
1220 FOR D%=1 TO 4
1230 IF E%(R%,D%) THEN X$=X$+" "+DIR$(D%)
1240 NEXT
1250 PRINT "EXITS:";X$
1260 ENDPROC
3000 DATA CRYO BAY,0,2,0,0
3010 DATA CORRIDOR,4,3,0,1
3020 DATA ENGINEERING,0,0,0,2
3030 DATA BRIDGE,0,0,2,0
3040 DATA NORTH,EAST,SOUTH,WEST
PROCSETUP makes the arrays and reads the map into them. RESTORE 3000 makes sure the reading starts at the map, whatever else is added later. The arrays are made inside a procedure, but they belong to the whole program.R% is the room you are in. You start in room 1.PROCLOOK shows where you are: the room's name in yellow, then its exits.PROCEXITS goes through the four directions and adds each one that leads somewhere to a string, X$. IF E%(R%,D%) THEN is true whenever the exit is not 0. X$ is LOCAL, so it starts empty each time.Starting from
A fresh boot, or NEW. When it runs, SAVE "ADV1".
What you should see
CRYO BAY
EXITS: EAST
>
CRYO BAY in light yellow. The screen was cleared by MODE 0 first.

R%=2, and run it. Then R%=4. Does each room show the exits the map says it should?R%=1 back and change line 3000 to DATA CRYO BAY,0,2,0,2. What does the cryo bay say now - and where would going west take you?PRINT ROOM$(E%(2,1)) at the >. Which room is that, and why?20.1 Add a line 50 that shows all four rooms and their exits, one after another, using a loop and PROCLOOK.
20.2 After the program has run, print BRIDGE IS NORTH OF THE CORRIDOR, working both room names out from the arrays.
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
Out of DATA in line 1020 or 1025 | A DATA line is missing a number, or has a comma too few. Each room needs a name and four exits. |
| A room shows the wrong exits | Its four numbers are in the wrong order: north, east, south, west. |
No PROC | Line 130's END is missing, and the program ran into the definitions. |
The map is four rooms in DATA: names, and for each direction the number of the room it leads to. PROCSETUP reads it into arrays; PROCLOOK shows the room you are in. Save it as ADV1.
S21, Moving - typing a direction, and going there.