/[fenfire]/fenfire/org/fenfire/demo/text-mm.py
ViewVC logotype

Diff of /fenfire/org/fenfire/demo/text-mm.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by tuukkah, Tue Aug 26 20:44:22 2003 UTC revision 1.5 by tuukkah, Tue Aug 26 22:43:25 2003 UTC
# Line 157  class MMScene: Line 157  class MMScene:
157  scene = MMScene()  scene = MMScene()
158    
159    
160    def tellFocus():
161        print "You are standing on: 0: "+scene.text(scene.focused)
162        print
163    
164    def tellNeighbours():
165        print "You can move to: "
166        list = scene.neighbours(scene.focused)
167        for i in range(len(list)): print "%d: %s" % (i+1, scene.text(list[i]))
168        print
169    
170    def tellComponents():
171        print "In the air around you:"
172        list = scene.components
173        for i in range(len(list)): print "%d: %s" % (-(i+1), scene.text(list[i]))
174        print
175    
176    def tellCommands():
177        keys = cmds.keys()
178        keys.sort()
179        print keys
180    
181    def look(arg=None, examineOnly=0):
182        if arg == None: arg = '' # they don't let me write arg == null || arg.strip
183        if arg.strip() == '':
184            tellFocus()
185            if not examineOnly:
186                tellNeighbours()    
187        elif arg.strip() == 'around':
188            tellComponents()
189        else:
190            try:
191                i = int(arg)
192                if i>0:
193                    print "%d: %s" % (i, scene.text(scene.neighbours(scene.focused)[i-1]))
194                elif i<0:
195                    print "%d: %s" % (i, scene.text(scene.components[-i-1]))
196                else:
197                    tellFocus()
198            except ValueError:
199                print "I don't see "+arg
200    
201    def whereabouts():
202        tellComponents()
203        look()
204    
205    
206  cmds = {'quit': lambda x:quit(),  cmds = {'quit': lambda x:quit(),
207          'save': lambda x:save(),          'save': lambda x:save(),
208            'help': lambda x:tellCommands(),
209            'examine': lambda str:look(str, examineOnly=1),
210            'look': look,
211            'lookat': look,
212            'whereabouts': lambda x:whereabouts(),
213          'new': scene.newNode,          'new': scene.newNode,
214          'add': scene.addNode,          'add': scene.addNode,
215          'write': scene.editText,          'write': scene.editText,
# Line 168  cmds = {'quit': lambda x:quit(), Line 219  cmds = {'quit': lambda x:quit(),
219          'unlink': lambda str:scene.unlink(scene.neighbours(scene.focused)[int(str)-1]),          'unlink': lambda str:scene.unlink(scene.neighbours(scene.focused)[int(str)-1]),
220          }          }
221    
222    postsuccess = {'moveto': look,
223                   'changeto': whereabouts,
224                   }
225    
226    print "*"*20
227    print """Welcome
228    You stand, and there is free space around you and under your feet.
229    You might see some writing, and perhaps by writing and creating more and
230    by linking pieces, you could make this mirror something you have on your mind.
231    
232    Just one more remark: remember to save every now and then.
233    """
234    print
235    whereabouts()
236    tellCommands()
237    
238  while 1:  while 1:
239      print '*' * 5      print '*' * 5
240      print "You are at: "+scene.text(scene.focused)      line = ''
241      print      while line == '':
242      print "You can move to: "          print "What, or where to, shall we? ",
243      list = scene.neighbours(scene.focused)          line = stdin.readline().lstrip()[:-1]
244      for i in range(len(list)): print "%d: %s" % (i+1, scene.text(list[i]))          print # there's some odd space character output, this hides it
     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()  
245      try:      try:
246          i = int(line)          i = int(line)
247          if i>0:          if i>0:
248              scene.focus(scene.neighbours(scene.focused)[i-1])              line = "moveto "+line
249          elif i<0:          elif i<0:
250              scene.focus(scene.components[-i-1])              line = "changeto "+line
251      except ValueError:      except ValueError:
252          cmdend = line.find(' ')          pass
253          cmd, rest = None, None      cmdend = line.find(' ')
254          if cmdend == -1:      cmd, rest = None, None
255              cmd = line      if cmdend == -1:
256              rest = None          cmd = line
257          else:          rest = None
258              cmd = line[:cmdend]      else:
259              rest = line[cmdend:].strip()          cmd = line[:cmdend]
260          try:          rest = line[cmdend:].strip()
261              cmds[cmd](rest)      try:
262          except KeyError:          cmds[cmd](rest)
263              print "I don't know how to "+cmd      except KeyError:
264          except:          print "I don't know how to "+cmd
265              print_exc()          tellCommands()
266      except:      except:
267          print_exc()          print_exc()
268        else:
269            try:
270                postsuccess[cmd]()
271            except:
272                pass

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26