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


Python State.print_board方法代码示例

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


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

示例1: __init__

# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import print_board [as 别名]
class Client:

	##	__init__(): Connect to the server and initial the players' state through the returning msg from server.
	##	
	##	1. Prompt the player to enter the server ip address;
	##	2. Receive the initial msg from the server and initial the client state;
	##	3. Launch a new thread to receive message from server for updating state.
	##	
	##	SIZE	:	Message length.
	##	PORT	:	Server ip address port number. Must be the same as the Server.py.
	##	sock	:	The socket to connect to server.
	##	ip		:	Server ip address. Entered by the user.
	##	state	:	The state of the player.
	##	update_flag	:	Decide whether to update the UI.

	def __init__(self):
		self.SIZE = 1024
		self.PORT = 11270
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		print "[Enter Server IP]:"
		self.ip = raw_input()
		self.sock.connect((self.ip, self.PORT))


		msg = self.sock.recv(self.SIZE) 
		self.state = State(msg)
		self.Name = self.state.Name
		self.update_flag = True


		thread.start_new_thread(self.recv_station, ())


	##	get_board(): Get the board state of the game.

	def get_board(self):
		return self.state.Board


	##	send_station(): Send the position of movement to the server.

	def send_station(self, x, y):
		if self.Name == self.state.Turn:	

			input = str(x)+","+str(y)
			pos = Position(input, self.Name)

			if is_valid(self.state.Board, pos) == False:
				print "[Position Invalid, Enter Again]"
			else:
				self.sock.send(pos.to_str())


	##	recv_station(): Receive the update msg from the server.

	def recv_station(self):
		while True:
			self.state = State(self.sock.recv(self.SIZE))
			self.state.print_board()
			self.update_flag = True
开发者ID:EdlinLink,项目名称:Go,代码行数:62,代码来源:Client.py


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