from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.label import Label
+from kivy.uix.popup import Popup
from kivy.graphics import Color, Rectangle
from kivy.utils import platform
from kivy.clock import Clock
title = "Peter's thread snake"
def __init__(self):
- self.levels = LevelList()
super(GameApp, self).__init__()
+ self.levels = LevelList()
def build(self):
root = ScrollView(size_hint=(None, None))
if platform() == 'android':
window.fullscreen = True
self.root.size = window.size
+ errors = self.levels.get_errors()
+ if errors:
+ popup = Popup(title='Levels excluded',
+ content=Label(text='\n'.join(errors)),
+ size_hint=(.5, .5))
+ popup.open()
self.make_intro()
def make_intro(self):
def __init__(self):
self.levels = []
+ 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)
except RuntimeError as err:
- raise RuntimeError(
+ self.errors.append(
'Invalid level %s in level_list: %s' % (line, err))
- self.levels.append(level)
else:
- raise RuntimeError('Level list includes non-existant level %s' % line)
+ self.errors.append(
+ 'Level list includes non-existant level %s' % line)
level_list.close()
self._cur_level = 0
else:
return None
+ def get_errors(self):
+ return self.errors
+
def advance_to_next_level(self):
self._cur_level += 1
return self.get_current_level()