本文整理汇总了Python中gamestate.GameState.fromString方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.fromString方法的具体用法?Python GameState.fromString怎么用?Python GameState.fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.fromString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import fromString [as 别名]
#.........这里部分代码省略.........
def handleNetworkRequest(self, data, address):
"""Handel een netwerk request af.
"""
# Lees bericht uit.
id = int(data.split(" ")[0])
command = data.split(" ")[1]
args = " ".join(data.split(" ")[2:])
# Check of het ons ID heeft.
if id not in [0, self.connectionId]:
return
# Welcome command bij inloggen.
if command == "welcome":
playerName = args.split(" ")[0]
if playerName == self.playerName:
connectionId = int(args.split(" ")[1])
self.connectionId = connectionId
print "Connected! Connection ID = %i" % connectionId
# Denied command.
elif command == "denied":
# Dit gaat alleen op als je nog geen verbinding hebt.
if self.connectionId == None:
# Check of het om onze speler gaat.
playerName = args.split(" ")[0]
if playerName == self.playerName:
# Sluit af met de reden die de server ons gaf.
reason = " ".join(args.split(" ")[1:])
print "Connection denied: %s" % reason
sys.exit(0)
# Updaten van de posities.
elif command == "update":
self.gameState.fromString(args)
# Onbekend request.
else:
print "Unknown network command: %s" % data
def handleConnection(self):
"""Handel server connection shit af.
"""
try:
data, address = self.sock.recvfrom( 1024 )
except socket.error:
pass
else:
#print "Received message:", data
self.handleNetworkRequest(data, address)
def draw(self):
"""Teken het scherm.
"""
# Zwarte achtergrond.
self.screen.fill((0,0,0))
# Teken alle players.
for player in self.gameState.getPlayers():
ding = pygame.Surface((16, 16))
ding.fill((255, 255, 255))
self.screen.blit(ding, player.getPosition())
# Teken de autopilot als die aan staat.
if self.autopilot == True:
text = self.font.render("Autopilot enabled", True, (255, 255, 255))
self.screen.blit(text, (10, 10))
# Display updaten.
pygame.display.flip()
def run(self):
"""Start de main loop.
"""
# Connect met de server.
self.sock.sendto("0 connect %s" % self.playerName, (self.serverAddress, 12221))
# Ga eeuwig door.
while True:
# Events afhandelen.
self.handleEvents()
# Bewegen doorsturen naar server.
self.move()
# Server network input afhandelen.
self.handleConnection()
# Tekenen.
self.draw()
# Wachten.
#pygame.time.delay(10)
pygame.time.delay(50)