当前位置: 首页>>代码示例>>Python>>正文


Python GameState.getPlayers方法代码示例

本文整理汇总了Python中gamestate.GameState.getPlayers方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getPlayers方法的具体用法?Python GameState.getPlayers怎么用?Python GameState.getPlayers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gamestate.GameState的用法示例。


在下文中一共展示了GameState.getPlayers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Client

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getPlayers [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)
开发者ID:rappie,项目名称:platformo_multiplayer_poc,代码行数:104,代码来源:client.py


注:本文中的gamestate.GameState.getPlayers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。