本文整理汇总了Python中buffer.Buffer.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.fill方法的具体用法?Python Buffer.fill怎么用?Python Buffer.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AgarClientProtocol
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import fill [as 别名]
class AgarClientProtocol(WebSocketClientProtocol):
def __init__(self, spectate, *args, **kwargs):
WebSocketClientProtocol.__init__(self, *args, **kwargs)
self.player = Player()
self.ingame = False
self.re_pattern = re.compile(u'[^\u0000-\uD7FF\uE000-\uFFFF]', re.UNICODE)
self.spectate = spectate
def onConnect(self, response):
self.buffer = Buffer()
def onOpen(self):
b = self.buffer
b.write_byte(254)
b.write_uint(5)
b.flush_protocol(self)
b.write_byte(255)
b.write_uint(154669603)
b.flush_protocol(self)
b.write_byte(80)
b.write_string(self.token)
b.flush_protocol(self)
self.player.reset()
self.player.world.reset()
self.player.nick = "PuffTheMagic"
if self.spectate:
self.send_spectate()
else:
self.send_respawn()
def send_respawn(self):
self.spectate = False
b = self.buffer
b.write_byte(0)
b.write_string(self.player.nick.encode('utf-16le'))
b.flush_protocol(self)
def send_spectate(self):
self.spectate = True
b = self.buffer
b.write_byte(1)
b.flush_protocol(self)
def send_target(self, x, y, cid=0):
b = self.buffer
b.write_byte(16)
b.write_int(x)
b.write_int(y)
b.write_uint(cid)
b.flush_protocol(self)
def send_split(self):
b = self.buffer
b.write_byte(17)
b.flush_protocol(self)
def send_shoot(self):
b = self.buffer
b.write_byte(21)
b.flush_protocol(self)
def onMessage(self, payload, isBinary):
self.buffer.fill(payload)
packet = self.buffer.read_byte()
self.parse_packet(packet)
def setInGame(self, opcode):
if opcode in [16,17,32,49,50,64]:
self.ingame =True
def parse_packet(self, opcode):
#print ("===========",opcode,"===========")
b = self.buffer
self.setInGame(opcode)
if opcode == 16:
preys = []
for i in range(0, b.read_short()):
hunter, prey = b.read_uint(), b.read_uint()
preys.append(prey)
if prey in self.player.own_ids:
if len(self.player.own_ids) <= 1:
#self.send_spectate()
print "DEAD!!!!!!!!!!!!!!!!"
#self.subscriber.on_death()
self.player.own_ids.remove(prey)
if prey in self.player.world.cells:
#self.subscriber.on_cell_removed(cid=prey)
del self.player.world.cells[prey]
self.game.gameLayer.sprite_batch.remove(self.game.gameLayer.sprites[prey].img)
self.game.gameLayer.sprite_pool.append(self.game.gameLayer.sprites[prey])
del self.game.gameLayer.sprites[prey]
if prey in self.game.gameLayer.names:
self.game.gameLayer.remove(self.game.gameLayer.names[prey])
#.........这里部分代码省略.........
示例2: Bot
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import fill [as 别名]
#.........这里部分代码省略.........
# remove all bot.ids from game.ids
for id in self.ids:
self.game.remove_id(id)
if self.has_id(id):
self.remove_id(id)
self.game.remove_id(id)
# game deletes all cells w/o watchers
return True
return False
# version 520
def update(self):
# connect if not connected
if not self.is_connected():
self.connect(self.game.host, self.game.port)
return False
# spawn if not alive
if not self.is_alive():
self.send_spawn()
# dont return: if we do, we dont parse spawn packet
# get all data
all = []
all.extend(self.session.inbound)
self.session.inbound = self.session.inbound[len(all):]
if (len(all) != 0):
self.n_updates += 1
# parse all data
for data in all:
self.buffer.fill(data)
packet = self.buffer.read_byte()
self.parse_packet(packet)
if not self.last_update == self.game.timestamp:
# if we didn't receive an update this tick, we dont need to check for destroys.
return
# removing dead cells no longer happens in bot.py
# cells are only removed on a packet, or when there are no watchers (only on disconnect)
return True
def act(self):
# todo: write AI
pass
def parse_packet(self, id):
b = self.buffer
if id == 16:
self.last_update = self.game.timestamp
self.parse_mergers()
self.parse_updates()
self.parse_deaths()
elif id == 17:
x = b.read_float()
y = b.read_float()
ratio = b.read_float()
print('[17]', x, y, ratio)
elif id == 20:
for id in self.ids:
self.game.remove_id(id)
self.ids = []
示例3: AgarClientProtocol
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import fill [as 别名]
class AgarClientProtocol(WebSocketClientProtocol):
def __init__(self, *args, **kwargs):
WebSocketClientProtocol.__init__(self, *args, **kwargs)
self.player = Player()
self.ingame = False
self.re_pattern = re.compile(u'[^\u0000-\uD7FF\uE000-\uFFFF]', re.UNICODE)
def onConnect(self, response):
self.buffer = Buffer()
def onOpen(self, spectate=False):
b = self.buffer
b.write_byte(254)
b.write_uint(5)
b.flush_protocol(self)
b.write_byte(255)
b.write_uint(154669603)
b.flush_protocol(self)
b.write_byte(80)
b.write_string(self.token)
b.flush_protocol(self)
self.player.reset()
self.player.world.reset()
self.player.nick = "PuffTheMagic"
if spectate:
self.send_spectate()
else:
self.send_respawn()
def send_respawn(self):
b = self.buffer
b.write_byte(0)
b.write_string(self.player.nick.encode('utf-16le'))
b.flush_protocol(self)
def send_spectate(self):
b = self.buffer
b.write_byte(1)
b.flush_protocol(self)
def send_target(self, x, y, cid=0):
b = self.buffer
b.write_byte(16)
b.write_int(x)
b.write_int(y)
b.write_uint(cid)
b.flush_protocol(self)
def send_split(self):
b = self.buffer
b.write_byte(17)
b.flush_protocol(self)
def send_shoot(self):
b = self.buffer
b.write_byte(21)
b.flush_protocol(self)
def onMessage(self, payload, isBinary):
self.buffer.fill(payload)
packet = self.buffer.read_byte()
self.parse_packet(packet)
def setInGame(self, opcode):
if opcode in [16,17,32,49,50,64]:
self.ingame = True
def parse_packet(self, opcode):
#print ("===========",opcode,"===========")
b = self.buffer
self.setInGame(opcode)
if opcode == 16:
preys = []
for i in range(0, b.read_short()):
hunter, prey = b.read_uint(), b.read_uint()
preys.append(prey)
if prey in self.player.own_ids:
if len(self.player.own_ids) <= 1:
print "DEAD!!!!!!!!!!!!!!!!"
self.player.own_ids.remove(prey)
if prey in self.player.world.cells:
del self.player.world.cells[prey]
self.game.glcell_pool.append(self.game.glcells[prey])
del self.game.glcells[prey]
while True:
id = b.read_uint()
if id == 0: break
x = b.read_int()
y = b.read_int()
size = b.read_short()
color = (b.read_byte(), b.read_byte(), b.read_byte())
flag = b.read_byte()
virus = (flag & 1)
#.........这里部分代码省略.........