本文整理汇总了Python中inventory.Inventory.bag方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.bag方法的具体用法?Python Inventory.bag怎么用?Python Inventory.bag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.bag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import bag [as 别名]
class Game(cmd.Cmd):
prompt = '> '
def __init__(self):
#-----------------------------------------------------------------------
#Here the game is initialized asking for commands via the Cmd module,
#the variables given are the first room you start in and prints out the
#location
cmd.Cmd.__init__(self)
self.loc = get_room('intro')
self.look()
self.inventory = Inventory()
self.player = Player()
#------------------------------------------------------------------------
#This checks which room you are in if you can go the way for the command
#given and prints out your location
def emptyline(self):
pass
def objects(self, args):
objects = self.loc._objects(args)
if objects is None:
print(('Ther are no %s in the area' % args))
self.look()
else:
self.look()
def move(self, dir):
newroom = self.loc._neighbor(dir)
if newroom is None:
print('''You cannot go this away''')
self.look()
else:
self.loc = get_room(newroom)
self.look()
def look(self):
print((self.loc.name))
for line in textwrap.wrap(self.loc.description, 72):
print(line)
print('')
#-----------------------------------------------------------------------
#commands
#movement
def do_n(self, args):
'''goes north'''
self.move('n')
def do_s(self, args):
'''goes south'''
self.move('s')
def do_e(self, args):
'''goes east'''
self.move('e')
def do_w(self, args):
'''goes west'''
self.move('w')
def do_climb(self, args):
'''Climbs where possible'''
self.move('climb')
def do_get(self, args):
'''Gets items from an area or from your bag'''
if self.inventory.slots[args] > 0:
self.player.right_hand(args)
else:
print('You do not have this item')
def do_enter(self, args):
'''Enters rooms, Villages, and caves where possible'''
self.move('enter')
def do_leave(self, args):
'''Exits the current room'''
self.move('leave')
def help_get(self):
for i in (textwrap.wrap(''' If you are trying to grab an item out from
your bag type get followed by the item in your bag, this applys to
items in an area as well''', 72)):
print(('', i))
#prompts
def do_chop(self, args):
self.objects('trees')
def do_name(self, args):
'''Prints the users name if there is one'''
self.player.player_name()
def do_hand(self, args):
'''Prints what is in hand'''
print((self.player.print_hand()))
#.........这里部分代码省略.........