
A text adventure is almost nothing but text. The player types a sentence; the program has to read it, break it into words, work out what they mean, and answer with a paragraph or two of prose. Then it does it again, a few hundred times, on a machine where Turbo's menu shows about 26K free for your program, its data and everything it has to say.
The Turbo Pascal course taught you the language. This primer takes one subject, text, and goes deep. Every job a text adventure does with words is done here two or three different ways, side by side, and timed on the Einstein, so you can see what each one costs. And then we open up three real adventures that ran on this machine and see how their authors did the same jobs.
What you will build is BEACON, a small adventure of the kind people typed in and played in 1984.
A storm. Your boat has gone down off a little island and you have dragged yourself up the beach. Out in the dark a ship is running for the rocks, and the lighthouse on the cliff above you is dark. The keeper is nowhere to be found. Somehow, you have to light the great lamp before the ship strikes.
There are twelve places to explore, six things to find and carry, and four puzzles between you and the lamp. You type what you want to do in plain words:
> OPEN THE DOOR WITH THE CROWBAR
You lever the door open with the
crowbar. The nails shriek and give.
The finished game is on the disc. At the 0: prompt, type BEACON:

Press a key, and you are on the beach. QUIT ends the game. Have a look round now if you like; by the end of the primer you will have written every line of it.
The game's words are not in its program. The room descriptions and everything else BEACON says live in two files on the disc, and the game reads only what it needs, when it needs it. That is one of the techniques this primer builds up to, and you will not have to type a word of the game's prose: the disc carries it.
The primer is in three parts.
Part one, words in. Reading what the player types: with Readln, and with a line editor of your own built from single key presses. Tidying it, splitting it into words three different ways, recognising the words, and turning them into numbers so the rest of the program never compares a string again. You will find, for instance, that the obvious way of splitting a sentence into words is the slow one, and that looking a word up in a sorted list takes seven comparisons where reading straight down it takes 121.
Part two, words out. Storing a great deal of text: in the program, in a text file, in a file of records you can jump about in, and squeezed, three letters to every two bytes, or with common words replaced by single codes. Each way is measured: how much memory it leaves you, how much disc it takes, and how long the player waits.
Part three, BEACON. The game, built a piece at a time from the best of what parts one and two found.
Three adventures from the TatungBytes library come up again and again, and everything the primer says about them comes from their own discs, read byte by byte, and from playing them.
Zork (in three parts) and The Hitchhiker's Guide to the Galaxy came from Infocom, and on the Einstein the four of them share one program: the four .COM files on their discs are the same, except for the name of the data file each one opens. Zork I's story alone is 84,876 bytes, and the program reads it from the disc as you play. Their text is packed three letters to every two bytes, and 96 common words and phrases are stored once and called up by number. Their dictionaries hold every word the game knows, but only its first six letters, which is why Zork will happily take MAILBOXXYZ for a mailbox.
Alice and the March Hare, by SYNTAXSOFT in 1986, did things almost the opposite way: plain text, a word list of whole words, and a one-byte number beside each word, the same number for words that mean the same thing.
You will build a small version of each technique in Pascal, and see what it costs.
The Turbo Pascal course, or the same ground: the menu and the editor, types, records, files, procedures and functions. The primer does not teach the language again. Where it leans on something the Turbo course covered, it says which section.
You also need the primer's own disc, which S2 sets up.
BEACON is a twelve-room adventure that reads its world from the disc. On the way to it, you will try every job a text adventure does with words in more than one way, measure each, and see how Zork, The Hitchhiker's Guide to the Galaxy and Alice and the March Hare did the same.
S2, Setting Up: the disc, and a first look at what is on it.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.