当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.remove_item方法代码示例

本文整理汇总了Python中inventory.Inventory.remove_item方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.remove_item方法的具体用法?Python Inventory.remove_item怎么用?Python Inventory.remove_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


在下文中一共展示了Inventory.remove_item方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import remove_item [as 别名]
 def test_remove(self):
     inv = Inventory(slot_count=20)
     block = random.choice(G.BLOCKS_DIR.keys())
     max_items = G.BLOCKS_DIR[block].max_stack_size * 20
     for i in xrange(0, max_items):
         self.assertTrue(inv.add_item(block))
     self.assertFalse(inv.remove_item(block, quantity=0))
     for i in xrange(0, 20):
         self.assertTrue(inv.remove_item(block, quantity=G.BLOCKS_DIR[block].max_stack_size))
     self.assertEqual(inv.slots, [None] * 20)
     for i in xrange(0, max_items):
         self.assertTrue(inv.add_item(block))
     for i in xrange(0, 20):
         self.assertTrue(inv.remove_by_index(i, quantity=G.BLOCKS_DIR[block].max_stack_size))
     self.assertEqual(inv.slots, [None] * 20)
     for i in xrange(0, 20):
         inv.slots[i] = ItemStack(block, amount=1)
         inv.slots[i].change_amount(-1)
     inv.remove_unnecessary_stacks()
     self.assertEqual(inv.slots, [None] * 20)
开发者ID:ArionPorfirio,项目名称:Minecraft,代码行数:22,代码来源:tests.py

示例2: InventoryTest

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import remove_item [as 别名]
class InventoryTest(unittest.TestCase):
    
    def setUp(self):
        """Create inventory instance."""
        self.inv = Inventory()

    def tearDown(self):
        """Close database opened by self.inv."""
        self.inv.close()

    def test_add_record_to_database(self):
        nrecords = self.count_records()
        self.inv.add_item('test_item', 15.00, 200)
        self.assertEqual(self.count_records(), nrecords+1)

    def test_remove_record_from_database(self):
        nrecords = self.count_records()
        self.inv.remove_item('test_item')
        self.assertEqual(self.count_records(), nrecords-1)

    def test_query_sort(self):
        for field in ['item', 'price', 'qty', 'updated']:
            for direction in ['ascending', 'descending']:
                count = 0
                for row in self.inv.query_sort(field, direction):
                    count += 1
                self.assertEqual(count, 100)

    def test_count_records(self):
        self.assertEqual(self.count_records(), self.inv.nrecords)

    def test_next_page(self):
        pass

    def test_update_qty(self):
        self.inv.update_qty('item000', 250)
        self.inv.c.execute('SELECT qty FROM inventory WHERE item=?', ('item000',))
        self.assertEqual(self.inv.c.fetchone()[0], 250)
        self.inv.update_qty('item000', 500)

    def test_update_price(self):
        original_price = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item000',)).fetchone()[0]
        self.inv.update_price('item000', 10)
        self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item000',))
        self.assertEqual(self.inv.c.fetchone()[0], 10)
        self.inv.update_price('item000', original_price)

    def test_query_by_price(self):
        original_price1 = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item050',)).fetchone()[0]
        original_price2 = self.inv.c.execute('SELECT price FROM inventory WHERE item=?', ('item150',)).fetchone()[0]
        self.inv.update_price('item050', 50)
        self.inv.update_price('item150', 70)
        # Check with low and high price range
        count = 0
        for row in self.inv.query_by_price(40,80):
            count += 1
        self.assertEqual(count, 2)
        # Check with only low price
        count = 0
        for row in self.inv.query_by_price(40):
            count += 1
        self.assertEqual(count, 2)
        # We also expect all records to be returned with no prices set
        count = 0
        for row in self.inv.query_by_price():
            count += 1
        self.assertEqual(count, self.count_records())

    def test_query_by_name(self):
        # Test should return same number of results regardless of sort
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100, 'item'):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100, 'price'):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0', 0, 100):
            count += 1
        self.assertEqual(count, 100)
        count = 0
        for row in self.inv.query_by_name('item0'):
            count += 1
        self.assertEqual(count, 100)

    def test_get_qty(self):
        self.inv.update_qty('item100', 1000)
        self.assertEqual(self.inv.view_qty('item100'), 1000)
        self.inv.update_qty('item100', 1000)

    def count_records(self):
        return self.inv.c.execute('SELECT Count(*) FROM inventory').fetchone()[0]
开发者ID:timahutchinson,项目名称:curly-quack,代码行数:96,代码来源:unit_test.py

示例3: Human

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import remove_item [as 别名]
class Human(Entity):
    """Human entity."""
  
    #
    # __init__()
    #
    def __init__(self, name, gender, view_radius, inventory_size):
        """Create new human entity instance.
        
        Arguments:
        name - name of entity
        gender - either "Male" or "Female"
        view_radius - number of tiles they can see into the distance
        inventory_size - size of their inventory, in game weight units
        
        """
        super(Human, self).__init__(name, "Human", '@', libtcod.white)

        self.gender = gender
        self.view_radius = view_radius
        self.inventory = Inventory(inventory_size)
        
        self.report = ReportType.VISIBLE_NPC
        
        # Add actions
        self.action_drop = ea.action_drop
        self.action_get = ea.action_get
        self.action_consume = ea.action_consume

    #
    # __str__()
    #
    def __str__(self):
        """Overridden from base class to include gender and name."""
        return "{0} human named {1}".format(self.gender.lower(), self.name)
        
    #
    # add_entity_to_inventory()
    #
    def add_entity_to_inventory(self, entity):
        """Helper method to add an entity to inventory.
        
        Arguments:
        entity - entity to add.
        """
        entity.x = -1
        entity.y = -1
        entity.owner = self
        self.inventory.add_item(entity)

    #
    # remove_entity_from_inventory()
    #
    def remove_entity_from_inventory(self, entity):
        """Helper method to remove an entity from inventory.
        
        Arguments:
        entity - entity to remove.
        """
        entity.owner = None
        self.inventory.remove_item(entity)
开发者ID:ajare,项目名称:citadel,代码行数:63,代码来源:human.py


注:本文中的inventory.Inventory.remove_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。