Move game validation to level_list
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 12:13:08 +0000 (14:13 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 12:13:08 +0000 (14:13 +0200)
erdslangetjie/__main__.py
erdslangetjie/level.py

index 5cd9b7fcc39de69995406e7b4f8615fe7ab6edde..71ef53b405cc46e9c6f5a8780109e6eaeac8abda 100644 (file)
@@ -25,7 +25,6 @@ class GameWindow(RelativeLayout):
     def __init__(self, level_list, app):
         self.level_list = level_list
         self.level_obj = self.level_list.get_current_level()
-        self.level_obj.validate()
         self.level_obj.load_tiles()
         self.tiles = {}
         self.view = app.root
@@ -207,7 +206,6 @@ class GameWindow(RelativeLayout):
         self.remove_widget(self.nemesis_tile)
         self.nemesis.reset_pos()
         if self.level_obj:
-            self.level_obj.validate()
             self.level_obj.load_tiles()
             self.player.pos = self.level_obj.enter_pos
             self.remove_widget(self.player_tile)
index b5dbe1343861f05958fd89d0c494d8e4f46d613c..e4bc0e09a58072ea9c28dccdd2e4f8a790d9a6fb 100644 (file)
@@ -241,8 +241,14 @@ class LevelList(object):
             line = line.strip()
             if os.path.exists(filepath(line)):
                 level_file = load(line)
-                self.levels.append(Level(level_file))
+                level = Level(level_file)
                 level_file.close()
+                try:
+                    level.validate()
+                except RuntimeError as err:
+                    raise RuntimeError(
+                            'Invalid level %s in level_list: %s' % (line, err))
+                self.levels.append(level)
             else:
                 raise RuntimeError('Level list includes non-existant level %s' % line)
         level_list.close()