Stupid Python Trick #6: Interactive Fiction

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.

Stupid Python Trick #6: Interactive Fiction

Postby ichabod801 » Sat Mar 23, 2013 7:20 pm

I have put together a few classes and a cmd.Cmd instance that works as a basic engine for interactive fiction/text adventures. The code is available on my Xenomind website as usual. The zip file that link goes to contains the p_machine package with the engine and elevator.py, a short sample adventure made with that engine.

Let me be clear about what this is and is not meant to be. This is not meant to be a full featured interactive fiction engine. It needs a lot of work before it can be anything like that: it's own interface, a broader and more flexible lexicon, a simple and embedded way to deal with doors, vehicles, group objects, at least a way to plug in a combat system, and who knows what else. Maybe I'll get around to writing something like that, but not today.

What this is meant to be is an answer to a common question. We are often asked "What's the problem with my text adventure?", and the answer is buried somewhere in a morass of 200 nested if statements. The usual answer is "learn classes." While that answer is correct, it's a bit short on details. We now have three brief tutorials on classes, and by the end of the week I hope to have a explanation here of how I wrote this program. Then we can give the more detailed answer of "read these tutorials on classes and the description of this program." So this is just meant to be a basic interactive fiction engine that a bright beginner could wrap their head around.
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC
ichabod801
 
Posts: 84
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Return to Completed Scripts

Who is online

Users browsing this forum: W3C [Linkcheck] and 1 guest