diff --git a/source/constants.py b/source/constants.py index 8ab6161..71550f7 100755 --- a/source/constants.py +++ b/source/constants.py @@ -162,7 +162,7 @@ MAP_UNAVAILABLE = 'unavailable' # 指完全不能种植物的地方,包括无 # 不喜欢用深拷贝,直接改用函数表示,需要时直接调用该函数生成即可 # 由于同一格显然不可能种两个相同的植物,所以用集合 def INIT_MAP_GRID(PLOT_TYPE): - return {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:POLT_TYPE} + return {MAP_PLANT:set(), MAP_SLEEP:False, MAP_PLOT_TYPE:PLOT_TYPE} # 地图相关像素数据 BACKGROUND_OFFSET_X = 220 diff --git a/source/tool.py b/source/tool.py index 5d1249e..4248d7d 100755 --- a/source/tool.py +++ b/source/tool.py @@ -14,7 +14,7 @@ class State(): self.done = False # false 代表未做完 self.next = None # 表示这个状态退出后要转到的下一个状态 self.persist = {} # 在状态间转换时需要传递的数据 - + # 当从其他状态进入这个状态时,需要进行的初始化操作 @abstractmethod def startup(self, current_time, persist): @@ -189,16 +189,14 @@ def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '. # 用于消除文件边框影响 def loadZombieImageRect(): file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'zombie.json') - f = open(file_path) - data = json.load(f) - f.close() + with open(file_path) as f: + data = json.load(f) return data[c.ZOMBIE_IMAGE_RECT] def loadPlantImageRect(): file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'plant.json') - f = open(file_path) - data = json.load(f) - f.close() + with open(file_path) as f: + data = json.load(f) return data[c.PLANT_IMAGE_RECT] pg.init()