示例#1
0
 def processKeyBindings(self, opcode):
     '''Process pressed key according to key bindings'''
     if self.inputState == 'normal':
         ch = chr(opcode)
         try:
             actionName, args = self.bindings[ch]
         except KeyError:
             raise UnknownKeyError
         
         self.inputState = 'action'
         self.currentAction = actionName
         self.actionArgs = copy.deepcopy(args)
         self.actionArgsIter = iter(args)
         
         if not self.tryLaunchAction():
             self.processAction()
     else:
         argName = self.actionArgsNext
         arg = self.actionArgs[argName]
         argType = arg[0]
         if argType == 'direction':
             ch = chr(opcode)
             if ch in self.movementKeys:
                 direct = self.movementKeys[ch]
                 result = Direct(*direct)
             else:
                 raise UnknownKeyError
         elif argType == 'inventory':
             result = self.processListArgument(self.entity.get('inv'), opcode)
         elif argType == 'list':
             elist = actionapi.action(arg[1], {'subject':self.entity})
             result = self.processListArgument(elist, opcode)
         else:
             raise RuntimeError('unknown input type requested: {0}'.format(argType))
         
         self.actionArgs[argName] = result
         if not self.tryLaunchAction():
             self.processAction()
示例#2
0
 def redraw(self):
     # TODO:
     # - flexible gui
     # - forbid direct access to world
     # - draw vision, not actual map
     mapVision = self.entity.mapVision()
     self.displayData = self.mapVisualizer.toXml(mapVision, 0, 6)
     
     # TODO: don't resize on every iteration
     w = mapVision.width
     h = mapVision.height
     self.resize(w+40, h+8)
     
     if self.showingLogs:
         self.showLogs()
     
     if self.inputState == 'normal':
         pass
     elif self.inputState == 'action' and self.nextArgumentType() == 'direction':
         self.putString(0, 0, 'direction?  ')
     elif self.inputState == 'action' and self.nextArgumentType() == 'inventory':
         self.showingInv = True
         self.putString(0, 0, 'list element?  ')
     elif self.inputState == 'action' and self.nextArgumentType() == 'list':
         self.showingList = True
         self.currentList = actionapi.action(self.nextArgument()[1], {'subject':self.entity})
         self.putString(0, 0, 'list element?  ')
     
     if self.showingInv:
         self.showInv()
     
     if self.showingList and self.currentList:
         self.showList(self.currentList)
     
     self.showAttr()
     
     super().redraw()
示例#3
0
 def attackEnemy(self, entity, dx, dy):
     actionapi.action('fight', {'subject':entity, 'target':Direct(dx, dy)})
示例#4
0
 def moveTo(self, entity, dx, dy):
     actionapi.action('move', {'subject':entity, 'dx':dx, 'dy':dy})
示例#5
0
 def wait(self, entity):
     '''Just wait'''
     actionapi.action('wait', {'subject':entity})