Next


This series of nodes describes how those interactive fiction, adventure games like Zork and the original Colossal Cave adventure game work. I chose C as the programming language for all the examples because it seems to be the most widely used, and the most likely to still be around in 20 years.

The first time I encountered a text adventure game was not on a computer at all. It was in a book called The Soul of a New Machine, by Tracy Kidder, a book about the engineers at Data General who were working to build the Eagle, a computer meant to compete with DEC's VAX.

The book contained a description of the original Colossal Cave adventure by Crowther and Woods, and gave tantalizing little excerpts of the program's output. This output amazed me at the time. I would read these little excerpts over and over wondering if it was genuine. I didn't know too much about computers then, and I strained my brain wondering how it was possible for the computer to seemingly understand input in English, and generate meaningful responses, seemingly understanding what it was directed to do. I wondered if this program were for real, or if the author had taken some artistic license to make it seem better than it really was. I soon found out that it was for real though, and this fact got me going.

I immediately set out to build one of these games myself, but I was very naive. I began with a section of BASIC code dedicated to describing each "room" in the game, and a series of gotos and gosubs depending on the player's typed input in each of these "rooms". This was a very very wrong way to go about it as I soon discovered.

I looked around in various books, and could find nothing that even began to tell how such a game worked. Eventually, I found an advertisement in (the now defunct) Compute! magazine for a little pamphlet describing how such games were made, and included a BASIC program for an example game. So I sent away for it. The name of the sample game was, appropriately enough, Deathship. It was some of the most horrible code I have ever seen. It performed as advertised, but it was made to run on a machine with 16k RAM, and it squeezed out every byte possible. Spaces in the source were dispensed with, an unnecessary luxury, no spaces. The names of verbs and nouns were significant only to the first two characters..., and the longer version of these words were contained nowhere in the program. I never did figure out what some of those words were supposed to be. Anyway, as bad as it was, it did teach me the concepts behind adventure games well enough that I could write my own code.

What I needed, it turned out, was the concept of arrays. Clever use of arrays is what makes these games tick, and Deathship was my bewildering and fascinating introduction to them.

But, I'm getting ahead of myself.

Eventually, I did manage to write a passable adventure game in Turbo Pascal with a parser that could do everything that the Infocom parser in Zork could do, plus a bunch more stuff. (I really need to resurrect that computer and save that code.)

But this node is not about building a sophisticated parser like that. This node is about the basics, and will describe just enough to get you started. Enough to get you started that is, if you're goal is to write such a game from scratch in C, or to learn about C while having a fun programming project to tinker with. If your goal is to write a serious adventure game, you'd probably be better off starting in a different place, standing on the shoulders of giants, using any of the many adventure writing toolkits out there, such as TADS, to name one.

So, If this sounds like your kind of thing, keep reading.

Next

Log in or registerto write something here or to contact authors.