From 2e7acc35bdbb1577963e1d342f6446ff4dc0051f Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Tue, 30 Aug 2022 16:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8C=85=E5=9B=B4=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=BC=80=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 3 + src/init.py | 18 + src/main.py | 877 +++++++++++++++++++++++++++++++++++++++------- src/path/path.py | 2 +- src/start_game.py | 2 +- 5 files changed, 766 insertions(+), 136 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d56657a..009ceba 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/src/init.py b/src/init.py index 95acdfa..37b3bb9 100644 --- a/src/init.py +++ b/src/init.py @@ -170,3 +170,21 @@ def clac_MAP1(): x, y = calc(719, 604) MAP[x][y] = 20 return MAP + +def refresh(): + 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_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) + + r_elephant = pygame.Rect(795, 673, CHESSSIZE_Y, CHESSSIZE_Y) + r_eagle = pygame.Rect(925, 570, CHESSSIZE_Y, CHESSSIZE_Y) + r_wolf = pygame.Rect(803, 458, CHESSSIZE_Y, CHESSSIZE_Y) + r_lion = pygame.Rect(802, 347, CHESSSIZE_Y, CHESSSIZE_Y) + r_leopard = pygame.Rect(796, 232, CHESSSIZE_Y, CHESSSIZE_Y) + r_fox = pygame.Rect(920, 123, CHESSSIZE_Y, CHESSSIZE_Y) + r_mouse = pygame.Rect(793, 16, CHESSSIZE_Y, CHESSSIZE_Y) + return 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 \ No newline at end of file diff --git a/src/main.py b/src/main.py index 9ab9f34..01ebf17 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,7 @@ import init import start_game import time import os +#import path.path WIDTH , HEIGHT = 1200 , 800 @@ -115,9 +116,6 @@ def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_eleph draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) #WIN.blit(L_fox,(fox.x,fox.y)) pygame.display.update() -#TODO:传入动物编号id,动物现在的位置(x,y),将点击的动物圈起来,并显示可以移动的地方 -def path(): - pass #animals rect l_elephant = pygame.Rect(int(2/9 * WIDTH),int(0 / 7 * HEIGHT),CHESSSIZE_Y,CHESSSIZE_Y) @@ -751,196 +749,810 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): return 1 if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + else: + return 0 + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + return 1 + return 1 + else : + return 0 + +#TODO:Judge who win +def left_win(x,y,MAP,MAP1): + global r_animals + if r_animals == 0: + return 1 + if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: + return 1 + isWin = 0 + for i in range(8,15): + if ID[i] == 1: + isWin = left_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def left_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 8: + if MAP[x][y] == 18: + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or MAP1[x][y] == 17): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + return 1 + return 1 + else : + return 0 + elif id == 9: + if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[i][y] != 15 and MAP[x][i] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=2): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 15 and MAP[i][y] != 18): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 10: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=3): + if 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + return 0 + elif id == 11: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=4): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 12: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 13: + if MAP[x][y] == 18: + return 0 + if MAP[x][y] == 20: + return 0 + if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if y > old_y: + for i in range(old_y+1,y): + if MAP[x][i] != 20 and MAP[x][i] != 8 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(y+1,old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + if x > old_x: + for i in range(old_x+1,x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + for i in range(x+1,old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 14: + if MAP[x][y] == 18: + return 0 + if(MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + +def left_Wall(id,MAP,MAP1): + if 8<=id<=14: + if id == 8: + old_x,old_y = init.calc(r_mouse.x,r_mouse.y) + elif id == 9: + old_x, old_y = init.calc(r_eagle.x, r_eagle.y) + elif id == 10: + old_x, old_y = init.calc(r_fox.x, r_fox.y) + elif id == 11: + old_x, old_y = init.calc(r_wolf.x, r_wolf.y) + elif id == 12: + old_x, old_y = init.calc(r_leopard.x, r_leopard.y) + elif id == 13: + old_x, old_y = init.calc(r_lion.x, r_lion.y) + elif id == 14: + old_x, old_y = init.calc(r_elephant.x, r_elephant.y) + for x in range(0,9): + for y in range(0,6): + if left_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 +def right_win(x,y,MAP,MAP1): + isWin = 0 + global l_animals + if l_animals == 0: + return 1 + if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: + return 1 + for i in range(1, 8): + if ID[i] == 1: + isWin = right_Wall(i,MAP,MAP1) + if isWin == 0: + return 0 + if isWin == 1: + return 1 + return 0 + +def right_move(old_x,old_y,x,y,id,MAP,MAP1): + if id == 1: + if MAP[x][y] == 16: + return 0 + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or MAP1[x][y] == 15): + if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: + return 0 + if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 2: + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + return 0 + if x == old_x and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if y > old_y: + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 17 and MAP[x][i] != 16 and MAP[x][i] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif y == old_y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 9): + if x > old_x: + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 17 and MAP[i][y] != 16 and MAP[i][y] != 18): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 3: + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 10): + if 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - else : + return 0 + elif id == 4: + if MAP[x][y] == 16: return 0 - elif id == 13: - if MAP[x][y] == 18: + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 5: + if MAP[x][y] == 16: + return 0 + if (MAP[x][y] == 20): + return 0 + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 6: + if MAP[x][y] == 16: return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): if y > old_y: - for i in range(old_y+1,y): - if MAP[x][i] != 20 and MAP[x][i] != 8 : + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: - for i in range(y+1,old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 1<=MAP[x][y]<=6): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 8 <=MAP[x][y] <= 13): if x > old_x: - for i in range(old_x+1,x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: - for i in range(x+1,old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 - if 1 <= MAP[x][y] <= 6: - if MAP[x][y] == 1: + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 else: return 0 - elif id == 14: - if MAP[x][y] == 18: + elif id == 7: + if MAP[x][y] == 16: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): - if 2 <= MAP[x][y] <= 7: - if MAP[x][y] == 1: + if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP1[x][y] == 17 or 2<=MAP[x][y]<=7): - if 2 <= MAP[x][y] <= 7: - if MAP[x][y] == 1: + elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 and MAP[x][y] == 18 or MAP1[x][y] == 15 or 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: if MAP1[x][y] != 20: - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 else: return 0 - ID[MAP[x][y]] = 0 - l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: - ID[MAP[x][y]] = 0 - l_animals -= 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - else : + else: return 0 - -#TODO:Judge who win -def left_win(old_x,old_y,x,y,MAP,MAP1): - global r_animals - if r_animals == 0: - return 1 - if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: - return 1 - for i in range(8,15): - pass - return 0 - -def right_win(old_x,old_y,x,y,MAP,MAP1): - global l_animals - if l_animals == 0: - return 1 - if MAP1[x][y] == 16 and 8 <= MAP[x][y] <= 14: - return 1 - for i in range(1, 8): - pass - return 0 - +def right_Wall(id,MAP,MAP1): + if 1<=id<=7: + if id == 1: + old_x,old_y = init.calc(l_mouse.x,l_mouse.y) + elif id == 2: + old_x, old_y = init.calc(l_eagle.x, l_eagle.y) + elif id == 3: + old_x, old_y = init.calc(l_fox.x, l_fox.y) + elif id == 4: + old_x, old_y = init.calc(l_wolf.x, l_wolf.y) + elif id == 5: + old_x, old_y = init.calc(l_leopard.x, l_leopard.y) + elif id == 6: + old_x, old_y = init.calc(l_lion.x, l_lion.y) + elif id == 7: + old_x, old_y = init.calc(l_elephant.x, l_elephant.y) + for x in range(0,9): + for y in range(0,6): + if right_move(old_x,old_y,x,y,id,MAP,MAP1): + return 0 + return 1 def main(): global l_animals,r_animals BGM.play(-1) @@ -949,7 +1561,6 @@ def main(): game_status = start_game.starting_screen() if not game_status: return True - #TODO:updata MAP1 run = True clock = pygame.time.Clock() font = pygame.font.SysFont('kaiti',40) @@ -962,7 +1573,6 @@ def main(): elif event.type == pygame.MOUSEBUTTONDOWN: b1, b2, b3 = pygame.mouse.get_pressed() if b1 and not b3: - print(r_animals) mouse_x , mouse_y = event.pos old_x = x old_y = y @@ -986,7 +1596,6 @@ def main(): elif id == 7: Elephant.play() status = 1 - path() elif 7 < id <15 and turn == 1: if id == 8: Mouse.play() @@ -1021,9 +1630,7 @@ def main(): elif id == 2 and turn == 0 and status == 1: if MAP[x][y] == id: status = 1 - path() else: - #print(ismove(old_x,old_y,x,y,id,MAP)) if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : l_eagle.x , l_eagle.y = init.tran(x,y) MAP[old_x][old_y] = MAP1[old_x][old_y] @@ -1176,24 +1783,26 @@ def main(): turn = 0 else : status = 0 - #print(turn, status) - if left_win(old_x,old_y,x,y,MAP,MAP1): + if left_win(x,y,MAP,MAP1): run = False - if right_win(old_x,old_y,x,y,MAP,MAP1): + if right_win(x,y,MAP,MAP1): run = False - #print(old_x,old_y) - #print(x,y) 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) - if left_win(old_x, old_y, x, y, MAP, MAP1): + if left_win(x, y, MAP, MAP1): print_text(WIN, font, 500, 400, "Left Win!", RED) pygame.display.update() - if right_win(old_x, old_y, x, y, MAP, MAP1): + if right_win(x, y, MAP, MAP1): print_text(WIN, font, 500, 400, "Right Win!", BLUE) pygame.display.update() - os.system("pause") - pygame.quit() - + time.sleep(2) + #os.system("pause") if __name__ == "__main__": - main() \ No newline at end of file + 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() + 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) + main() + pygame.quit() diff --git a/src/path/path.py b/src/path/path.py index 0b73811..743ecfb 100644 --- a/src/path/path.py +++ b/src/path/path.py @@ -1,5 +1,5 @@ import pygame -import win32con + rules = {} for i in range(1, 8): diff --git a/src/start_game.py b/src/start_game.py index 544a183..5b14df0 100644 --- a/src/start_game.py +++ b/src/start_game.py @@ -1,6 +1,6 @@ import pygame import init -import main + font_addr = pygame.font.get_default_font() font = pygame.font.Font(font_addr, 36)