nickm.com > classes > cms workshop i, fall 2007

The Video Game I

12 September 2007

Escaper: A Minimal Video Game in Python

This exercise is done in pairs.

Reading the Code

Download escaper.py to the desktop. Open it in a text editor (TextEdit or Text Wrangler will do nicely) and take a look at it.

Read through each line. What does each statement do? The helpful comments can contribute to your understanding of the program. Your experience with a Python "terminal saver" should help as well, although this program uses a different way of putting text in the terminal window. Formulate a theory about what this program does. What will appear in the terminal window when you run it? What can you do to interact with the program? When will it terminate?

Running the Code

Open a Terminal window and type "cd Desktop" to get there, and then type "python escaper.py" to run it. Play the game and see if you are right about how it works. If you are, do the Snoopy dance to signal your triumph. If you aren't, read through the code again and see how it works.

Modifying the Code

Perhaps you don't know a lot of Python, or even any extra Python beyond what you've seen here, and you don't see how to make this program more complex. You should at least be able to make it simpler. Change the program to make a one-dimensional version of the game — one that uses a line rather than a plane as its playing field.

Interactive Fiction

This exercise is done in pairs, too, but different pairs. For this one, you will need an Inform 6 compiler, which unfortunately does not come standard with OS X. Download the Inform 6 compiler for Mac OS X onto the desktop and double click to uncompress it. You can rename the file something like "inform" to make it easy to type. Then, from the terminal window, once you have typed "cd Desktop" to make the desktop the current directory, you can type "./inform" to make sure it works.

You also will need an interpreter, which will let you play the compiled file. There are two good ones for Mac OS X: Zoom and Spatterlight. Both are nice; Zoom has some extra features while Spatterlight allows you to also play interactive fiction in other formats — games that are not Inform/z-code. Pick one, download, and install it.

Finally, you also need the Inform library. Download it and uncompress it.

With that out of the way, you can download two starter kits for Inform to the desktop and double-click this file to uncompress it. In the "kits" folder you will find documentation and two folders with starter games. First, open the starter2 folder and read the three files in it, starting with starter2.inf. What does each line of each file do?

Compile the game, run it, play it, and see if you are right about how it works.

Then, do the same with starter1.

Finally, pick one of the two starter games and modify it into your own, original interactive fiction. You can design a small IF work beforehand if you like, or you can start twiddling with the code and create something in a more "bottom-up" manner.

You can look through the Inform Designer's Manual for more information about the language. It is the canoncial reference, by the creator of Inform, Graham Nelson. Also, check out Roger Firth's IF resources, particularly "Inform in four minutes" (a zipped PDF file.) You can use this as a reference card while you work on your in-class exercise.