How to use python pygame to realize Gobang online
This article mainly explains "how to use python pygame to achieve Gobang online". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use python pygame to achieve Gobang online.
In the same local area network, when the server is turned on, another machine changes the IP address HOST to the IP address corresponding to the server, and the port number is consistent with that of the server. (IP address query method: enter cmd,cmd window in the menu bar, enter ipconfig to find the IPv4 address under the wireless network)
Server:
#-*-coding: utf-8-*-"Created on Tue Jun 8 14:03:09 2021@author: Administrator"import pygameimport sysfrom pygame.locals import * from collections import Counterfrom socket import * from timeimport ctimeimport jsonimport selectimport socket# interface initialization screen=pygame.display.set_mode ((400450)) pygame.display.set_caption ('Gobang') pygame.init () # Image Import img_board=pygame.image.load ('F:/images/ Gobang / chess_board. Png') img_bchess=pygame.image.load ('F:/images/ Gobang / black_chess.jpg') img_wchess=pygame.image.load (' F:/images/ Gobang / white_chess.jpg') # Color white= (255255255) black= (0L0 0) # data used for transmission msg= [] # Checkerboard definition chess_board= [[]] def set_chess_board (): XQuery Yizhao 0 while True: if Xerox 40 if y