marblexu/PythonPlantsVsZombies

No such file or directory: 'source\\data\\map\\level_6.json'

tscswcn opened this issue · 2 comments

Traceback (most recent call last):
File "main.py", line 5, in
main()
File "E:\PythonPlantsVsZombies-master\source\main.py", line 14, in main
game.main()
File "E:\PythonPlantsVsZombies-master\source\tool.py", line 82, in main
self.update()
File "E:\PythonPlantsVsZombies-master\source\tool.py", line 54, in update
self.flip_state()
File "E:\PythonPlantsVsZombies-master\source\tool.py", line 64, in flip_state
self.state.startup(self.current_time, persist)
File "E:\PythonPlantsVsZombies-master\source\state\level.py", line 21, in startup
self.loadMap()
File "E:\PythonPlantsVsZombies-master\source\state\level.py", line 28, in loadMap
f = open(file_path)
FileNotFoundError: [Errno 2] No such file or directory: 'source\data\map\level_6.json'

因为目前level_5.json 是最后一关,代码里没有加判断是否是最后一关,所以继续去读取下一关level_6.json的文件,但是不存在level_6.json文件,然后出错。

Was this bug fixed? I faced this bug when c.LEVEL_NUM == 5.
After inspecting the codes, I changed line of add 1 to c.LEVEL_NUM to ↓↓

def checkGameState(self):                                                                                                                                                           
         if self.checkVictory():
             if self.game_info[c.LEVEL_NUM] < 5:
                 self.game_info[c.LEVEL_NUM] += 1
             self.next = c.GAME_VICTORY
             self.done = True

, then the games worked well as c.LEVEL_NUM == 1.