Text Game Update

I really think I've got it! I've solved the problems that I faced earlier, neatly outlined by this webpage.

Here's the first problem I faced:

"Another fun case: some checks apply to multiple actions. An electrified lever zaps you if you pull, push, or even touch it. We don't want to copy that check into every touching method. Maybe we could have "pull" and "push" be subclasses of a base "touch" class... except, hang on, that makes no sense. OO has no notion of methods subclassing other methods."

At first, I tried to tackle it head-on by challenging the assumption that "OO has no notion of methods subclassing other methods". In Python, objects can subclass other objects, and those objects might just happen to be callable. It'd certainly be possible, but it'd be a lot of effort for very little reward.

A more practical idea, I found, was to maintain a dictionary of callbacks and their 'hooks', or triggers, and expose a change_behaviour interface for anything subclassing from Object (note the capital). If multiple hooks are needed (as in the example above), the user can use a simple loop:

def shock_player(self, player=None, location=None):  
    output("ZAP!!! You're thrown across the {}.".format(
        location.type))
       player.alter_health(-10)

lever = Object("electrified lever")  
for hook in (TOUCHED, PULLED, PUSHED):  
    lever.change_behaviour(hook, shock_player)

The main point that keeps limiting the examples in the webpage above is the parser - designed only to "spit out" a verb-noun tuple. This makes it harder than necessary to implement certain features like checking inventory and moving things from one place to another.

To get around this, I'll have a kind of meta-parser:

try:  
    verb, noun = vn_parse(user_text)
except ValueError:  
    pass
else:  
    return lambda: noun.verb()

try:  
    callable = call_parse(user_text)
except ValueError:  
    pass
else:  
    return callable
...

One other thing - I'm not a big fan of the "Interactive Fiction" label, since what I'm really trying to build is a system for any natural language text-based game. So from now on I'll probably prefer the Text Game label.