9.14下午进度

master
DoubleQ 3 years ago
parent 33c0989010
commit 1a4f07f70c

@ -35,8 +35,19 @@ IMAGES = {}
bias_top = 100 #棋盘的上边距
bias_left = 100 #棋盘的左边距
#multithreading?
mutex = Lock()
mutex_playing = Lock()
def startNewThread(target):
thread = Thread(target=target)
thread.daemon = True
thread.start()
#网络版更新需要注意多线程的问题?
#尝试写一个函数分配一个新线程供监听
#等待敌人移动
def updateForEnemy(network: backend.Network,game_state: backend.GameState):
print("waiting for the other player to move...")
otherMove = game_state.dnldmv_server()
if otherMove is not None:
game_state.makeMove(otherMove)
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
pieces = ["r7", "r6", "r5", "r4", "r3", "r2", "r1",
@ -308,6 +319,7 @@ def main(mode,p1,p2,network = None):
if mademove:
valid_moves = game_state.getAllMoves()
mademove = False
ShowGameState(screen,game_state,valid_moves,square_selected)
if game_state.conquer():
showGameOverText(screen,"player "+game_state.win_person+" wins")
@ -351,11 +363,11 @@ def main(mode,p1,p2,network = None):
if mademove:
valid_moves = game_state.getAllMoves()
#mademove = False
#* 网络对战局面更新
if network is not None:
startNewThread(updateForEnemy(network,game_state))
ShowGameState(screen,game_state,valid_moves,square_selected)
#* 网络对战局面更新
if network is not None:
print('waiting for other players to move...')
otherMove = game_state.dnldmv_server()
if game_state.conquer():
showGameOverText(screen,"player "+game_state.win_person+" wins")

@ -128,7 +128,7 @@ class GameState:
self.client.send(thisMove)
def dnldmv_server(self):
thisMovejson = self.client.receive()
thisMove =
thisMove = Move([thisMovejson['src']['x'],thisMovejson['src']['y']],[thisMovejson['dst']['x'],thisMovejson['dst']['y']],self.board)
return thisMove
# 判断特殊位置

@ -1,5 +1,5 @@
SOCKET_HOST=127.0.0.1
SOCKET_PORT=50005
MAX_WAITING_TIME=600
MAX_THNIKING_TIME=15
MAX_WAITING_TIME=600000
MAX_THNIKING_TIME=15000
MAX_TOTAL_TIME=1000

Loading…
Cancel
Save