|
|
|
@ -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")
|
|
|
|
|