From 677e3e0716760c5caadd7655ae658eeba8bfeb3f Mon Sep 17 00:00:00 2001 From: tzzzzzzzx <414850847@qq.com> Date: Fri, 23 Sep 2022 20:20:58 +0800 Subject: [PATCH] fixed countdown and current_player a bit... --- SafariChess_Gamev1.0.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/SafariChess_Gamev1.0.py b/SafariChess_Gamev1.0.py index 6740153..9b2acf5 100644 --- a/SafariChess_Gamev1.0.py +++ b/SafariChess_Gamev1.0.py @@ -318,15 +318,15 @@ def showText(screen,fontObj,text,x,y): def drawButton22(screen): - ##一些按钮的实例化 - button_stop = Button(pg.transform.scale(pg.image.load("Image/叫停.bmp"),(100,50)),(400,0)) - screen.blit(button_stop.image, button_stop.rect) - button_quit = Button(pg.transform.scale(pg.image.load("Image/退出.bmp"),(100,50)),(300,0)) - screen.blit(button_quit.image, button_quit.rect) - button_fail = Button(pg.transform.scale(pg.image.load("Image/认输.bmp"),(100,50)),(500,0)) - screen.blit(button_fail.image, button_fail.rect) - button_restart = Button(pg.transform.scale(pg.image.load("Image/restart.bmp"),(100,50)),(100,0)) - screen.blit(button_restart.image, button_restart.rect) + ##一些按钮的实例化 + button_stop = Button(pg.transform.scale(pg.image.load("Image/叫停.bmp"),(100,50)),(400,0)) + screen.blit(button_stop.image, button_stop.rect) + button_quit = Button(pg.transform.scale(pg.image.load("Image/退出.bmp"),(100,50)),(300,0)) + screen.blit(button_quit.image, button_quit.rect) + button_fail = Button(pg.transform.scale(pg.image.load("Image/认输.bmp"),(100,50)),(500,0)) + screen.blit(button_fail.image, button_fail.rect) + button_restart = Button(pg.transform.scale(pg.image.load("Image/restart.bmp"),(100,50)),(100,0)) + screen.blit(button_restart.image, button_restart.rect) @@ -455,6 +455,7 @@ def main(mode): #print('current moving color: ',game_state.color()) if lastNetworkMsg != networkMsg:#handle #! 无法解决的问题:判断延迟导致无法同时接收来自服务器的两条转发消息。 + #! 尝试让输方发送消息解决上述问题。 print('catch new msg: ',networkMsg) lastNetworkMsg = networkMsg #networkMsg中保存当前字典 if 'status' in networkMsg.keys(): @@ -505,10 +506,6 @@ def main(mode): valid_moves = game_state.getAllMoves() other_stage = not other_stage counts=20 - #轮到的方 - showText(screen,bigfont,backend.GameState().color() ,700,350) - pg.display.update() - game_state.conquer()#update conquer stage thisMove = None for e in pg.event.get(): @@ -550,8 +547,8 @@ def main(mode): else: click_queue = [square_selected] elif e.type == COUNTS:# 判断事件是否为计时事件 - counts -= 1 - text = str(counts).rjust(3) if counts >= 0 else '0' + if not other_stage and counts > 0 and not game_over: counts -= 1 + text = str(counts).rjust(3) showText(screen,bigfont,text,650,250) pg.display.update() @@ -591,7 +588,7 @@ def main(mode): if game_state.conquer() and not game_over: print("GAME OVER!") # - if game_state.win_person == ('b' if MySide == 1 else 'r'): + if game_state.win_person == ('r' if MySide == 1 else 'b'): #测试:我输了再发 winJson = { 'type': 2, 'msg': { @@ -601,7 +598,7 @@ def main(mode): } } client.send(json.dumps(winJson).encode("utf-8")) - print('i won, and game over message sent.') + print('i lost, and game over message sent.') game_over = True #print('game over label confirmed.') @@ -612,7 +609,7 @@ def main(mode): showGameOverText(screen,"player "+ ("b" if MySide==0 else "r") + " quitted the game") #对手退出了 if time_out_side != None: showGameOverText(screen,"player "+ ("b" if time_out_side==1 else "r")+" timed out") #超时了 - + showText(screen,bigfont,game_state.color(),700,350) clock.tick(50) pg.display.flip()