本文整理汇总了Python中buffer.Buffer.flush_session方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.flush_session方法的具体用法?Python Buffer.flush_session怎么用?Python Buffer.flush_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.flush_session方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Bot
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import flush_session [as 别名]
#.........这里部分代码省略.........
# set owner if it is ours
if self.has_id(id):
cell.owner = self
# add cell to global cells
self.game.add_cell(cell)
# version 520
def parse_deaths(self):
amount = self.buffer.read_int()
for i in range(0, amount):
id = self.buffer.read_int()
# if it is one of ours
if self.has_id(id):
self.remove_id(id)
self.game.remove_id(id)
if len(self.ids) == 0:
self.send_spawn()
print("[bot/parse_deaths] No cells left, respawning")
# remove cell globally
if self.game.has_cell(id):
cell = self.game.get_cell(id)
cell.remove_watcher(self)
self.game.remove_cell(id)
def send_init(self):
if self.is_connected() and not self.has_sent_init:
self.has_sent_init = True
self.buffer.write_byte(254)
self.buffer.write_int(4)
self.buffer.flush_session(self.session)
self.buffer.write_byte(255)
self.buffer.write_int(1)
self.buffer.flush_session(self.session)
return True
return False
def send_spawn(self):
if self.is_connected() and (time.time() - self.last_sent_spawn > 4):
for cell in self.game.cells.values():
cell.remove_watcher(self)
self.last_sent_spawn = time.time()
self.buffer.write_string(self.name)
self.buffer.flush_session(self.session)
return True
return False
def send_move(self, x, y):
if self.is_connected() and self.is_alive():
if not (self.last_x == x and self.last_y == y):
# update our last variables
self.last_x = x
self.last_y = y
# send new coordinates
self.buffer.write_byte(16)
self.buffer.write_double(x)
self.buffer.write_double(y)
self.buffer.write_int(0)
# flush
self.buffer.flush_session(self.session)