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


Python Keyboard.increment方法代码示例

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


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

示例1: GameManager

# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import increment [as 别名]

#.........这里部分代码省略.........

        # Start the system running
        self.running = DataToggle(
            source = DataOr(self.keyboard[sf.Key.ESCAPE],
                            DataAnd(self.keyboard[sf.Key.Q], 
                                    DataOr(self.keyboard[sf.Key.L_SYSTEM],
                                           self.keyboard[sf.Key.R_SYSTEM]))),
                                  initVal = True)
        
################################################################################

    def handle_input(self):
        """Processes the list of events, sending them to their various handlers.
        """
            
        for event in self.window.iter_events():
            # If the window is ever closed, stop running.
            if event.type == sf.Event.CLOSED:
                self.running = False
                return
            
            # Send key events to the keyboard, intercepting certain special
            # cases (that restart the game)
            elif event.type == sf.Event.KEY_PRESSED:
                if event.code == sf.Key.R or \
                  (event.code == sf.Key.SPACE and not self.players[-1].alive):
                    self.start_again()
                    continue
                self.keyboard.down(event.code)
                
            elif event.type == sf.Event.KEY_RELEASED:
                self.keyboard.up(event.code)  
                
        self.keyboard.increment()
        for vkb in self.virtual_keyboards:
            vkb.increment()
                
################################################################################

    def run(self):
        """Main game loop.  Updates all entities then draws everything,
        repeating over and over again."""
        
        # Begin loop
        while self.running:
            self.handle_input()
            self.update()
            if self.running:
                self.draw()
#                if self.RECORDING:
#                    self.image.copy_screen(self.window)
#                    self.image.save_to_file("frames/"+str(self.frameNo) + ".png")
#                    self.frameNo += 1
        self.shutdown()

################################################################################
    
    def update(self):
        """Update the game's state."""
        # Handle the menu screens
        if self.state == 'game':
            if len(self.asteroids) == 0:
                self.state = 'win'
                self.keyboard.up(sf.Key.SPACE)
                return
        else:
开发者ID:mkeeter,项目名称:Multitroids,代码行数:70,代码来源:game_manager.py


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