[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] fenfire/org/fenfire/demo text-mm.py
From: |
Tuukka Hastrup |
Subject: |
[ff-cvs] fenfire/org/fenfire/demo text-mm.py |
Date: |
Tue, 26 Aug 2003 18:43:25 -0400 |
CVSROOT: /cvsroot/fenfire
Module name: fenfire
Branch:
Changes by: Tuukka Hastrup <address@hidden> 03/08/26 18:43:25
Modified files:
org/fenfire/demo: text-mm.py
Log message:
less flooding, added inspection commands
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/demo/text-mm.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: fenfire/org/fenfire/demo/text-mm.py
diff -u fenfire/org/fenfire/demo/text-mm.py:1.4
fenfire/org/fenfire/demo/text-mm.py:1.5
--- fenfire/org/fenfire/demo/text-mm.py:1.4 Tue Aug 26 16:44:22 2003
+++ fenfire/org/fenfire/demo/text-mm.py Tue Aug 26 18:43:25 2003
@@ -157,8 +157,59 @@
scene = MMScene()
+def tellFocus():
+ print "You are standing on: 0: "+scene.text(scene.focused)
+ print
+
+def tellNeighbours():
+ print "You can move to: "
+ list = scene.neighbours(scene.focused)
+ for i in range(len(list)): print "%d: %s" % (i+1, scene.text(list[i]))
+ print
+
+def tellComponents():
+ print "In the air around you:"
+ list = scene.components
+ for i in range(len(list)): print "%d: %s" % (-(i+1), scene.text(list[i]))
+ print
+
+def tellCommands():
+ keys = cmds.keys()
+ keys.sort()
+ print keys
+
+def look(arg=None, examineOnly=0):
+ if arg == None: arg = '' # they don't let me write arg == null || arg.strip
+ if arg.strip() == '':
+ tellFocus()
+ if not examineOnly:
+ tellNeighbours()
+ elif arg.strip() == 'around':
+ tellComponents()
+ else:
+ try:
+ i = int(arg)
+ if i>0:
+ print "%d: %s" % (i,
scene.text(scene.neighbours(scene.focused)[i-1]))
+ elif i<0:
+ print "%d: %s" % (i, scene.text(scene.components[-i-1]))
+ else:
+ tellFocus()
+ except ValueError:
+ print "I don't see "+arg
+
+def whereabouts():
+ tellComponents()
+ look()
+
+
cmds = {'quit': lambda x:quit(),
'save': lambda x:save(),
+ 'help': lambda x:tellCommands(),
+ 'examine': lambda str:look(str, examineOnly=1),
+ 'look': look,
+ 'lookat': look,
+ 'whereabouts': lambda x:whereabouts(),
'new': scene.newNode,
'add': scene.addNode,
'write': scene.editText,
@@ -168,41 +219,54 @@
'unlink': lambda
str:scene.unlink(scene.neighbours(scene.focused)[int(str)-1]),
}
+postsuccess = {'moveto': look,
+ 'changeto': whereabouts,
+ }
+
+print "*"*20
+print """Welcome
+You stand, and there is free space around you and under your feet.
+You might see some writing, and perhaps by writing and creating more and
+by linking pieces, you could make this mirror something you have on your mind.
+
+Just one more remark: remember to save every now and then.
+"""
+print
+whereabouts()
+tellCommands()
+
while 1:
print '*' * 5
- print "You are at: "+scene.text(scene.focused)
- print
- print "You can move to: "
- list = scene.neighbours(scene.focused)
- for i in range(len(list)): print "%d: %s" % (i+1, scene.text(list[i]))
- print
- print "In the air around you:"
- list = scene.components
- for i in range(len(list)): print "%d: %s" % (-(i+1), scene.text(list[i]))
- print
- print cmds.keys()
- print "What, or where to, shall we? ",
- line = stdin.readline().strip()
+ line = ''
+ while line == '':
+ print "What, or where to, shall we? ",
+ line = stdin.readline().lstrip()[:-1]
+ print # there's some odd space character output, this hides it
try:
i = int(line)
if i>0:
- scene.focus(scene.neighbours(scene.focused)[i-1])
+ line = "moveto "+line
elif i<0:
- scene.focus(scene.components[-i-1])
+ line = "changeto "+line
except ValueError:
- cmdend = line.find(' ')
- cmd, rest = None, None
- if cmdend == -1:
- cmd = line
- rest = None
- else:
- cmd = line[:cmdend]
- rest = line[cmdend:].strip()
- try:
- cmds[cmd](rest)
- except KeyError:
- print "I don't know how to "+cmd
- except:
- print_exc()
+ pass
+ cmdend = line.find(' ')
+ cmd, rest = None, None
+ if cmdend == -1:
+ cmd = line
+ rest = None
+ else:
+ cmd = line[:cmdend]
+ rest = line[cmdend:].strip()
+ try:
+ cmds[cmd](rest)
+ except KeyError:
+ print "I don't know how to "+cmd
+ tellCommands()
except:
print_exc()
+ else:
+ try:
+ postsuccess[cmd]()
+ except:
+ pass