规范常数表达
This commit is contained in:
parent
2bca7f1d65
commit
4e055429b0
@ -10,27 +10,27 @@ class Map():
|
|||||||
self.width = c.GRID_POOL_X_LEN
|
self.width = c.GRID_POOL_X_LEN
|
||||||
self.height = c.GRID_POOL_Y_LEN
|
self.height = c.GRID_POOL_Y_LEN
|
||||||
self.gridHeightSize = c.GRID_POOL_Y_SIZE
|
self.gridHeightSize = c.GRID_POOL_Y_SIZE
|
||||||
self.map = [[(c.INIT_MAP_GRID(c.MAP_GRASS), c.INIT_MAP_GRID(c.MAP_WATER))[y in {2, 3}] for x in range(self.width)] for y in range(self.height)]
|
self.map = [[(self.initMapGrid(c.MAP_GRASS), self.initMapGrid(c.MAP_WATER))[y in {2, 3}] for x in range(self.width)] for y in range(self.height)]
|
||||||
elif self.background_type in c.ON_ROOF_BACKGROUNDS:
|
elif self.background_type in c.ON_ROOF_BACKGROUNDS:
|
||||||
self.width = c.GRID_ROOF_X_LEN
|
self.width = c.GRID_ROOF_X_LEN
|
||||||
self.height = c.GRID_ROOF_Y_LEN
|
self.height = c.GRID_ROOF_Y_LEN
|
||||||
self.gridHeightSize = c.GRID_ROOF_Y_SIZE
|
self.gridHeightSize = c.GRID_ROOF_Y_SIZE
|
||||||
self.map = [[c.INIT_MAP_GRID(c.MAP_TILE) for x in range(self.width)] for y in range(self.height)]
|
self.map = [[self.initMapGrid(c.MAP_TILE) for x in range(self.width)] for y in range(self.height)]
|
||||||
elif self.background_type == c.BACKGROUND_SINGLE:
|
elif self.background_type == c.BACKGROUND_SINGLE:
|
||||||
self.width = c.GRID_X_LEN
|
self.width = c.GRID_X_LEN
|
||||||
self.height = c.GRID_Y_LEN
|
self.height = c.GRID_Y_LEN
|
||||||
self.gridHeightSize = c.GRID_Y_SIZE
|
self.gridHeightSize = c.GRID_Y_SIZE
|
||||||
self.map = [[(c.INIT_MAP_GRID(c.MAP_UNAVAILABLE), c.INIT_MAP_GRID(c.MAP_GRASS))[y == 2] for x in range(self.width)] for y in range(self.height)]
|
self.map = [[(self.initMapGrid(c.MAP_UNAVAILABLE), self.initMapGrid(c.MAP_GRASS))[y == 2] for x in range(self.width)] for y in range(self.height)]
|
||||||
elif self.background_type == c.BACKGROUND_TRIPLE:
|
elif self.background_type == c.BACKGROUND_TRIPLE:
|
||||||
self.width = c.GRID_X_LEN
|
self.width = c.GRID_X_LEN
|
||||||
self.height = c.GRID_Y_LEN
|
self.height = c.GRID_Y_LEN
|
||||||
self.gridHeightSize = c.GRID_Y_SIZE
|
self.gridHeightSize = c.GRID_Y_SIZE
|
||||||
self.map = [[(c.INIT_MAP_GRID(c.MAP_UNAVAILABLE), c.INIT_MAP_GRID(c.MAP_GRASS))[y in {1, 2, 3}] for x in range(self.width)] for y in range(self.height)]
|
self.map = [[(self.initMapGrid(c.MAP_UNAVAILABLE), self.initMapGrid(c.MAP_GRASS))[y in {1, 2, 3}] for x in range(self.width)] for y in range(self.height)]
|
||||||
else:
|
else:
|
||||||
self.width = c.GRID_X_LEN
|
self.width = c.GRID_X_LEN
|
||||||
self.height = c.GRID_Y_LEN
|
self.height = c.GRID_Y_LEN
|
||||||
self.gridHeightSize = c.GRID_Y_SIZE
|
self.gridHeightSize = c.GRID_Y_SIZE
|
||||||
self.map = [[c.INIT_MAP_GRID(c.MAP_GRASS) for x in range(self.width)] for y in range(self.height)]
|
self.map = [[self.initMapGrid(c.MAP_GRASS) for x in range(self.width)] for y in range(self.height)]
|
||||||
|
|
||||||
def isValid(self, map_x, map_y):
|
def isValid(self, map_x, map_y):
|
||||||
if (map_x < 0 or map_x >= self.width or
|
if (map_x < 0 or map_x >= self.width or
|
||||||
@ -38,6 +38,12 @@ class Map():
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# 地图单元格状态
|
||||||
|
# 注意是可变对象,不能直接引用
|
||||||
|
# 由于同一格显然不可能种两个相同的植物,所以用集合
|
||||||
|
def initMapGrid(PLOT_TYPE):
|
||||||
|
return {c.MAP_PLANT:set(), c.MAP_SLEEP:False, c.MAP_PLOT_TYPE:PLOT_TYPE}
|
||||||
|
|
||||||
# 判断位置是否可用
|
# 判断位置是否可用
|
||||||
# 暂时没有写紫卡植物的判断方法
|
# 暂时没有写紫卡植物的判断方法
|
||||||
# 由于紫卡植物需要移除以前的植物,所以可用另外定义一个函数
|
# 由于紫卡植物需要移除以前的植物,所以可用另外定义一个函数
|
||||||
|
|||||||
@ -182,12 +182,6 @@ MAP_GRASS = "grass"
|
|||||||
MAP_WATER = "water"
|
MAP_WATER = "water"
|
||||||
MAP_TILE = "tile" # 指屋顶上的瓦片
|
MAP_TILE = "tile" # 指屋顶上的瓦片
|
||||||
MAP_UNAVAILABLE = "unavailable" # 指完全不能种植物的地方,包括无草皮的荒地和坚果保龄球等红线右侧
|
MAP_UNAVAILABLE = "unavailable" # 指完全不能种植物的地方,包括无草皮的荒地和坚果保龄球等红线右侧
|
||||||
# 地图单元格状态
|
|
||||||
# 注意是可变对象,不能直接引用
|
|
||||||
# 不喜欢用深拷贝,直接改用函数表示,需要时直接调用该函数生成即可
|
|
||||||
# 由于同一格显然不可能种两个相同的植物,所以用集合
|
|
||||||
def INIT_MAP_GRID(PLOT_TYPE):
|
|
||||||
return {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:PLOT_TYPE}
|
|
||||||
|
|
||||||
# 地图相关像素数据
|
# 地图相关像素数据
|
||||||
BACKGROUND_OFFSET_X = 220
|
BACKGROUND_OFFSET_X = 220
|
||||||
@ -646,6 +640,7 @@ for _part1 in (DUCKY_TUBE_ZOMBIE, CONEHEAD_DUCKY_TUBE_ZOMBIE, BUCKETHEAD_DUCKY_T
|
|||||||
for _part2 in ("", "Attack", "Swim"):
|
for _part2 in ("", "Attack", "Swim"):
|
||||||
ZOMBIE_RECT[f"{_part1}{_part2}"] = {"x":55, "width":105}
|
ZOMBIE_RECT[f"{_part1}{_part2}"] = {"x":55, "width":105}
|
||||||
|
|
||||||
|
|
||||||
# 音效
|
# 音效
|
||||||
def _getSound(filename):
|
def _getSound(filename):
|
||||||
return pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,"resources", "sound", filename))
|
return pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,"resources", "sound", filename))
|
||||||
@ -696,7 +691,7 @@ SOUNDS = ( # 程序交互等
|
|||||||
SOUND_WIN := _getSound("win.ogg"),
|
SOUND_WIN := _getSound("win.ogg"),
|
||||||
SOUND_SCREAM := _getSound("scream.ogg"),
|
SOUND_SCREAM := _getSound("scream.ogg"),
|
||||||
SOUND_CANNOT_CHOOSE_WARNING := _getSound("cannotChooseWarning.ogg"),
|
SOUND_CANNOT_CHOOSE_WARNING := _getSound("cannotChooseWarning.ogg"),
|
||||||
SOUND_FINAL_FANFARE := _getSound("finalfanfare.ogg")
|
SOUND_FINAL_FANFARE := _getSound("finalfanfare.ogg"),
|
||||||
)
|
)
|
||||||
|
|
||||||
# 记录本地存储文件初始值
|
# 记录本地存储文件初始值
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user