self.levels = LevelList()
self.game = None
+ def build_config(self, config):
+ config.setdefaults('bane', {
+ 'start_level': 'levels/level1.txt',
+ 'sound': 'True'
+ })
+
+ def build_settings(self, settings):
+ config_json = """[
+ { "type": "title",
+ "title": "Bane's Befuddlement"
+ },
+
+ { "type": "options",
+ "title": "Start Level",
+ "desc": "Level to start at",
+ "section": "bane",
+ "key": "start_level",
+ "options": ["%s"] },
+
+ { "type": "bool",
+ "title": "Sound",
+ "desc": "Enable sound",
+ "section": "bane",
+ "key": "sound"
+ }
+ ]""" % '", "'.join(self.levels.get_level_names())
+ settings.add_json_panel("Bane's Befuddlement",
+ self.config, data=config_json)
+
def build(self):
root = ScrollView(size_hint=(None, None))
+ level_name = self.config.getdefault('bane', 'start_level', None)
+ if level_name:
+ self.levels.set_level_to(level_name)
return root
def on_start(self):
LEVELS = 'level_list'
def __init__(self):
- self.levels = []
- self.errors = []
+ self._levels = []
+ self._level_names = []
+ self._errors = []
level_list = load(self.LEVELS)
for line in level_list:
line = line.strip()
level_file.close()
try:
level.validate()
- self.levels.append(level)
+ self._levels.append(level)
+ self._level_names.append(line)
except RuntimeError as err:
- self.errors.append(
+ self._errors.append(
'Invalid level %s in level_list: %s' % (line, err))
else:
- self.errors.append(
+ self._errors.append(
'Level list includes non-existant level %s' % line)
level_list.close()
self._cur_level = 0
def get_current_level(self):
- if self._cur_level < len(self.levels):
- return self.levels[self._cur_level]
+ if self._cur_level < len(self._levels):
+ return self._levels[self._cur_level]
else:
return None
def get_errors(self):
- return self.errors
+ return self._errors
+
+ def get_level_names(self):
+ return self._level_names
+
+ def set_level_to(self, level_name):
+ if level_name in self._level_names:
+ self._cur_level = self._level_names.index(level_name)
def advance_to_next_level(self):
self._cur_level += 1