#!/usr/bin/env python import cgi import cgitb import os import sys import random import game def getToken( form ): keys = form.keys() if 2 != len( keys ): return [] if 'token' in form.keys(): return form['token'].value return None def getCommand( form ): keys = form.keys() if 2 != len( keys ): return None if 'token' == keys[0]: return form[keys[1]].name else: return form[keys[0]].name def emitInteraction( i ): return '' % (i.title(), i.command()) def drawMap( map ): ## ## assume -8 to 8 in x and y ## # print '
| %s | ' % token.ascii( None ), # print '
'
count = 1
for line in map:
for token in line:
if count == 145:
print '@',
else:
print token.ascii( None ),
count = count + 1
print
def emitMessages():
pass
def getCardinal( l, c ):
for x in l:
if c == x.title():
return emitInteraction( x )
return '' % (c,c)
def createForm( g ):
print ''
cgitb.enable()
print 'Content-Type: text/html\n'
form = cgi.FieldStorage()
token = getToken( form )
command = getCommand( form )
g = game.gameClass()
if not token:
## start a new game
token = g.newGame()
g.load( token )
if command:
g.player().interact( command )
loc = g.player().location()
zone = g.map().getFill( loc[0], loc[1], loc[2] ).zone( None )
title = g.map().getFill( loc[0], loc[1], loc[2] ).title( None )
if zone and title:
print '