|
|
@ -35,9 +35,20 @@ IMAGES = {}
|
|
|
|
bias_top = 100 #棋盘的上边距
|
|
|
|
bias_top = 100 #棋盘的上边距
|
|
|
|
bias_left = 100 #棋盘的左边距
|
|
|
|
bias_left = 100 #棋盘的左边距
|
|
|
|
#multithreading?
|
|
|
|
#multithreading?
|
|
|
|
mutex = Lock()
|
|
|
|
def startNewThread(target):
|
|
|
|
mutex_playing = Lock()
|
|
|
|
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双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
def loadImages():#加载图片,a,b双方分别有象狮豹狼狐鹰鼠七个角色
|
|
|
|
pieces = ["r7", "r6", "r5", "r4", "r3", "r2", "r1",
|
|
|
|
pieces = ["r7", "r6", "r5", "r4", "r3", "r2", "r1",
|
|
|
|
"b7", "b6", "b5", "b4", "b3", "b2", "b1",
|
|
|
|
"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))
|
|
|
|
IMAGES[piece] = pg.transform.scale(pg.image.load("./Image/pieces/pieces_rb/" + piece + ".png"), (SIZE - 10, SIZE - 10))
|
|
|
|
|
|
|
|
|
|
|
|
tools = ["trap", "home1","home2"]
|
|
|
|
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))
|
|
|
|
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 = pg.display.set_mode((BOARD_WIDTH + MOVE_LOG_PANEL_WIDTH, BOARD_HEIGHT))#设置窗口大小
|
|
|
|
#screen.fill(pg.Color("white"))
|
|
|
|
#screen.fill(pg.Color("white"))
|
|
|
@ -307,7 +318,8 @@ def main(mode,p1,p2,network = None):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if mademove:
|
|
|
|
if mademove:
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
|
|
|
|
|
mademove = False
|
|
|
|
ShowGameState(screen,game_state,valid_moves,square_selected)
|
|
|
|
ShowGameState(screen,game_state,valid_moves,square_selected)
|
|
|
|
if game_state.conquer():
|
|
|
|
if game_state.conquer():
|
|
|
|
showGameOverText(screen,"player "+game_state.win_person+" wins")
|
|
|
|
showGameOverText(screen,"player "+game_state.win_person+" wins")
|
|
|
@ -350,12 +362,12 @@ def main(mode,p1,p2,network = None):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if mademove:
|
|
|
|
if mademove:
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
|
valid_moves = game_state.getAllMoves()
|
|
|
|
ShowGameState(screen,game_state,valid_moves,square_selected)
|
|
|
|
#mademove = False
|
|
|
|
#* 网络对战局面更新
|
|
|
|
#* 网络对战局面更新
|
|
|
|
if network is not None:
|
|
|
|
if network is not None:
|
|
|
|
print('waiting for other players to move...')
|
|
|
|
startNewThread(updateForEnemy(network,game_state))
|
|
|
|
otherMove = game_state.dnldmv_server()
|
|
|
|
ShowGameState(screen,game_state,valid_moves,square_selected)
|
|
|
|
|
|
|
|
|
|
|
|
if game_state.conquer():
|
|
|
|
if game_state.conquer():
|
|
|
|
showGameOverText(screen,"player "+game_state.win_person+" wins")
|
|
|
|
showGameOverText(screen,"player "+game_state.win_person+" wins")
|
|
|
|