#!/usr/bin/python ## ## Simple web game by William D. Colburn ## http://infohost.nmt.edu/~schlake/ ## 505 480 9406 ## schlake@nmt.edu ## import cgi import cgitb import os import sys import random def getField( field ): if form.has_key( field ): try: return int(form[field].value) except: return form[field].value return None cgitb.enable() print 'Content-Type: text/html\n' form = cgi.FieldStorage() cmd = getField( 'cmd' ) loc = getField( 'loc' ) from rooms import rooms def showRoom( loc ): print rooms[loc].description print '
' def getCommand( loc ): print """
""" % loc def parseCommand( loc, cmd ): dirs = { 'north':['n', 'north'], 'south': ['s', 'south'], 'east':['e', 'east'], 'west':['w', 'west'], 'up':['u', 'up'], 'down':['d','down'], 'northeast':['ne', 'northeast'], 'northwest':['nw', 'northwest'], 'southeast':['se', 'southeast'], 'southwest':['sw', 'southwest'], 'in':['enter', 'in'], 'out':['exit', 'out', 'o'] } cmd = cmd.lower() for dir in dirs: if cmd in dirs[dir]: if dir in rooms[loc].exits: print 'You go %s.' % dir return rooms[loc].exits[dir] else: print 'You cannot go %s from here.
' % dir return None for exit in rooms[loc].exits: if cmd == exit: print 'You go "%s".
' % cmd return rooms[loc].exits[cmd] print 'I did not understand "%s".
' % cmd return None if cmd == None or loc == None: loc = 'purgatory' elif cmd != None and loc != None: pass else: print 'Internal Error', cmd, loc sys.exit( 1 ) showRoom( loc ) if cmd: newloc = parseCommand(loc, cmd ) if newloc: loc = newloc showRoom( loc ) getCommand( loc ) """