本文整理汇总了Python中Client.recieve方法的典型用法代码示例。如果您正苦于以下问题:Python Client.recieve方法的具体用法?Python Client.recieve怎么用?Python Client.recieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client
的用法示例。
在下文中一共展示了Client.recieve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MultiClientGame
# 需要导入模块: import Client [as 别名]
# 或者: from Client import recieve [as 别名]
class MultiClientGame():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self, color):
self.butterflies = []
self.screen = pygame.display.get_surface()
self.backgroundImage, self.backgroundRect = loadPNG("background.png")
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.active = True
self.level = Map(True)
self.toolbar = GameToolbar()
self.client = Client('localhost')
self.client.connect()
self.client.recieve()
self.client.send(b"connexion avec serveur : OK")
#MAP STRING RECIEVE
mapStr = self.client.recieve(4096)
mapStr = struct.unpack(str(len(mapStr)) + "s", mapStr)[0]
#LOAD MAP FROM STRING
self.level.saveFromStr("tempClient", mapStr)
self.level.load("tempClient")
#CREATE CLIENT RABBIT
self.regis = Rabbit(1, "regis" , color, self.level.objectList, self.level.objectSpritesList)
#SERVER RABBIT COLOR RECIEVE
serverCol = self.client.recieve()
serverCol = struct.unpack("iii", serverCol)
#CLIENT RABBIT COLOR SEND
self.client.send(struct.pack("iii", self.regis.color[0], self.regis.color[1], self.regis.color[2]))
#CREATE SERVER RABBIT
self.john = Rabbit(2, "john" , serverCol, self.level.objectList, self.level.objectSpritesList, True)
self.regis.appendRabbit(self.john)
self.john.appendRabbit(self.regis)
self.pauseMenu = PauseGameMenu()
# for l in range(0, 6):
# while True:
# randPos = random.randint(0, 16)
# if not self.level.isInBlock(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26):
# break
# butterfly = Butterfly(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26, (255, 10, 100), self.level.objectList, self.level.objectSpritesList)
# self.butterflies.append(butterfly)
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
if self.active:
pygame.mouse.set_visible(0)
for event in pygame.event.get():
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
return False, self
elif event.type == KEYDOWN:
if event.key == K_UP:
self.regis.jump()
if event.key == K_LEFT:
self.regis.moveLeftStart()
if event.key == K_RIGHT:
self.regis.moveRightStart()
if event.key == K_KP0:
self.regis.throwCarrot()
elif event.type == KEYUP:
if event.key == K_LEFT:
self.regis.moveLeftStop()
if event.key == K_RIGHT:
self.regis.moveRightStop()
# #IF A RABBIT IS TOUCHED
# elif event.type == USEREVENT + 1:
# print "touche"
# if self.john.isTouched():
# self.john.moveLeftStop()
# self.john.moveRightStop()
# elif self.regis.isTouched():
# self.regis.moveLeftStop()
# self.regis.moveRightStop()
# elif event.type == USEREVENT + 2:
#.........这里部分代码省略.........