9.14下午进度

master
DoubleQ 3 years ago
parent 33c0989010
commit 1a4f07f70c

@ -35,9 +35,20 @@ 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",
"b7", "b6", "b5", "b4", "b3", "b2", "b1",
@ -46,7 +57,7 @@ def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角
IMAGES[piece] = pg.transform.scale(pg.image.load("./Image/pieces/pieces_rb/" + piece + ".png"), (SIZE - 10, SIZE - 10))
tools = ["trap", "home1","home2"]
for tool in tools:
for tool in tools:
IMAGES[tool] = pg.transform.scale(pg.image.load("./Image/tools/" + tool + ".jpg"), (SIZE-10, SIZE-10))
#screen = pg.display.set_mode((BOARD_WIDTH + MOVE_LOG_PANEL_WIDTH, BOARD_HEIGHT))#设置窗口大小
#screen.fill(pg.Color("white"))
@ -307,7 +318,8 @@ def main(mode,p1,p2,network = None):
pass
if mademove:
valid_moves = game_state.getAllMoves()
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")
@ -350,12 +362,12 @@ def main(mode,p1,p2,network = None):
pass
if mademove:
valid_moves = game_state.getAllMoves()
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()
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 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