本文整理汇总了Python中engine.Engine.update方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.update方法的具体用法?Python Engine.update怎么用?Python Engine.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Hero
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import update [as 别名]
hero = Hero(config, engine)
engine.entities.append(hero)
engine.entities.append(menu)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.dict['key'] == pygame.K_LEFT:
hero.moving_left = True
if event.dict['key'] == pygame.K_RIGHT:
hero.moving_right = True
if event.dict['key'] == pygame.K_UP:
hero.moving_up = True
if event.dict['key'] == pygame.K_DOWN:
hero.moving_down = True
elif event.type == pygame.KEYUP:
if event.dict['key'] == pygame.K_LEFT:
hero.moving_left = False
if event.dict['key'] == pygame.K_RIGHT:
hero.moving_right = False
if event.dict['key'] == pygame.K_UP:
hero.moving_up = False
if event.dict['key'] == pygame.K_DOWN:
hero.moving_down = False
engine.update()
示例2: __init__
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import update [as 别名]
class Controller:
def __init__(self, connection):
self._connection = connection
self._engine = Engine()
self._cmd_timestamps = deque([0] * 9, 5) # max 9 commands per second
self._direction = Direction.STOP
self._score = defaultdict(int)
def start(self, botname, duelpartner = None):
log.info("Started controller")
if duelpartner == None:
self._join_game(botname)
else:
self._request_duel(botname, duelpartner)
self._mainloop()
def _mainloop(self):
response_handlers = {
'joined': self._game_joined,
'gameStarted': self._game_started,
'gameIsOn': self._make_move,
'gameIsOver': self._game_over
}
response = ""
while True:
try:
response = self._connection.receive()
msg_type, data = response['msgType'], response['data']
if response_handlers.has_key(msg_type):
response_handlers[msg_type](data)
else:
log.warning('Invalid Message received: %s' % response)
except:
log.exception('Json data: %s' % response)
def _game_joined(self, data):
log.info('Game visualization url: %s' % data)
def _game_started(self, data):
log.info('Game started: %s vs. %s' % (data[0], data[1]))
self._engine.start_round()
def _game_over(self, data):
log.info('Game ended. Winner: %s' % data)
self._score[data] += 1
log.info('Score: %s' % self._score)
def _make_move(self, data):
dataentry = DataEntry(data)
direction = self._engine.check_direction(dataentry)
self._engine.update(dataentry)
if direction != self._engine.direction:
self._set_direction(self._engine.direction)
def _join_game(self, botname):
log.info('Joining game...')
self._connection.send({'msgType': 'join', 'data': botname})
def _request_duel(self, botname, duelpartner):
log.info('Challenging %s...' % duelpartner)
self._connection.send({'msgType': 'requestDuel', 'data': [botname, duelpartner]})
def _set_direction(self, direction):
if time.time() - self._cmd_timestamps[0] < Direction.DOWN:
raise Exception("Discard message. Too many requests sent in one second!")
self._cmd_timestamps.append(time.time())
self._connection.send({'msgType': 'changeDir', 'data': direction})