master
JackyMa 2 years ago
parent c70e6bdc9d
commit b8aa1f8f1a

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="int.__getitem__" />
</list>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/animalCraft.iml" filepath="$PROJECT_DIR$/.idea/animalCraft.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [Haorong Jiang]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

@ -0,0 +1,622 @@
import pygame
from copy import copy
from os import _exit # 退出
from collections import Counter as aniSet # 490行
import win32api # 鼠标类操作、屏幕
import win32con # 鼠标类操作、屏幕
pygame.init()
# 主界面
pygame.display.set_mode((1200, 600))
menu_image = pygame.image.load("./mainGround.png")
menu_image = pygame.transform.scale(menu_image, (1200, 600))
flag = True
while flag:
for event in pygame.event.get():
x, y = pygame.mouse.get_pos()
if pygame.mouse.get_pressed()[0] and 500 <= x <= 900 and 300 <= y <= 500:
flag = False
menu = pygame.display.get_surface()
menu.blit(menu_image, (0, 0))
pygame.display.update()
# 获取屏幕大小
sizel = 0.8
size = width, height = win32api.GetSystemMetrics(win32con.SM_CXSCREEN) * sizel, win32api.GetSystemMetrics(
win32con.SM_CYSCREEN) * sizel
# 满屏推算棋格大小
ul = 135 * height // 1080
# 特殊区域
river = [(3, 1), (3, 2), (3, 4), (3, 5),
(4, 1), (4, 2), (4, 4), (4, 5),
(5, 1), (5, 2), (5, 4), (5, 5)]
# 陷阱
Blue_trap = [(0, 2), (0, 4), (1, 3)]
Red_trap = [(8, 2), (8, 4), (7, 3)]
rd = 0
# 穴
Blue_home = [(0, 3)]
Red_home = [(8, 3)]
# 是否可走
Blue_way = 0
Red_way = 0
def get_rect(i, pos): # 定位
j = i.get_rect()
j.left, j.top = pos
return j
def is_chess_in_board(x, y): # 在棋盘里
return 0 <= x < 9 and 0 <= y < 7
def tryout():
global movable, win, rd, Blue_way, Red_way
movable = True # 判断移动变量
win = 0 # 胜负判断变量初始为0为1时红方胜为2时蓝方胜
rd = 0 # 回合计数变量
Blue_way = 0 # 蓝方总可走位置数目
Red_way = 0 # 红方总可走位置数目
# 对方进入洞穴判胜负
if grid[0][3]:
if grid[0][3].camp == 1:
movable = False
win = 1
if grid[8][3]:
if grid[8][3].camp == 0:
movable = False
win = 2
if rd == 100: # 回合数为100时不能继续移动
movable = False
# 遍历双方可走位置总数
for i in range(7):
for j in range(9):
if grid[i][j]:
if grid[i][j].camp == 0:
Blue_way += len(grid[i][j].next)
else:
Red_way += len(grid[i][j].next)
if Blue_way == 0:
win = 1
movable = False
if Red_way == 0:
win = 2
movable = False
def refresh(): # 继续
for i in grid:
for j in i:
if j:
j.next_step(grid)
class Base: # 定义棋子的类
def __init__(self, camp, b, r, Rank): # 初始化camp为阵营camp=1红方camp=0蓝方
self.camp = camp # Rank为吃子顺序从0到6依次为鼠、鹰、狐、狼、豹、狮、象
if self.camp: # camp=1红方
self.img = r
else:
self.img = b
self.rank = Rank
self.x = self.y = 0
self.next = [] # 可走位置的集合
self.eat = [] # 可吃位置的集合
self.pro = [] # 不可走位置的集合
def hint(self): # 显示可走路径
for i, j in self.next:
htrect.center = pos[i][j].center
screen.blit(ht, htrect)
for i, j in self.eat:
screen.blit(cpht, pos[i][j])
def next_step(self, grid): # 步法
pass
def eagle_next(self, grid): # 老鹰走法
for i in range(self.x + 1, 9): # 向右飞
if grid[i][self.y]:
if grid[i][self.y].camp != self.camp and (grid[i][self.y].rank <= self.rank or
(((i, self.y) in Blue_trap or (i, self.y) in Red_trap) and grid[i][
self.y].camp == 1) or
(((i, self.y) in Blue_trap or (i, self.y) in Red_trap) and grid[i][
self.y].camp == 0)) and (i, self.y) not in river:
self.eat.append([i, self.y])
else:
self.pro.append([i, self.y])
break
if (i, self.y) in Blue_trap or (i, self.y) in Red_trap:
self.next.append([i, self.y])
break
# 判断老鹰不能进河不能进入本方兽穴
if (i, self.y) not in river and (
((i, self.y) not in Blue_home and self.camp == 0) or ((i, self.y) not in Red_home and self.camp == 1)):
self.next.append([i, self.y])
for i in range(self.x - 1, -1, -1): # 向左飞
if grid[i][self.y]:
if grid[i][self.y].camp != self.camp and (grid[i][self.y].rank <= self.rank or
(((i, self.y) in Blue_trap or (i, self.y) in Red_trap) and grid[i][
self.y].camp == 1) or
(((i, self.y) in Blue_trap or (i, self.y) in Red_trap) and grid[i][
self.y].camp == 0)) and (i, self.y) not in river:
self.eat.append([i, self.y])
else:
self.pro.append([i, self.y])
break
if (i, self.y) in Blue_trap or (i, self.y) in Red_trap:
self.next.append([i, self.y])
break
if (i, self.y) not in river and (
((i, self.y) not in Blue_home and self.camp == 0) or ((i, self.y) not in Red_home and self.camp == 1)):
self.next.append([i, self.y])
for i in range(self.y + 1, 7): # 向上飞
if grid[self.x][i]:
if grid[self.x][i].camp != self.camp and (grid[self.x][i].rank <= self.rank or
(((self.x, i) in Blue_trap or (self.x, i) in Red_trap) and
grid[self.x][i].camp == 1) or
(((self.x, i) in Blue_trap or (self.x, i) in Red_trap) and
grid[self.x][i].camp == 0)) and (self.x, i) not in river:
self.eat.append([self.x, i])
else:
self.pro.append([self.x, i])
break
if (self.x, i) in Blue_trap or (self.x, i) in Red_trap:
self.next.append([self.x, i])
break
if (self.x, i) not in river and (
((self.x, i) not in Blue_home and self.camp == 0) or ((self.x, i) not in Red_home and self.camp == 1)):
self.next.append([self.x, i])
for i in range(self.y - 1, -1, -1): # 向下飞
if grid[self.x][i]:
if grid[self.x][i].camp != self.camp and (grid[self.x][i].rank <= self.rank or
(((self.x, i) in Blue_trap or (self.x, i) in Red_trap) and
grid[self.x][i].camp == 1) or
(((self.x, i) in Blue_trap or (self.x, i) in Red_trap) and
grid[self.x][i].camp == 0)) and (self.x, i) not in river:
self.eat.append([self.x, i])
else:
self.pro.append([self.x, i])
break
if (self.x, i) in Blue_trap or (self.x, i) in Red_trap:
self.next.append([self.x, i])
break
if (self.x, i) not in river and (
((self.x, i) not in Blue_home and self.camp == 0) or ((self.x, i) not in Red_home and self.camp == 1)):
self.next.append([self.x, i])
def lion_next(self, grid): # 狮子跳河
tx, ty = self.x, self.y
i = 1 # 向右走
if is_chess_in_board(tx + i, ty):
while (tx + i, ty) in river:
if grid[tx + i][ty]:
break
i += 1
if grid[tx + i][ty]:
if grid[tx + i][ty].camp != self.camp and (grid[tx + i][ty].rank <= self.rank or
(((tx + i, ty) in Blue_trap or (tx + i, ty) in Red_trap) and
grid[tx + i][ty].camp == 1) or
(((tx + i, ty) in Blue_trap or (tx + i, ty) in Red_trap) and
grid[tx + i][ty].camp == 0)) and (tx + i, ty) not in river:
self.eat.append([tx + i, ty])
else:
self.pro.append([tx + i, ty])
# 判断狮子不能进入己方洞穴
elif ((tx + i, ty) not in Blue_home and self.camp == 0) or ((tx + i, ty) not in Red_home and self.camp == 1):
self.next.append([tx + i, ty])
i = -1 # 向左走
if is_chess_in_board(tx + i, ty):
while (tx + i, ty) in river:
if grid[tx + i][ty]:
break
i -= 1
if grid[tx + i][ty]:
if grid[tx + i][ty].camp != self.camp and (grid[tx + i][ty].rank <= self.rank or
(((tx + i, ty) in Blue_trap or (tx + i, ty) in Red_trap) and
grid[tx + i][ty].camp == 1) or
(((tx + i, ty) in Blue_trap or (tx + i, ty) in Red_trap) and
grid[tx + i][ty].camp == 0)) and (tx + i, ty) not in river:
self.eat.append([tx + i, ty])
else:
self.pro.append([tx + i, ty])
elif ((tx + i, ty) not in Blue_home and self.camp == 0) or ((tx + i, ty) not in Red_home and self.camp == 1):
self.next.append([tx + i, ty])
i = 1 # 向上走
if is_chess_in_board(tx, ty + i):
while (tx, ty + i) in river:
if grid[tx][ty + i]:
break
i += 1
if grid[tx][ty + i]:
if grid[tx][ty + i].camp != self.camp and (grid[tx][ty + i].rank <= self.rank or
(((tx, ty + i) in Blue_trap or (tx, ty + i) in Red_trap) and
grid[tx][ty + i].camp == 1) or
(((tx, ty + i) in Blue_trap or (tx, ty + i) in Red_trap) and
grid[tx][ty + i].camp == 0)) and (tx, ty + i) not in river:
self.eat.append([tx, ty + i])
else:
self.pro.append([tx, ty + i])
elif (((tx, ty + i) not in Blue_home and self.camp == 0) or ((tx, ty + i) not in Red_home and self.camp == 1)):
self.next.append([tx, ty + i])
i = -1 # 向下走
if is_chess_in_board(tx, ty + i):
while (tx, ty + i) in river:
if grid[tx][ty + i]:
break
i -= 1
if grid[tx][ty + i]:
if grid[tx][ty + i].camp != self.camp and (grid[tx][ty + i].rank <= self.rank or
(((tx, ty + i) in Blue_trap or (tx, ty + i) in Red_trap) and
grid[tx][ty + i].camp == 1) or
(((tx, ty + i) in Blue_trap or (tx, ty + i) in Red_trap) and
grid[tx][ty + i].camp == 0)) and (tx, ty + i) not in river:
self.eat.append([tx, ty + i])
else:
self.pro.append([tx, ty + i])
elif (((tx, ty + i) not in Blue_home and self.camp == 0) or ((tx, ty + i) not in Red_home and self.camp == 1)):
self.next.append([tx, ty + i])
# 非特殊棋子
class Elephant(Base): # 大象
def __init__(self, camp):
Base.__init__(self, camp, Bel, Rel, 6)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for i, j in dir:
tx, ty = self.x + i, self.y + j
if is_chess_in_board(tx, ty):
if (tx, ty) not in river:
if grid[tx][ty]:
# 判断可吃,但对方不能为老鼠
if grid[tx][ty].camp != self.camp and (grid[tx][ty].rank <= self.rank or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 1) or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 0)) and (tx, ty) not in river and \
grid[tx][ty].rank != 0:
self.eat.append([tx, ty])
else:
self.pro.append([tx, ty])
# 不能进入本方兽穴
elif ((tx, ty) not in Blue_home and self.camp == 0) or ((tx, ty) not in Red_home and self.camp == 1):
self.next.append([tx, ty])
class Lion(Base): # 狮子基本走法
def __init__(self, camp):
Base.__init__(self, camp, Bl, Rl, 5)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
self.lion_next(grid)
class Leopard(Base): # 豹子
def __init__(self, camp):
Base.__init__(self, camp, Ble, Rle, 4)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for i, j in dir:
tx, ty = self.x + i, self.y + j
if is_chess_in_board(tx, ty):
if (tx, ty) not in river:
if grid[tx][ty]:
if grid[tx][ty].camp != self.camp and (grid[tx][ty].rank <= self.rank or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 1) or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 0)) and (tx, ty) not in river:
self.eat.append([tx, ty])
else:
self.pro.append([tx, ty])
elif (((tx, ty) not in Blue_home and self.camp == 0) or ((tx, ty) not in Red_home and self.camp == 1)):
self.next.append([tx, ty])
class Wolf(Base): # 狼
def __init__(self, camp):
Base.__init__(self, camp, Bw, Rw, 3)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for i, j in dir:
tx, ty = self.x + i, self.y + j
if is_chess_in_board(tx, ty):
if (tx, ty) not in river:
if grid[tx][ty]:
if grid[tx][ty].camp != self.camp and (grid[tx][ty].rank <= self.rank or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 1) or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 0)) and (tx, ty) not in river:
self.eat.append([tx, ty])
else:
self.pro.append([tx, ty])
elif ((tx, ty) not in Blue_home and self.camp == 0) or ((tx, ty) not in Red_home and self.camp == 1):
self.next.append([tx, ty])
class Fox(Base): # 狐狸
def __init__(self, camp):
Base.__init__(self, camp, Bf, Rf, 2)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
dir = [[-1, 0], [1, 0], [0, -1], [0, 1],
[-1, -1], [-1, 1], [1, -1], [1, 1]]
for i, j in dir:
tx, ty = self.x + i, self.y + j
if is_chess_in_board(tx, ty):
if (tx, ty) not in river:
if grid[tx][ty]:
if grid[tx][ty].camp != self.camp and (grid[tx][ty].rank <= self.rank or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 1) or
(((tx, ty) in Blue_trap or (tx, ty) in Red_trap) and grid[tx][
ty].camp == 0)) and (tx, ty) not in river:
self.eat.append([tx, ty])
else:
self.pro.append([tx, ty])
elif ((tx, ty) not in Blue_home and self.camp == 0) or ((tx, ty) not in Red_home and self.camp == 1):
self.next.append([tx, ty])
class Eagle(Base): # 老鹰
def __init__(self, camp):
Base.__init__(self, camp, Bea, Rea, 1)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
self.eagle_next(grid)
class Mouse(Base): # 老鼠
def __init__(self, camp):
Base.__init__(self, camp, Bm, Rm, 0)
def next_step(self, grid):
self.next = []
self.eat = []
self.pro = []
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for i, j in dir:
tx, ty = self.x + i, self.y + j
if is_chess_in_board(tx, ty):
if grid[tx][ty]:
if grid[tx][ty].camp != self.camp and (self.x, self.y) not in river and (
(grid[tx][ty].rank == 6 or grid[tx][ty].rank == 0)
or (((tx, ty) in Red_trap or (tx, ty) in Blue_trap) and grid[tx][ty].camp == 1)
or (((tx, ty) in Red_trap or (tx, ty) in Blue_trap) and grid[tx][ty].camp == 0)):
self.eat.append([tx, ty])
else:
self.pro.append([tx, ty])
elif ((tx, ty) not in Blue_home and self.camp == 0) or ((tx, ty) not in Red_home and self.camp == 1):
self.next.append([tx, ty])
# 导入背景音乐
file = r'.\Space - Just Blue.mp3'
pygame.mixer.init()
# 加载音乐文件
pygame.mixer.music.load(file)
# 开始播放音乐流
pygame.mixer.music.play()
# def game_start():
# 导入图片
size1 = 0.91
chessboard = pygame.transform.scale(pygame.image.load("backGround.png"), (1080 * size1 * sizel, 827 * size1 * sizel))
Bel = pygame.transform.scale(pygame.image.load("BElephant.jpg"), (ul, ul))
Rel = pygame.transform.scale(pygame.image.load("RElephant.jpg"), (ul, ul))
Bea = pygame.transform.scale(pygame.image.load("BEagle.jpg"), (ul, ul))
Rea = pygame.transform.scale(pygame.image.load("REagle.jpg"), (ul, ul))
Bf = pygame.transform.scale(pygame.image.load("BFox.jpg"), (ul, ul))
Rf = pygame.transform.scale(pygame.image.load("RFox.jpg"), (ul, ul))
Ble = pygame.transform.scale(pygame.image.load("BLeopard.jpg"), (ul, ul))
Rle = pygame.transform.scale(pygame.image.load("RLeopard.jpg"), (ul, ul))
Bl = pygame.transform.scale(pygame.image.load("BLion.jpg"), (ul, ul))
Rl = pygame.transform.scale(pygame.image.load("RLion.jpg"), (ul, ul))
Bw = pygame.transform.scale(pygame.image.load("BWolf.jpg"), (ul, ul))
Rw = pygame.transform.scale(pygame.image.load("RWolf.jpg"), (ul, ul))
Bm = pygame.transform.scale(pygame.image.load("BMouse.jpg"), (ul, ul))
Rm = pygame.transform.scale(pygame.image.load("RMouse.jpg"), (ul, ul))
ht = pygame.transform.scale(pygame.image.load("AimAt.png"), (44 * sizel, 44 * sizel))
htrect = ht.get_rect()
cpht = pygame.transform.scale(pygame.image.load("prey.png"), (108 * sizel, 108 * sizel))
grid = [] # 位置上有没有棋子
pos = []
occ = []
movable = False
for i in range(9):
grid.append([])
pos.append([])
occ.append([])
for j in range(9):
occ[i].append([])
grid[i].append(None)
recthere = Bl.get_rect()
recthere.left, recthere.top = (width - height) / 2 + ul * i, ul * j # 中心点计算位置
pos[i].append(recthere)
dir = (1, 0), (-1, 0), (0, 1), (0, -1) # 坐标存储
times = 1
lastmove = []
selected = False
chesslst = []
def scan():
tmp2 = []
for i in grid:
tmp = []
for j in i:
if j:
tmp.append(type(j))
yield type(j)
else:
tmp.append(j)
tmp2.append(tmp)
chesslst.append(tmp2)
def add(i, x, y):
i.x, i.y = x - 1, y - 1
grid[x - 1][y - 1] = i
# 左边棋子放置
add(Elephant(0), 3, 1)
add(Lion(0), 3, 4)
add(Leopard(0), 3, 5)
add(Wolf(0), 3, 3)
add(Fox(0), 2, 6)
add(Eagle(0), 2, 2)
add(Mouse(0), 3, 7)
# 右边棋子放置
add(Elephant(1), 7, 7)
add(Lion(1), 7, 4)
add(Leopard(1), 7, 3)
add(Wolf(1), 7, 5)
add(Fox(1), 8, 2)
add(Eagle(1), 8, 6)
add(Mouse(1), 7, 1)
scan()
refresh()
running = True
screen = pygame.display.set_mode(size)
def animate():
screen.blit(chessboard, [(width - height) / 2, 0])
if selected:
selected.hint()
for x, i in enumerate(grid):
for y, j in enumerate(i):
if j:
screen.blit(j.img, [(width - height) / 2 + ul * x, ul * y])
pygame.display.flip()
while running:
for event in pygame.event.get():
# 程序退出
if event.type == pygame.QUIT:
running = False
# 点击鼠标
elif event.type == pygame.MOUSEBUTTONDOWN:
mousex, mousey = pygame.mouse.get_pos() # 获取鼠标坐标
x = y = z = j = False
for y, i in enumerate(grid):
for z, j in enumerate(i):
if pos[y][z].collidepoint(mousex, mousey):
x = j
break
if pos[y][z].collidepoint(mousex, mousey):
break
if x is False:
continue
if selected:
if [y, z] in selected.next or [y, z] in selected.eat:
lastmove = []
selected.used = True
lastmove.append(copy(selected))
grid[y][z] = selected
grid[selected.x][selected.y] = None
grid[y][z].x, grid[y][z].y = y, z
lastmove.append(grid[y][z])
selected = False
times ^= 1
refresh()
tryout()
for i2 in occ:
for j2 in range(len(i2)):
i2[j2] = []
for i in grid:
for j in i:
if j:
for k, t in j.eat:
occ[k][t].append(j)
animate()
scanlst = scan()
camp = aniSet()
camp.update(scanlst)
if not movable:
if rd != 100:
print("BLue" if win == 2 else "RED", "check!!!")
my_font = pygame.font.SysFont("Consolas", 100)
time_surf = my_font.render("BLUE WIN!!!" if win == 2 else "RED WIN!!!", 1,
[255, 0, 0] if win == 1 else [0, 0, 255])
gor = time_surf.get_rect()
gor.center = width / 2, height / 2
screen.blit(time_surf, gor)
pygame.display.update()
running2 = True
while running2:
for event2 in pygame.event.get():
if event2.type == pygame.KEYDOWN:
if event2.key == pygame.K_ESCAPE:
_exit(0)
else:
print("平局", "check!!!")
my_font = pygame.font.SysFont("Consolas", 100)
time_surf = my_font.render("平局", 1, [255, 255, 255])
gor = time_surf.get_rect()
gor.center = width / 2, height / 2
screen.blit(time_surf, gor)
pygame.display.update()
running2 = True
while running2:
for event2 in pygame.event.get():
if event2.type == pygame.KEYDOWN:
if event2.key == pygame.K_ESCAPE:
_exit(0)
rd += 1
elif x:
if x.camp == times:
selected = x
else:
selected = False
else:
selected = False
else:
if x:
if x.camp == times:
selected = x
animate()
pygame.quit()

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Loading…
Cancel
Save