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


Python Display.tick方法代码示例

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


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

示例1: Simulator

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import tick [as 别名]
class Simulator(object):
    def __init__(self, config={}, size=(8, 8), frames_per_second=30, foreground=False):
        try:
            game_name = config["game"]
            del config["game"]
        except KeyError:
            game_name = DEFAULT_GAME
        game = GAMES[game_name]
        self.GAME_CODE = GAME_CODES[game_name]
        self.arena = game(**config)

        self.display = Display(self.arena, self.GAME_CODE)

        self.foreground = foreground
        self.frames_per_second = frames_per_second

        if not self.foreground:
            self._loop_thread = threading.Thread(target=self._main_loop, args=(frames_per_second,))
            self._loop_thread.setDaemon(True)
            self._loop_thread.start()

    def run(self):
        if not self.foreground:
            raise RuntimeError("Simulator runs in the background. Try passing foreground=True")
        self._main_loop(self.frames_per_second)

    def set_robots(self, robots):
        self.robots = robots

    def _main_loop(self, frames_per_second):
        clock = pygame.time.Clock()

        while True:
            if any(
                event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)
                for event in pygame.event.get()
            ):
                break

            self.display.tick(1 / frames_per_second)
            clock.tick(frames_per_second)

        for robot in self.robots:
            try:
                robot.raiseExc(KeyboardInterrupt)
            except threading.ThreadError:
                pass

        pygame.quit()
        sys.exit(0)
开发者ID:Chinbob2515,项目名称:MCSROBO,代码行数:52,代码来源:simulator.py

示例2: Simulator

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import tick [as 别名]
class Simulator(object):
    def __init__(self, config={}, frames_per_second=30, background=True):
        try:
            game_name = config['game']
            del config['game']
        except KeyError:
            game_name = DEFAULT_GAME
        game = GAMES[game_name]

        os.chdir(os.path.dirname(os.path.realpath(__file__)))
        self.arena = game(**config)

        self.background = background
        self.frames_per_second = frames_per_second

        if self.background:
            self._loop_thread = threading.Thread(target=self._main_loop, args=(frames_per_second,))
            self._loop_thread.setDaemon(False)
            self._loop_thread.start()

    def run(self):
        if self.background:
            raise RuntimeError('Simulator runs in the background. Try passing background=False')
        self._main_loop(self.frames_per_second)

    def _main_loop(self, frames_per_second):
        self.display = Display(self.arena)
        clock = pygame.time.Clock()

        while True:
            if any(event.type == pygame.QUIT
                   or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)
                   for event in pygame.event.get()):
                # KILL IT ALL WITH FIRE!!
                # must be _exit with an error code to force the other threads to die too.
                os._exit(0)

            self.display.tick(1 / frames_per_second)
            clock.tick(frames_per_second)

        pygame.quit()
开发者ID:srobo-southampton,项目名称:python-lab,代码行数:43,代码来源:simulator.py

示例3: Simulator

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import tick [as 别名]
class Simulator(object):
    def __init__(self, config={}, size=(8, 8), frames_per_second=30, foreground=False):
        try:
            game_name = config['game']
            del config['game']
        except KeyError:
            game_name = DEFAULT_GAME
        game = GAMES[game_name]
        init_marker_info(game)
        self.arena = game(**config)

        self.display = Display(self.arena)

        self.foreground = foreground
        self.frames_per_second = frames_per_second

        if not self.foreground:
            self._loop_thread = threading.Thread(target=self._main_loop, args=(frames_per_second,))
            self._loop_thread.setDaemon(True)
            self._loop_thread.start()

    def run(self):
        if not self.foreground:
            raise RuntimeError('Simulator runs in the background. Try passing foreground=True')
        self._main_loop(self.frames_per_second)

    def _main_loop(self, frames_per_second):
        clock = pygame.time.Clock()

        while True:
            if any(event.type == pygame.QUIT
                    or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)
                    for event in pygame.event.get()):
                break

            self.display.tick(1/frames_per_second)
            clock.tick(frames_per_second)

        pygame.quit()
开发者ID:ReDDsMediaSam,项目名称:robot-sim,代码行数:41,代码来源:simulator.py


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