fixed countdown and current_player a bit...

master
tzzzzzzzx 3 years ago
parent 12d0a71380
commit 677e3e0716

@ -318,15 +318,15 @@ def showText(screen,fontObj,text,x,y):
def drawButton22(screen): def drawButton22(screen):
##一些按钮的实例化 ##一些按钮的实例化
button_stop = Button(pg.transform.scale(pg.image.load("Image/叫停.bmp"),(100,50)),(400,0)) button_stop = Button(pg.transform.scale(pg.image.load("Image/叫停.bmp"),(100,50)),(400,0))
screen.blit(button_stop.image, button_stop.rect) screen.blit(button_stop.image, button_stop.rect)
button_quit = Button(pg.transform.scale(pg.image.load("Image/退出.bmp"),(100,50)),(300,0)) button_quit = Button(pg.transform.scale(pg.image.load("Image/退出.bmp"),(100,50)),(300,0))
screen.blit(button_quit.image, button_quit.rect) screen.blit(button_quit.image, button_quit.rect)
button_fail = Button(pg.transform.scale(pg.image.load("Image/认输.bmp"),(100,50)),(500,0)) button_fail = Button(pg.transform.scale(pg.image.load("Image/认输.bmp"),(100,50)),(500,0))
screen.blit(button_fail.image, button_fail.rect) screen.blit(button_fail.image, button_fail.rect)
button_restart = Button(pg.transform.scale(pg.image.load("Image/restart.bmp"),(100,50)),(100,0)) button_restart = Button(pg.transform.scale(pg.image.load("Image/restart.bmp"),(100,50)),(100,0))
screen.blit(button_restart.image, button_restart.rect) screen.blit(button_restart.image, button_restart.rect)
@ -455,6 +455,7 @@ def main(mode):
#print('current moving color: ',game_state.color()) #print('current moving color: ',game_state.color())
if lastNetworkMsg != networkMsg:#handle if lastNetworkMsg != networkMsg:#handle
#! 无法解决的问题:判断延迟导致无法同时接收来自服务器的两条转发消息。 #! 无法解决的问题:判断延迟导致无法同时接收来自服务器的两条转发消息。
#! 尝试让输方发送消息解决上述问题。
print('catch new msg: ',networkMsg) print('catch new msg: ',networkMsg)
lastNetworkMsg = networkMsg #networkMsg中保存当前字典 lastNetworkMsg = networkMsg #networkMsg中保存当前字典
if 'status' in networkMsg.keys(): if 'status' in networkMsg.keys():
@ -505,10 +506,6 @@ def main(mode):
valid_moves = game_state.getAllMoves() valid_moves = game_state.getAllMoves()
other_stage = not other_stage other_stage = not other_stage
counts=20 counts=20
#轮到的方
showText(screen,bigfont,backend.GameState().color() ,700,350)
pg.display.update()
game_state.conquer()#update conquer stage
thisMove = None thisMove = None
for e in pg.event.get(): for e in pg.event.get():
@ -550,8 +547,8 @@ def main(mode):
else: else:
click_queue = [square_selected] click_queue = [square_selected]
elif e.type == COUNTS:# 判断事件是否为计时事件 elif e.type == COUNTS:# 判断事件是否为计时事件
counts -= 1 if not other_stage and counts > 0 and not game_over: counts -= 1
text = str(counts).rjust(3) if counts >= 0 else '0' text = str(counts).rjust(3)
showText(screen,bigfont,text,650,250) showText(screen,bigfont,text,650,250)
pg.display.update() pg.display.update()
@ -591,7 +588,7 @@ def main(mode):
if game_state.conquer() and not game_over: if game_state.conquer() and not game_over:
print("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 = { winJson = {
'type': 2, 'type': 2,
'msg': { 'msg': {
@ -601,7 +598,7 @@ def main(mode):
} }
} }
client.send(json.dumps(winJson).encode("utf-8")) 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 game_over = True
#print('game over label confirmed.') #print('game over label confirmed.')
@ -612,7 +609,7 @@ def main(mode):
showGameOverText(screen,"player "+ ("b" if MySide==0 else "r") + " quitted the game") #对手退出了 showGameOverText(screen,"player "+ ("b" if MySide==0 else "r") + " quitted the game") #对手退出了
if time_out_side != None: if time_out_side != None:
showGameOverText(screen,"player "+ ("b" if time_out_side==1 else "r")+" timed out") #超时了 showGameOverText(screen,"player "+ ("b" if time_out_side==1 else "r")+" timed out") #超时了
showText(screen,bigfont,game_state.color(),700,350)
clock.tick(50) clock.tick(50)
pg.display.flip() pg.display.flip()

Loading…
Cancel
Save