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


Python Inventory.contents方法代码示例

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


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

示例1: SpaceshipCommand

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import contents [as 别名]
class SpaceshipCommand(cmd.Cmd):
    intro = 'Welcome to Spaceship Build'
    prompt = '> '

    def __init__(self):
        self.bus = Bus('root')
        self.inventory = Inventory()
        self.shop = Shop()
        super().__init__()
        
    def do_exit(self, _):
        '''Exits the game'''
        print(random.choice([
            'So long!',
            'Toodles!',
            'Sayonara!',
            'Bye',
            'Farewell',
            'Take care',
            'Goodbye',
            'Till next time',
            'Later',
            'Best of luck!',
            'Peace Out!',
            'Adios',
            'Ciao!',
            'Au revoir',
            "Don't leave!"]))
        return True

    def do_EOF(self, arg):
        '''Handles Ctrl+D'''
        return self.do_exit(arg)

    
    #----Spaceship Commands
    def do_broadcast(self, arg):
        '''Broadcast message from terminal to attached Buses:

        > broadcast guns.all fire!
        > broadcast system.report 'Everything nominal'
        '''
        topic, message, *_ = shlex.split(arg)
        self.bus.broadcast(topic, message)

    def do_buy(self, type_name):
        '''This purchases an item from the shop and puts it into the
        player's inventory

        > buy raygun
        Raygun-001 purchased and added to inventory.
        '''
        item = self.shop.buy(type_name)
        if item is None:
            print("Can't buy {!r} there's nothing like that."
                  .format(type_name))
        else:
            self.inventory.store(item)
            print(item, "purchased and added to inventory.")
       
        
    def do_subscribe(self, topic_key=''):
        '''Subscribe to message using the topic key, they will be
        visible in the console. If no argument given, all topics are
        subscribed to.

        > subscribe damage.report
        > subscribe guns
        > subscribe
        '''
        self.bus.subscribe(topic_key, spaceship.basic_subscriber)

    def do_inv(self, verbose):
        ''' Prints full inventory'''
        if verbose == '-v':
            print(self.inventory.contents())
        else:
            print(self.inventory.summary_contents())
开发者ID:asm-products,项目名称:spaceship-build,代码行数:80,代码来源:commandline.py


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