示例#1
0
 def test_PutTake(self):
     self.assertIsNone(container.get_item(self.inv_15.container, 0))
     
     container.put_item(self.inv_15.container, self.sword_1.containable, 0)        
     self.assertIsNotNone(container.get_item(self.inv_15.container, 0))        
     self.assertListEqual(self.inv_15.container.children, self.sword_1.containable.container.children)
     self.assertEqual(self.inv_15.container.children[0].container, self.sword_1.containable.container)
     self.assertEqual(self.inv_15.container.children[0].slot, self.sword_1.containable.slot)
     
     container.take_item(self.inv_15.container, 0)
     self.assertIsNone(self.inv_15.container.children[0])
示例#2
0
    def dragObject(self, obj):
        """Drag the selected object.
           @type obj: string
           @param obj: The name of the object
           @return: None"""
        # get the widget from the gui with the name obj
        drag_widget = self.gui.findChild(name=obj)
        drag_item = drag_widget.item
        # only drag if the widget is not empty
        if drag_item != None:
            if isinstance(drag_item, General):
                drag_item = drag_item.containable
            # get the image of the widget
            image = drag_widget.image
            self.setDragData(drag_item, image, image)
            container.take_item(self.container, drag_item.slot)

            # after dragging the 'item', set the widgets' images
            # so that it has it's default 'empty' images
            drag_widget.item = None
            self.updateImage(drag_widget)
示例#3
0
 def dragObject(self, obj):
     """Drag the selected object.
        @type obj: string
        @param obj: The name of the object within
                    the dictionary 'self.buttons'
        @return: None"""
     # get the widget from the gui with the name obj
     drag_widget = self.gui.findChild(name = obj)
     drag_item = drag_widget.item
     # only drag if the widget is not empty
     if (drag_item != None):
         # get the item that the widget is 'storing'
         data_drag.dragged_item = drag_widget.item
         # get the up and down images of the widget
         up_image = drag_widget.up_image
         down_image = drag_widget.down_image
         self.setDragData(drag_widget.item, down_image, up_image)
         container.take_item(self.container, drag_widget.item.slot)
         
         # after dragging the 'item', set the widgets' images
         # so that it has it's default 'empty' images
         drag_widget.item = None
         self.updateImage(drag_widget)
示例#4
0
 def __call__(self, game_state):
     """
     Move items from the player's inventory to the NPC's inventory.
     
     @param game_state: variables and functions that make up the current
         game state.
     @type game_state: dict of objects
     """
     item_types = self.item_types
     for item_type in item_types:
         item = container.take_item(game_state['pc'].container, item_type)
         if (item):
             container.put_item(game_state['npc'].container, item)
             print("You give the {0} to {1}".format(item_type,
                                                    game_state['npc'].
                                                    description.view_name))
         else:
             print("You don't have the {0}".format(item_type))
示例#5
0
 def __call__(self, game_state):
     """
     Take an item from the player and place another at its place.
     
     @param game_state: variables and functions that make up the current
         game state.
     @type game_state: dict of objects
     """
     old_type = self.item_types[0]
     new_type = self.item_types[1]
     item = container.take_item(game_state['pc'].container, old_type)
     if item:
         model = game_state['model']
         new_item = model.createItemByType(new_type, new_type, 
                                           item.entity.world)
         container.put_item(game_state['pc'].container, 
                            new_item.containable, item.slot)
         model.deleteObject(item.entity.general.identifier)
         item.delete()
         print("{0} took the {1} and gave you the {2}".format(
             game_state['npc'].description.view_name, old_type, item_type))
     else:
         print("You don't have the {0}".format(old_type))