|
|
|
@ -1624,7 +1624,7 @@ def server_thread(conn,addr) :
|
|
|
|
|
player.id = id
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
continue
|
|
|
|
|
if msg["status"] == 1:
|
|
|
|
|
elif msg["status"] == 1:
|
|
|
|
|
status_2,counterpart_name,game_id,side,think_time,total_time = C.handle_new_player(msg)
|
|
|
|
|
player.game_id = game_id
|
|
|
|
|
player.status_2 = status_2
|
|
|
|
@ -1639,19 +1639,36 @@ def server_thread(conn,addr) :
|
|
|
|
|
player.status_2 = status_2
|
|
|
|
|
player.request = request
|
|
|
|
|
player.game_id = game_id
|
|
|
|
|
player.side = side
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
break
|
|
|
|
|
if request == "stop" or request == "report":
|
|
|
|
|
if side == 0:
|
|
|
|
|
player.Left_win = 1
|
|
|
|
|
elif side == 1:
|
|
|
|
|
player.Right_win = 1
|
|
|
|
|
elif request == "quit":
|
|
|
|
|
if side == 0:
|
|
|
|
|
player.Right_win = 1
|
|
|
|
|
elif side == 1:
|
|
|
|
|
player.Left_win = 1
|
|
|
|
|
#print(player.status_2)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
elif msg["status"] == 3:
|
|
|
|
|
status_2, game_id, side = C.handle_time_over(msg)
|
|
|
|
|
player.status_2 = status_2
|
|
|
|
|
player.game_id = game_id
|
|
|
|
|
player.side = side
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
if side == 0:
|
|
|
|
|
player.Right_win = 1
|
|
|
|
|
elif side == 1:
|
|
|
|
|
player.Left_win = 1
|
|
|
|
|
break
|
|
|
|
|
except:
|
|
|
|
|
break
|
|
|
|
|
conn.close()
|
|
|
|
|
try:
|
|
|
|
|
conn.close()
|
|
|
|
|
except:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_playing = Lock()
|
|
|
|
@ -1678,28 +1695,7 @@ class Config:
|
|
|
|
|
MAX_THNIKING_TIME = 60
|
|
|
|
|
MAX_TOTAL_TIME = 600
|
|
|
|
|
|
|
|
|
|
def pause():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def report():
|
|
|
|
|
pass
|
|
|
|
|
def quit():
|
|
|
|
|
return 0
|
|
|
|
|
def surrender():
|
|
|
|
|
pass
|
|
|
|
|
def start_menu():
|
|
|
|
|
pygame.init()
|
|
|
|
|
surface = pygame.display.set_mode((600, 400))
|
|
|
|
|
menu = pygame_menu.Menu('DO YOUR ACTIONS', 400, 300, theme = pygame_menu.themes.THEME_BLUE)
|
|
|
|
|
menu.add.button('Pause', pause)
|
|
|
|
|
menu.add.button('Surrender', surrender)
|
|
|
|
|
menu.add.button('Report', report)
|
|
|
|
|
menu.add.button('Quit', pygame_menu.events.EXIT)
|
|
|
|
|
draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion,
|
|
|
|
|
r_leopard, r_mouse, r_fox, 0, 0, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
|
|
menu.mainloop(surface)
|
|
|
|
|
def main():
|
|
|
|
|
global l_animals,r_animals
|
|
|
|
|
global player, Axis
|
|
|
|
@ -1707,11 +1703,11 @@ def main():
|
|
|
|
|
MAP = init.calc_map()
|
|
|
|
|
MAP1 = init.clac_MAP1()
|
|
|
|
|
game_status = start_game.starting_screen()
|
|
|
|
|
Left_win = Right_win = 0
|
|
|
|
|
demo = 0 # 标识是否为网络版
|
|
|
|
|
stop = 0 # 标识是否请求暂停游戏
|
|
|
|
|
pause = 0 # 标识是否请求暂停游戏
|
|
|
|
|
exit = 0 # 标识是否请求退出游戏
|
|
|
|
|
report = 0 # 标识是否举报对方
|
|
|
|
|
other_player_move = 0 # 标识对方是否能移动
|
|
|
|
|
if not game_status:
|
|
|
|
|
return False
|
|
|
|
|
elif game_status == 1:
|
|
|
|
@ -1725,6 +1721,8 @@ def main():
|
|
|
|
|
if demo == 1:
|
|
|
|
|
name = input("Please tell us your name:")
|
|
|
|
|
player.name = name
|
|
|
|
|
Left_win = player.Left_win
|
|
|
|
|
Right_win = player.Right_win
|
|
|
|
|
Address = (Config.SOCKET_HOST, Config.SOCKET_PORT)
|
|
|
|
|
if demo == 1:
|
|
|
|
|
C.load_config()
|
|
|
|
@ -1733,19 +1731,36 @@ def main():
|
|
|
|
|
C.conn_to_server(client, name)
|
|
|
|
|
while run:
|
|
|
|
|
clock.tick(FPS)
|
|
|
|
|
|
|
|
|
|
if left_win(x, y, MAP, MAP1):
|
|
|
|
|
if demo == 1 and exit == 1:
|
|
|
|
|
request = "quit"
|
|
|
|
|
C.exit_game(client,request,player.game_id,player.side)
|
|
|
|
|
if player.side == 0:
|
|
|
|
|
player.Right_win = Right_win = 1
|
|
|
|
|
elif player.side == 1:
|
|
|
|
|
player.Left_win = Left_win = 1
|
|
|
|
|
if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1):
|
|
|
|
|
run = False
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1):
|
|
|
|
|
run = False
|
|
|
|
|
if demo == 1:
|
|
|
|
|
C.start_new_thread(server_thread, (client,Address))
|
|
|
|
|
Right_win = player.Right_win
|
|
|
|
|
Left_win = player.Left_win
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
|
|
|
|
start_game.starting_menu()
|
|
|
|
|
elif event.type == pygame.QUIT:
|
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
|
run = False
|
|
|
|
|
elif event.type == pygame.KEYDOWN and demo == 1: # and demo == 1
|
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
|
|
|
|
flag = start_game.starting_menu()
|
|
|
|
|
if flag == 1:
|
|
|
|
|
pause = 1
|
|
|
|
|
report = exit = 0
|
|
|
|
|
elif flag == 2:
|
|
|
|
|
report = 1
|
|
|
|
|
pause = exit = 0
|
|
|
|
|
elif flag == 3:
|
|
|
|
|
exit = 1
|
|
|
|
|
report = pause = 0
|
|
|
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
|
|
|
b1, b2, b3 = pygame.mouse.get_pressed()
|
|
|
|
|
if b1 and not b3:
|
|
|
|
@ -2119,16 +2134,33 @@ def main():
|
|
|
|
|
|
|
|
|
|
draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion,
|
|
|
|
|
r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn)
|
|
|
|
|
if left_win(x, y, MAP, MAP1):
|
|
|
|
|
if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1):
|
|
|
|
|
run = False
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1):
|
|
|
|
|
run = False
|
|
|
|
|
if left_win(x, y, MAP, MAP1):
|
|
|
|
|
if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1):
|
|
|
|
|
if demo == 1 and player.side == 0:
|
|
|
|
|
if pause == 1:
|
|
|
|
|
request = "stop"
|
|
|
|
|
C.exit_game(client,request,player.game_id,player.side)
|
|
|
|
|
print_text(WIN, font, 500, 400, "Red Win!", RED)
|
|
|
|
|
pygame.display.update()
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
if player.status_2 == 2 and demo == 1 :
|
|
|
|
|
C.ack_exit_game(client, player.side)
|
|
|
|
|
#client.close()
|
|
|
|
|
|
|
|
|
|
if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1):
|
|
|
|
|
if demo == 1 and player.side == 1:
|
|
|
|
|
if pause == 1:
|
|
|
|
|
request = "stop"
|
|
|
|
|
C.exit_game(client,request,player.game_id,player.side)
|
|
|
|
|
print_text(WIN, font, 500, 400, "Blue Win!", BLUE)
|
|
|
|
|
pygame.display.update()
|
|
|
|
|
if player.status_2 == 2 and demo == 1 :
|
|
|
|
|
print('******')
|
|
|
|
|
C.ack_exit_game(client,player.side)
|
|
|
|
|
#client.close()
|
|
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
#os.system("pause")
|
|
|
|
|
return start_game.starting_screen()
|
|
|
|
@ -2136,7 +2168,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
again = 1
|
|
|
|
|
while again == 1:
|
|
|
|
|
while again > 0:
|
|
|
|
|
l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_fox, r_mouse=init.refresh()
|
|
|
|
|
draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion,
|
|
|
|
|
r_leopard, r_mouse, r_fox,0,0,0,0,0,0,0)
|
|
|
|
|