Coding a text adventure game

So, how hard would it be to code a text adventure?

I have minimal programming skills (some very elementary basic from waaaaay back, and one CS class in C a few years ago).

I imagine that on the broad spectrum of programming this might not be too daunting a task.

I’m thinking of making this my free-time project for a while, so I don’t mind a bit of work and learning, I’m just curious as to how much learning it’s going to take to pull this off effectively.

It would be very easy – there are lots of authoring systems out there to help you build one. Here’s a good place to start: http://www-2.cs.cmu.edu/afs/cs.cmu.edu/user/wsr/Web/IF/homepage.html

If you want to do it all by yourself, though, then it seems to me that it’s mainly a question of how difficult you want to make it. Writing an intelligent parser that can understand the difference between the verb ring and the noun ring is probably somewhat difficult. Writing a parser that functions like an old LucasArts adventure game, with a set amount of verbs that can be applied to one noun (or possibly two) at a time is probably much less challenging. Writing NPCs that move from location to location and go about their own agendas in a seemingly intelligent manner is more difficult than writing NPCs that stay in one place and only respond to the actions of the player. And so on.

Never got around to getting started in TADS, but it seems to be one of the most widely used authoring systems. In the developer FAQ listed in the link above you can read some more about Glk which may be of interest to you as a C coder.

Very easy. I wrote one in Sinclair BASIC when I was about 8 or 9 needless to say it was shite, but it is probably the most easy form of game to make esp. using a basic programming language.

I used to have enormous amounts of fun doing this. I’ve done it in a couple forms of BASIC, Pascal, and C. They’re just plain fun.

One I did on an Apple IIe in its BASIC, and I eventually hit an upper memory limit cause I had so much text description for all of the rooms and objects. The actual space used up by the game logic and various bits of state information (which room you’re in, what objects you’re holding) and the ‘map’ were miniscule in comparison. Fortunately I managed to trim the text back enough to submit it for my grade 10 project.

Granted, I love this stuff (programming) and now do it for a living, so you’ll have to take my opinion with a grain of salt, but it’s not that hard to do.

There are really good ways to do it, and really bad ways to do it, though, to allow you to easily add more ‘things’ and ‘places’ and improve the game’s ‘intelligence’. As an example, you shouldn’t write it so that different parts of your program represent being in different rooms or things.

You should try to write it so that what room you’re in or what things you’re holding are simply ‘state’ information or ‘variables’ containing that information. This enables your program to be more flexible, but at the same time simpler.



repeat
   get user sentence
   understand player sentence
   apply player sentence to 'update' the player state and world
end repeat


This way, the ‘update’ operations as a result of player action can either be very general (move from room to room, pick up or drop an object) or very specific (throw the machine switch).

Depending on what language you choose, you probably want to understand structures or their equivalent. You almost certainly want to learn about arrays. Because of the sentences and processing them, you probably want to learn how to work with strings as well.

As always, KISS (Keep It Simple, Silly). Even a game that just allows < verb > < noun > can work pretty well.

Starting place: Choose the language you’ll use.

Second the recommendation for TADS. It’s a pretty straightforward object-oriented language, and easy to work with. That is, if you’re making an easy adventure. It can be as complicated as you want to make it.

The other advantage is that it’s a popular language, so you can get lots of source code for other games to see how they’re done.

One disadvantage is that, in making it easy for you, it cuts off some flexibility. I once toyed with an adventure on a boat, and I tried to replace the compass directions — north, south, east, west — with nautical directions — fore, aft, starboard, port. I beat my head against it for days before I gave up. Maybe there’s a way to make it work, but I couldn’t figure it out.

But for what most people use it for, TADS is great.

If you don’t want to go with TADS, there is also Inform, which is very close to what was used for the old Infocom games.

If you want to see a nice example of a text adventure game (i.e. a MUD), telnet to mud.lordtrox.com: 8500

Activision recently released the old Infocom Zork text games into the public domain. You can play them in Windows using the WinFrotz interpreter. Here are links to Frotz, Inform (mentioned earlier) and other game interpreters here. Several programs include source code and game design tips.

If you want a good overview of the systems available for writing adventure/interactive fiction games, check out Cloak of Darkness which gives an overview of about a dozen systems along with a small sample game written in each system.