From 19fc29009d20801a6d8960292e28f479d0e2dd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 12 Apr 2022 00:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=88=86=E7=82=B8=E5=90=8E?= =?UTF-8?q?=E5=83=B5=E5=B0=B8=E9=BB=91=E8=89=B2=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 6 ++++++ source/constants.py | 3 ++- source/state/level.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 96fe589..531008a 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -8,6 +8,8 @@ class Map(): def __init__(self, width, height): self.width = width self.height = height + # 要把记录信息改成元组的话这里又得改 + # 而且不同场地还不一样 self.map = [[0 for x in range(self.width)] for y in range(self.height)] def isValid(self, map_x, map_y): @@ -16,9 +18,13 @@ class Map(): return False return True + # 判断能否种植 def isMovable(self, map_x, map_y): # 目前没有南瓜头,所以用是否为空判断 # 可将南瓜头新定义一个状态(如:2),基于此进一步判断 + # 应当改成元组,保存南瓜头、花盆、睡莲等状态 + # 当然,不用元组的话字符串也行,但是得把判断植物写在母函数中,并且需要更多参数 + # 这样返回的就是一个具体信息,而非bool值了 return (self.map[map_y][map_x] == c.MAP_EMPTY) def getMapIndex(self, x, y): diff --git a/source/constants.py b/source/constants.py index 7f83ea1..c2984d5 100755 --- a/source/constants.py +++ b/source/constants.py @@ -67,13 +67,14 @@ INIT_SUN_NAME = 'init_sun_value' ZOMBIE_LIST = 'zombie_list' MAP_EMPTY = 0 -MAP_EXIST = 1 +MAP_COMMON_PLANT = 1 # 只有南瓜头 MAP_PUMPKIN_ONLY = 2 # 有南瓜头和其他植物 MAP_PUMPKIN_WITH = 3 # 可能还需要给咖啡豆定义一个状态,但是这个最好是在种植的时候判断那里是否有睡眠的蘑菇 # 睡莲与花盆更为特殊,可能需要更复杂的定义 +# 可能可以用元组或者字符串 BACKGROUND_OFFSET_X = 220 MAP_OFFSET_X = 35 diff --git a/source/state/level.py b/source/state/level.py index 25df602..886cda3 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -140,7 +140,7 @@ class Level(tool.State): print('initBowlingMap') for x in range(3, self.map.width): for y in range(self.map.height): - self.map.setMapGridType(x, y, c.MAP_EXIST) + self.map.setMapGridType(x, y, c.MAP_COMMON_PLANT) def initState(self): # 小游戏才有CHOOSEBAR_TYPE @@ -524,7 +524,7 @@ class Level(tool.State): self.menubar.deleateCard(self.select_plant) if self.bar_type != c.CHOSSEBAR_BOWLING: - self.map.setMapGridType(map_x, map_y, c.MAP_EXIST) + self.map.setMapGridType(map_x, map_y, c.MAP_COMMON_PLANT) self.removeMouseImage() #print('addPlant map[%d,%d], grid pos[%d, %d] pos[%d, %d]' % (map_x, map_y, x, y, pos[0], pos[1]))