本文整理汇总了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)
示例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()
示例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()