diff --git a/src/main.py b/src/main.py index 0848147..43bd26b 100644 --- a/src/main.py +++ b/src/main.py @@ -131,10 +131,10 @@ def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) def 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): WIN.blit(SPACE,(0,0)) - if turn == 0: - WIN.blit(left_turn,init.tran(0,3)) - elif turn == 1: - WIN.blit(right_turn,init.tran(8,3)) + if turn == 1: + WIN.blit(left_turn,init.tran(8,3)) + elif turn == 0: + WIN.blit(right_turn,init.tran(0,3)) draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) path(id, x, y, status, MAP, MAP1, turn) @@ -159,6 +159,7 @@ r_mouse = pygame.Rect(793,16,CHESSSIZE_Y,CHESSSIZE_Y) ############################################# l_animals =r_animals = 7 + def ismove(old_x,old_y,x,y,id,MAP,MAP1): global l_animals global r_animals @@ -959,7 +960,7 @@ def path(id, x, y, status, MAP, MAP1, turn): for i, j in movement: WIN.blit(hint, init.tran(i,j)) WIN.blit(capture_hint,init.tran(x,y)) -#TODO:Judge who win + def left_win(x,y,MAP,MAP1): global r_animals if r_animals == 0: @@ -1615,6 +1616,7 @@ def server_thread(conn,addr) : if not 'status' in msg: status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg) id = num + 1 + id = (id+7) % 14 player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1628,7 +1630,7 @@ def server_thread(conn,addr) : 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 - player.side = side + player.side = 1 - side player.counterpart_name = counterpart_name player.think_time = think_time player.total_time = total_time @@ -1689,7 +1691,7 @@ def time_thread(): return True class Config: - SOCKET_HOST = '192.168.43.201'#Symbolic name meaning all available interfaces + SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces SOCKET_PORT = 50005#Arbitrary non-privileged port MAX_WAITING_TIME = 180 MAX_THNIKING_TIME = 60 @@ -1717,7 +1719,8 @@ def main(): run = True clock = pygame.time.Clock() font = pygame.font.SysFont('kaiti',40) - status = id = old_x = old_y = x = y = turn = 0 + status = id = old_x = old_y = x = y = 0 + turn = 1 if demo == 1: name = input("Please tell us your name:") player.name = name @@ -1733,7 +1736,7 @@ def main(): clock.tick(FPS) if demo == 1 and exit == 1: request = "quit" - C.exit_game(client,request,player.game_id,player.side) + C.exit_game(client,request,player.game_id,1 - player.side) if player.side == 0: player.Right_win = Right_win = 1 elif player.side == 1: @@ -1814,7 +1817,7 @@ def main(): MAP[x][y] = id status = 0 if(demo == 1): - C.move(client,player.game_id,player.side,id,old_x,old_y,x,y) + C.move(client,player.game_id,1 - player.side,(id+7) % 14,old_x,old_y,x,y) turn = 1 else: status = 0 @@ -1828,7 +1831,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1842,7 +1845,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1856,7 +1859,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1870,7 +1873,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1884,7 +1887,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1898,7 +1901,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1912,7 +1915,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1926,7 +1929,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1940,7 +1943,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1954,7 +1957,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1968,7 +1971,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1982,7 +1985,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1996,13 +1999,14 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: counterpart_id = player.id - counterpart_old_x , counterpart_old_y= Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] + print(turn,counterpart_id) + counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] if counterpart_id == 1 and turn == 0: if MAP[counterpart_x][counterpart_y] != counterpart_id: @@ -2144,10 +2148,10 @@ def main(): if pause == 1: request = "stop" C.exit_game(client,request,player.game_id,player.side) - print_text(WIN, font, 500, 400, "Red Win!", RED) + print_text(WIN, font, 500, 400, "Blue Win!", BLUE) pygame.display.update() if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client, player.side) + C.ack_exit_game(client, 1- player.side) if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): @@ -2155,10 +2159,10 @@ def main(): if pause == 1: request = "stop" C.exit_game(client,request,player.game_id,player.side) - print_text(WIN, font, 500, 400, "Blue Win!", BLUE) + print_text(WIN, font, 500, 400, "Red Win!", RED) pygame.display.update() if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client,player.side) + C.ack_exit_game(client,1 - player.side) time.sleep(10) diff --git a/src/main_an.py b/src/main_an.py index 74614c8..43bd26b 100644 --- a/src/main_an.py +++ b/src/main_an.py @@ -131,10 +131,10 @@ def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) def 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): WIN.blit(SPACE,(0,0)) - if turn == 0: - WIN.blit(left_turn,init.tran(0,3)) - elif turn == 1: - WIN.blit(right_turn,init.tran(8,3)) + if turn == 1: + WIN.blit(left_turn,init.tran(8,3)) + elif turn == 0: + WIN.blit(right_turn,init.tran(0,3)) draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) path(id, x, y, status, MAP, MAP1, turn) @@ -159,6 +159,7 @@ r_mouse = pygame.Rect(793,16,CHESSSIZE_Y,CHESSSIZE_Y) ############################################# l_animals =r_animals = 7 + def ismove(old_x,old_y,x,y,id,MAP,MAP1): global l_animals global r_animals @@ -959,7 +960,7 @@ def path(id, x, y, status, MAP, MAP1, turn): for i, j in movement: WIN.blit(hint, init.tran(i,j)) WIN.blit(capture_hint,init.tran(x,y)) -#TODO:Judge who win + def left_win(x,y,MAP,MAP1): global r_animals if r_animals == 0: @@ -1615,6 +1616,7 @@ def server_thread(conn,addr) : if not 'status' in msg: status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg) id = num + 1 + id = (id+7) % 14 player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1628,7 +1630,7 @@ def server_thread(conn,addr) : 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 - player.side = side + player.side = 1 - side player.counterpart_name = counterpart_name player.think_time = think_time player.total_time = total_time @@ -1717,7 +1719,8 @@ def main(): run = True clock = pygame.time.Clock() font = pygame.font.SysFont('kaiti',40) - status = id = old_x = old_y = x = y = turn = 0 + status = id = old_x = old_y = x = y = 0 + turn = 1 if demo == 1: name = input("Please tell us your name:") player.name = name @@ -1733,7 +1736,7 @@ def main(): clock.tick(FPS) if demo == 1 and exit == 1: request = "quit" - C.exit_game(client,request,player.game_id,player.side) + C.exit_game(client,request,player.game_id,1 - player.side) if player.side == 0: player.Right_win = Right_win = 1 elif player.side == 1: @@ -1814,7 +1817,7 @@ def main(): MAP[x][y] = id status = 0 if(demo == 1): - C.move(client,player.game_id,player.side,id,old_x,old_y,x,y) + C.move(client,player.game_id,1 - player.side,(id+7) % 14,old_x,old_y,x,y) turn = 1 else: status = 0 @@ -1828,7 +1831,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1842,7 +1845,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1856,7 +1859,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1870,7 +1873,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1884,7 +1887,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1898,7 +1901,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 1 else : status = 0 @@ -1912,7 +1915,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1926,7 +1929,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1940,7 +1943,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1954,7 +1957,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1968,7 +1971,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1982,7 +1985,7 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 @@ -1996,13 +1999,14 @@ def main(): MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, player.side, id, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) turn = 0 else : status = 0 elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: counterpart_id = player.id - counterpart_old_x , counterpart_old_y= Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] + print(turn,counterpart_id) + counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] if counterpart_id == 1 and turn == 0: if MAP[counterpart_x][counterpart_y] != counterpart_id: @@ -2133,19 +2137,21 @@ 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) or (demo == 1 and Left_win == 1): + if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and left_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False - if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): + Left_win = 1 + if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and right_win(counterpart_x,counterpart_y,MAP,MAP1)): run = False + Right_win = 1 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) + print_text(WIN, font, 500, 400, "Blue Win!", BLUE) pygame.display.update() if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client, player.side) + C.ack_exit_game(client, 1- player.side) if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): @@ -2153,13 +2159,13 @@ def main(): if pause == 1: request = "stop" C.exit_game(client,request,player.game_id,player.side) - print_text(WIN, font, 500, 400, "Blue Win!", BLUE) + print_text(WIN, font, 500, 400, "Red Win!", RED) pygame.display.update() if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client,player.side) + C.ack_exit_game(client,1 - player.side) - time.sleep(2) + time.sleep(10) #os.system("pause") return start_game.starting_screen()