|
|
|
@ -2,7 +2,23 @@ import pygame
|
|
|
|
|
import init
|
|
|
|
|
import start_game
|
|
|
|
|
import time
|
|
|
|
|
import Client_connection as C
|
|
|
|
|
import os
|
|
|
|
|
import socket
|
|
|
|
|
import sys
|
|
|
|
|
import json
|
|
|
|
|
import uuid
|
|
|
|
|
import time
|
|
|
|
|
from threading import Thread, Lock
|
|
|
|
|
import socket_client as s
|
|
|
|
|
import pygame_menu
|
|
|
|
|
|
|
|
|
|
if(sys.version[:1] == "3"):
|
|
|
|
|
import queue as Queue
|
|
|
|
|
from _thread import *
|
|
|
|
|
else:
|
|
|
|
|
import Queue
|
|
|
|
|
from _thread import *
|
|
|
|
|
WIDTH , HEIGHT = 1200 , 800
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,7 +38,6 @@ Elephant = pygame.mixer.Sound('audio/Elephant.mp3')
|
|
|
|
|
Leopard = pygame.mixer.Sound('audio/Leopard.mp3')
|
|
|
|
|
Lion = pygame.mixer.Sound('audio/Lion.mp3')
|
|
|
|
|
Mouse = pygame.mixer.Sound('audio/Mouse.mp3')
|
|
|
|
|
#Start = pygame.mixer.Sound('audio/start.mp3')
|
|
|
|
|
Tiger = pygame.mixer.Sound('audio/Tiger.mp3')
|
|
|
|
|
Wolf = pygame.mixer.Sound('audio/Wolf.mp3')
|
|
|
|
|
Fox = pygame.mixer.Sound('audio/Fox.mp3')
|
|
|
|
@ -129,7 +144,7 @@ def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_eleph
|
|
|
|
|
l_elephant = pygame.Rect(281,10,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_eagle = pygame.Rect(157,120,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_wolf = pygame.Rect(284,229,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_lion = pygame.Rect(292,343,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_lion = pygame.Rect(282,343,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_leopard = pygame.Rect(285,450,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_mouse = pygame.Rect(285,665,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
|
l_fox = pygame.Rect(157,557,CHESSSIZE_Y,CHESSSIZE_Y)
|
|
|
|
@ -1277,7 +1292,6 @@ def right_win(x,y,MAP,MAP1):
|
|
|
|
|
return 0
|
|
|
|
|
if isWin == 1:
|
|
|
|
|
return 1
|
|
|
|
|
#print(isWin)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def right_move(old_x,old_y,x,y,id,MAP,MAP1):
|
|
|
|
@ -1584,51 +1598,153 @@ def right_Wall(id,MAP,MAP1):
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def goBack(l_axis,r_axis,MAP,MAP1,turn,animalsName):
|
|
|
|
|
if turn:
|
|
|
|
|
id,old_x,old_y = l_axis.pop()
|
|
|
|
|
x, y = init.calc(animalsName[id].x,animalsName[id].y)
|
|
|
|
|
MAP[x][y] = MAP1[x][y]
|
|
|
|
|
MAP[old_x][old_y] = id
|
|
|
|
|
animalsName[id].x , animalsName[id].y = init.tran(old_x,old_y)
|
|
|
|
|
turn = 0
|
|
|
|
|
player = s.Player()
|
|
|
|
|
axis = [(0, 0), (2, 6), (1, 1), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2),
|
|
|
|
|
(6, 3), (6, 6)]
|
|
|
|
|
Axis = s.Chessmen_axis(axis)
|
|
|
|
|
def server_thread(conn,addr) :
|
|
|
|
|
global player,Axis
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
msg = conn.recv(1024)
|
|
|
|
|
if not msg:
|
|
|
|
|
break
|
|
|
|
|
print(msg)
|
|
|
|
|
msg = json.loads(msg)
|
|
|
|
|
#TODO : side的确定
|
|
|
|
|
if not 'status' in msg:
|
|
|
|
|
status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg)
|
|
|
|
|
id = num + 1
|
|
|
|
|
player.game_id = game_id
|
|
|
|
|
player.status_2 = status_2
|
|
|
|
|
Axis.axis[id]['old_x'] = old_x
|
|
|
|
|
Axis.axis[id]['old_y'] = old_y
|
|
|
|
|
Axis.axis[id]['x'] = x
|
|
|
|
|
Axis.axis[id]['y'] = y
|
|
|
|
|
player.id = id
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
continue
|
|
|
|
|
if 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
|
|
|
|
|
player.side = side
|
|
|
|
|
player.counterpart_name = counterpart_name
|
|
|
|
|
player.think_time = think_time
|
|
|
|
|
player.total_time = total_time
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
continue
|
|
|
|
|
elif msg["status"] == 2:
|
|
|
|
|
status_2,request,game_id,side = C.handle_exit_game(msg)
|
|
|
|
|
player.status_2 = status_2
|
|
|
|
|
player.request = request
|
|
|
|
|
player.game_id = game_id
|
|
|
|
|
player.side = side
|
|
|
|
|
player.invalid = 1
|
|
|
|
|
break
|
|
|
|
|
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
|
|
|
|
|
break
|
|
|
|
|
except:
|
|
|
|
|
break
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_playing = Lock()
|
|
|
|
|
def time_thread():
|
|
|
|
|
mutex_playing.acquire()
|
|
|
|
|
is_over_time = 0
|
|
|
|
|
while True:
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
if player.think_time <= 0:
|
|
|
|
|
is_over_time = 1
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
player.think_time -= 1
|
|
|
|
|
player.total_time -= 1
|
|
|
|
|
if is_over_time:
|
|
|
|
|
return False
|
|
|
|
|
else :
|
|
|
|
|
id, old_x, old_y = r_axis.pop()
|
|
|
|
|
x, y = init.calc(animalsName[id].x, animalsName[id].y)
|
|
|
|
|
MAP[x][y] = MAP1[x][y]
|
|
|
|
|
MAP[old_x][old_y] = id
|
|
|
|
|
animalsName[id].x, animalsName[id].y = init.tran(old_x, old_y)
|
|
|
|
|
turn = 1
|
|
|
|
|
return l_axis,r_axis,MAP,MAP1,turn
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
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
|
|
|
|
|
MAX_TOTAL_TIME = 600
|
|
|
|
|
|
|
|
|
|
def pause():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
animalsName = init.getAnimalsname()
|
|
|
|
|
print(animalsName)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
BGM.play(-1)
|
|
|
|
|
MAP = init.calc_map()
|
|
|
|
|
MAP1 = init.clac_MAP1()
|
|
|
|
|
game_status = start_game.starting_screen()
|
|
|
|
|
demo = 0 # 标识是否为网络版
|
|
|
|
|
stop = 0 # 标识是否请求暂停游戏
|
|
|
|
|
exit = 0 # 标识是否请求退出游戏
|
|
|
|
|
report = 0 # 标识是否举报对方
|
|
|
|
|
other_player_move = 0 # 标识对方是否能移动
|
|
|
|
|
if not game_status:
|
|
|
|
|
return False
|
|
|
|
|
elif game_status == 1:
|
|
|
|
|
demo = 0
|
|
|
|
|
elif game_status == 2:
|
|
|
|
|
demo = 1
|
|
|
|
|
run = True
|
|
|
|
|
#print(animalsName[1].x)
|
|
|
|
|
l_axis=r_axis=[]
|
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
|
font = pygame.font.SysFont('kaiti',40)
|
|
|
|
|
status = id = old_x = old_y = x = y = turn = 0
|
|
|
|
|
if demo == 1:
|
|
|
|
|
name = input("Please tell us your name:")
|
|
|
|
|
player.name = name
|
|
|
|
|
Address = (Config.SOCKET_HOST, Config.SOCKET_PORT)
|
|
|
|
|
if demo == 1:
|
|
|
|
|
C.load_config()
|
|
|
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
client.connect((Config.SOCKET_HOST, Config.SOCKET_PORT))
|
|
|
|
|
C.conn_to_server(client, name)
|
|
|
|
|
while run:
|
|
|
|
|
#print("left win:",left_win(x, y, MAP, MAP1))
|
|
|
|
|
#print("right win:",right_win(x, y, MAP, MAP1))
|
|
|
|
|
clock.tick(FPS)
|
|
|
|
|
|
|
|
|
|
if left_win(x, y, MAP, MAP1):
|
|
|
|
|
run = False
|
|
|
|
|
break
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
run = False
|
|
|
|
|
break
|
|
|
|
|
clock.tick(FPS)
|
|
|
|
|
if demo == 1:
|
|
|
|
|
C.start_new_thread(server_thread, (client,Address))
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
|
|
|
|
start_game.starting_menu()
|
|
|
|
|
elif event.type == pygame.QUIT:
|
|
|
|
|
run = False
|
|
|
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
|
|
|
b1, b2, b3 = pygame.mouse.get_pressed()
|
|
|
|
@ -1636,11 +1752,11 @@ def main():
|
|
|
|
|
mouse_x , mouse_y = event.pos
|
|
|
|
|
old_x = x
|
|
|
|
|
old_y = y
|
|
|
|
|
x = int(mouse_x / WIDTH * 9)
|
|
|
|
|
y = int(mouse_y / HEIGHT * 7)
|
|
|
|
|
if status == 0:
|
|
|
|
|
x = int((mouse_x+10) / WIDTH * 9)
|
|
|
|
|
y = int((mouse_y+10) / HEIGHT * 7)
|
|
|
|
|
if status == 0 :
|
|
|
|
|
id = MAP[x][y]
|
|
|
|
|
if 0 < id < 8 and turn == 0:
|
|
|
|
|
if (0 < id < 8 and turn == 0 and demo == 0) or (0 < id < 8 and demo == 1 and turn == player.side):
|
|
|
|
|
if id == 1:
|
|
|
|
|
Mouse.play()
|
|
|
|
|
elif id == 2:
|
|
|
|
@ -1656,7 +1772,7 @@ def main():
|
|
|
|
|
elif id == 7:
|
|
|
|
|
Elephant.play()
|
|
|
|
|
status = 1
|
|
|
|
|
elif 7 < id <15 and turn == 1:
|
|
|
|
|
elif (7 < id <15 and turn == 1 and demo == 0) or (7 < id <15 and demo == 1 and turn == player.side):
|
|
|
|
|
if id == 8:
|
|
|
|
|
Mouse.play()
|
|
|
|
|
if id == 9:
|
|
|
|
@ -1674,216 +1790,344 @@ def main():
|
|
|
|
|
status = 2
|
|
|
|
|
#TODO: Cirlce the elective animal
|
|
|
|
|
else:
|
|
|
|
|
if id == 1 and turn == 0 and status == 1:
|
|
|
|
|
if (id == 1 and turn == 0 and status == 1 and demo == 0) or (id == 1 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if(ismove(old_x,old_y,x,y,id,MAP,MAP1)):
|
|
|
|
|
#print(MAP1[old_x][old_y])
|
|
|
|
|
l_mouse.x,l_mouse.y = init.tran(x,y)
|
|
|
|
|
animalsName[1]=l_mouse
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if(demo == 1):
|
|
|
|
|
C.move(client,player.game_id,player.side,id,old_x,old_y,x,y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id,old_x,old_y))
|
|
|
|
|
else:
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 2 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 2 and turn == 0 and status == 1 and demo == 0) or (id == 2 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_eagle.x , l_eagle.y = init.tran(x,y)
|
|
|
|
|
animalsName[2] = l_leopard
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 3 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 3 and turn == 0 and status == 1 and demo == 0) or (id == 3 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_fox.x , l_fox.y = init.tran(x,y)
|
|
|
|
|
animalsName[3] = l_fox
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 4 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 4 and turn == 0 and status == 1 and demo == 0) or (id == 4 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_wolf.x , l_wolf.y = init.tran(x,y)
|
|
|
|
|
animalsName[4] = l_wolf
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 5 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 5 and turn == 0 and status == 1 and demo == 0) or (id == 5 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_leopard.x , l_leopard.y = init.tran(x,y)
|
|
|
|
|
animalsName[5] = l_leopard
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 6 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 6 and turn == 0 and status == 1 and demo == 0) or (id == 6 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_lion.x , l_lion.y = init.tran(x,y)
|
|
|
|
|
animalsName[6] = l_lion
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 7 and turn == 0 and status == 1:
|
|
|
|
|
elif (id == 7 and turn == 0 and status == 1 and demo == 0) or (id == 7 and demo == 1 and status == 1 and turn == player.side and turn == 0):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 1
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
l_elephant.x , l_elephant.y = init.tran(x,y)
|
|
|
|
|
animalsName[7] = l_elephant
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 1
|
|
|
|
|
l_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 8 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 8 and turn == 1 and status == 2 and demo == 0) or (id == 8 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_mouse.x , r_mouse.y = init.tran(x,y)
|
|
|
|
|
animalsName[8] = r_mouse
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 9 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 9 and turn == 1 and status == 2 and demo == 0) or (id == 9 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_eagle.x , r_eagle.y = init.tran(x,y)
|
|
|
|
|
animalsName[9] = r_eagle
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 10 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 10 and turn == 1 and status == 2 and demo == 0) or (id == 10 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_fox.x , r_fox.y = init.tran(x,y)
|
|
|
|
|
animalsName[10] = r_fox
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 11 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 11 and turn == 1 and status == 2 and demo == 0) or (id == 11 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_wolf.x , r_wolf.y = init.tran(x,y)
|
|
|
|
|
animalsName[11] = r_wolf
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 12 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 12 and turn == 1 and status == 2 and demo == 0) or (id == 12 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_leopard.x , r_leopard.y = init.tran(x,y)
|
|
|
|
|
animalsName[12] = r_leopard
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 13 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 13 and turn == 1 and status == 2 and demo == 0) or (id == 13 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_lion.x , r_lion.y = init.tran(x,y)
|
|
|
|
|
animalsName[13] = r_lion
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
else :
|
|
|
|
|
status = 0
|
|
|
|
|
elif id == 14 and turn == 1 and status == 2:
|
|
|
|
|
elif (id == 14 and turn == 1 and status == 2 and demo == 0) or (id == 14 and turn == player.side and status == 2 and demo == 1 and turn == 1):
|
|
|
|
|
if MAP[x][y] == id:
|
|
|
|
|
status = 2
|
|
|
|
|
else:
|
|
|
|
|
if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) :
|
|
|
|
|
r_elephant.x , r_elephant.y = init.tran(x,y)
|
|
|
|
|
animalsName[14] = r_elephant
|
|
|
|
|
MAP[old_x][old_y] = MAP1[old_x][old_y]
|
|
|
|
|
MAP[x][y] = id
|
|
|
|
|
status = 0
|
|
|
|
|
if (demo == 1):
|
|
|
|
|
C.move(client, player.game_id, player.side, id, old_x, old_y, x, y)
|
|
|
|
|
turn = 0
|
|
|
|
|
r_axis.append((id, old_x, old_y))
|
|
|
|
|
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']
|
|
|
|
|
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:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_mouse.x , l_mouse.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 2 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_eagle.x , l_eagle.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 3 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_fox.x , l_fox.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 4 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_wolf.x , l_wolf.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 5 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_leopard.x , l_leopard.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 6 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_lion.x , l_lion.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 7 and turn == 0:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
l_elephant.x , l_elephant.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 8 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_mouse.x , r_mouse.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 9 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_eagle.x , r_eagle.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 10 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_fox.x , r_fox.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 11 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_wolf.x , r_wolf.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 12 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_leopard.x , r_leopard.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 13 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_lion.x , r_lion.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
elif counterpart_id == 14 and turn == 1:
|
|
|
|
|
if MAP[counterpart_x][counterpart_y] != counterpart_id:
|
|
|
|
|
if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
|
|
|
|
|
ID[MAP[counterpart_x][counterpart_y]] = 0
|
|
|
|
|
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
|
|
|
|
|
MAP[counterpart_x][counterpart_y] = counterpart_id
|
|
|
|
|
r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y)
|
|
|
|
|
turn = (1-turn)
|
|
|
|
|
player.invalid = 0
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
|
run = False
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
run = False
|
|
|
|
|
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.update(animalsName)
|
|
|
|
|
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)
|
|
|
|
|
#print("left win:", left_win(x, y, MAP, MAP1))
|
|
|
|
|
#print("right win:", right_win(x, y, MAP, MAP1))
|
|
|
|
|
if left_win(x, y, MAP, MAP1):
|
|
|
|
|
print_text(WIN, font, 500, 400, "Left Win!", RED)
|
|
|
|
|
print_text(WIN, font, 500, 400, "Red Win!", RED)
|
|
|
|
|
pygame.display.update()
|
|
|
|
|
if right_win(x, y, MAP, MAP1):
|
|
|
|
|
print_text(WIN, font, 500, 400, "Right Win!", BLUE)
|
|
|
|
|
print_text(WIN, font, 500, 400, "Blue Win!", BLUE)
|
|
|
|
|
pygame.display.update()
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
#os.system("pause")
|
|
|
|
@ -1894,13 +2138,12 @@ if __name__ == "__main__":
|
|
|
|
|
again = 1
|
|
|
|
|
while again == 1:
|
|
|
|
|
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()
|
|
|
|
|
#print(r_eagle)
|
|
|
|
|
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)
|
|
|
|
|
again = main()
|
|
|
|
|
l_animals = r_animals = 7
|
|
|
|
|
ID = [1 for i in range(20)]
|
|
|
|
|
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()
|
|
|
|
|
animalsName = init.getAnimalsname()
|
|
|
|
|
print(animalsName)
|
|
|
|
|
axis = [(0, 0), (2, 6), (1, 1), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2),
|
|
|
|
|
(6, 3), (6, 6)]
|
|
|
|
|
Axis = s.Chessmen_axis(axis)
|
|
|
|
|
pygame.quit()
|
|
|
|
|