本文整理汇总了Python中inventory.Inventory.categorized_view方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.categorized_view方法的具体用法?Python Inventory.categorized_view怎么用?Python Inventory.categorized_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.categorized_view方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Player
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import categorized_view [as 别名]
#.........这里部分代码省略.........
self.search_skill = SearchSkill(self)
self.inventory = Inventory(self)
def move(self, dx, dy):
newx, newy = self.x + dx, self.y + dy
if not self.map.coords_okay(newx, newy):
return False, False, None
if self.map.has_critter_at((newx, newy)):
cost = self.attack(self.map.get_critter_at(newx, newy))
return True, False, cost
next_tile = self.map.tile_at(newx, newy)
move_to, take_turn, fov_recalc = next_tile.player_move_into(self, newx, newy, self.map)
if move_to:
#todo move cost should be changed by the type of tile we're entering
self.x, self.y = newx, newy
self.search(self.map, 4)
return take_turn, fov_recalc, self.action_cost.move
elif next_tile.is_wall():
gl.message("You bump into wall")
return take_turn, fov_recalc, None
def search(self, map, range=None):
if not range:
range = self.fov_range
map.iterate_fov(self.x, self.y, range, self.see)
return self.action_cost.search
def descend(self, map):
if map.descend_or_ascend(True):
return self.action_cost.stairsdown / 2
return None
def ascend(self, map):
if map.descend_or_ascend(False):
return self.action_cost.stairsdown / 2
return None
def die(self, killer):
gl.message( 'You die...', 'CRITICAL')
gl.__game_state__ = "died"
def earn_exp(self, src):
self.xp += src.xp
if self.xp > util.xp_for_lvl(self.xl):
self.lvl_up()
def lvl_up(self):
self.xl += 1
gl.message ("Congratulations! Level up", 'INFO')
def see(self, tile, tilex, tiley, map):
if tile.items and len(tile.items):
item = tile.items[0]
if not getattr(item, 'seen', False):
gl.message('You see %s' % item)
item.seen = True
if getattr(tile, 'has_hidden', False):
self.search_skill.observe(tile)
def take_damage(self, mob, dmgs, attack):
#take evasion into account
super(Player, self).take_damage(mob, dmgs, attack)
if self.hitpoints <= self.base_hp * gl.__hp_warning__:
gl.message('Low HP!!!', 'WARN')
def gethp(self):
return self.hitpoints
def sethp(self, value):
self.hitpoints = value
gl.require_hud_update()
hp = property(gethp, sethp)
def get_inventory_categorized(self):
""" get_inventory_categorized() => {category :[items]}
Returns list of items divided by category
"""
return self.inventory.categorized_view()
def _item_pickup(self, item):
self.inventory.add_item(item)
gl.message('You pick up ' + str(item))
item.on_pickup(self)
def pickup(self, map, multi_select_handler=None):
tile = self.map.tile_at(self.x, self.y)
items = tile.items
if not items:
gl.message('There is nothing to pick up here')
if len(items) == 1:
item = items.pop()
self._item_pickup(item)
elif multi_select_handler:
selected_items = multi_select_handler(categorize_items(items))
if selected_items:
for item in selected_items:
items.remove(item)
self._item_pickup(item)