def testDestroyElements(self): levels = Levels("data/levels", window=WindowMock()) l = levels.next_level() batch = pyglet.graphics.Batch() l.elements.extend( Universe.create_elements(l.space, ["O2(g)", "O2(g)", "CH4(g)"], batch, None))
def testDestroyElements(self): levels = Levels("data/levels", window=WindowMock()) l = levels.next_level() batch = pyglet.graphics.Batch() l.elements.extend(Universe.create_elements(l.space, ["O2(g)", "O2(g)", "CH4(g)"], batch, None))
def testLevels(self): levels = Levels("data/levels", window=WindowMock()) l = levels.next_level() expected = ['H+(g)', 'O(g)', 'O(g)', 'H+(g)', 'P(g)', 'F(g)', 'Al(s)'] self.assertEqual(l.cml.molecules, expected) self.assertEqual(l.cml.victory_condition, ["H2O"]) self.assertEqual(l.cml.objective, "Create a water molecule") self.assertEqual(l.cml.hint, "H + H + O => H2O") self.assertEqual(l.victory(), False) batch = pyglet.graphics.Batch() l.elements.extend( Universe.create_elements(l.space, "H2O(g)", batch, None)) victory_effect = l.hud.horizontal.victory victory_effect.put_element(l.elements.pop()) self.assertEqual(l.victory(), True) l = levels.next_level() expected = [ 'H+(g)', 'O(g)', 'O(g)', 'H+(g)', 'OH-(aq)', 'CO2(g)', 'CH4(g)' ] self.assertEqual(l.cml.molecules, expected) self.assertEqual(l.cml.victory_condition, ['CO', 'H2', 'H2', 'H2']) self.assertEqual(l.cml.objective, "Create a CO and 3 H2 molecules") self.assertEqual(l.cml.hint, "H2O + CH4 + Heat => CO + 3H2") levels.current_level = 1000 l = levels.next_level() self.assertEqual(l, None)
def testLevels(self): levels = Levels("data/levels", window=WindowMock()) l = levels.next_level() expected = ['H+(g)', 'O(g)', 'O(g)', 'H+(g)', 'P(g)', 'F(g)', 'Al(s)'] self.assertEqual(l.cml.molecules, expected) self.assertEqual(l.cml.victory_condition, ["H2O"]) self.assertEqual(l.cml.objective, "Create a water molecule") self.assertEqual(l.cml.hint, "H + H + O => H2O") self.assertEqual(l.victory(), False) batch = pyglet.graphics.Batch() l.elements.extend(Universe.create_elements(l.space, "H2O(g)", batch, None)) victory_effect = l.hud.horizontal.victory victory_effect.put_element(l.elements.pop()) self.assertEqual(l.victory(), True) l = levels.next_level() expected = ['H+(g)', 'O(g)', 'O(g)', 'H+(g)', 'OH-(aq)', 'CO2(g)', 'CH4(g)'] self.assertEqual(l.cml.molecules, expected) self.assertEqual(l.cml.victory_condition, ['CO', 'H2', 'H2', 'H2']) self.assertEqual(l.cml.objective, "Create a CO and 3 H2 molecules") self.assertEqual(l.cml.hint, "H2O + CH4 + Heat => CO + 3H2") levels.current_level = 1000 l = levels.next_level() self.assertEqual(l, None)
def testAllLevels(self): levels = Levels("data/levels", window=WindowMock()) for level in levels.level_iter(): self.assertIsNotNone(level.cml.objective) self.assertEqual(level.victory(), False)
def getLevel1(): levels = Levels("data/levels", window=WindowMock()) level1 = levels.next_level() return level1
def start(self): pyglet.gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0) self.levels = Levels("data/levels", Config.current.level, window=self) self.switch_level() pyglet.clock.schedule_interval(self.update, 1/100.0)
class Game(pyglet.window.Window): def __init__(self): config = self.create_config() fullscreen = Config.current.fullscreen resizable = Config.current.resizable width = Config.current.width height = Config.current.height if fullscreen: width = None height = None super(Game, self).__init__(caption="Molecule", config=config, vsync=True, resizable=resizable, fullscreen=fullscreen, width=width, height=height) self.init_pyglet() self.DEBUG_GRAPHICS = False self.level = None self.start() def create_config(self): platform = pyglet.window.get_platform() display = platform.get_default_display() screen = display.get_default_screen() try: template = pyglet.gl.Config(sample_buffers=1, samples=4, double_buffer=True) config = screen.get_best_config(template) except pyglet.window.NoSuchConfigException: print("Hardware does not support all features,", "fallback to just the basic features") config = pyglet.gl.Config(double_buffer=True) return config def start(self): pyglet.gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0) self.levels = Levels("data/levels", Config.current.level, window=self) self.switch_level() pyglet.clock.schedule_interval(self.update, 1/100.0) def init_pyglet(self): gl.glLineWidth(4) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) def update(self, dt): self.level.update() def on_draw(self): self.clear() self.batch.draw() if self.DEBUG_GRAPHICS: pymunk.pyglet_util.draw(self.space) def switch_level(self, level=None): """ Switch to level, if level=None switch to next level""" if self.level is not None: self.level.delete() if level is None: level = self.levels.next_level() if level is None: Gui.create_popup(self, self.batch, "Congratulation you have won the game!", on_escape=self.close) else: self.run_level(level) else: self.run_level(level) def run_level(self, level): self.batch = level.batch self.level = level self.space = level.space def reset_level(self): level = self.levels.get_current_level() self.switch_level(level)
class Game(pyglet.window.Window): def __init__(self): config = self.create_config() fullscreen = Config.current.fullscreen resizable = Config.current.resizable width = Config.current.width height = Config.current.height if fullscreen: width = None height = None super(Game, self).__init__(caption="Molecule", config=config, vsync=True, resizable=resizable, fullscreen=fullscreen, width=width, height=height) self.init_pyglet() self.DEBUG_GRAPHICS = False self.level = None self.start() def create_config(self): display = pyglet.canvas.get_display(); screen = display.get_default_screen() try: template = pyglet.gl.Config(sample_buffers=1, samples=4, double_buffer=True) config = screen.get_best_config(template) except pyglet.window.NoSuchConfigException: print("Hardware does not support all features,", "fallback to just the basic features") config = pyglet.gl.Config(double_buffer=True) return config def start(self): pyglet.gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0) self.levels = Levels("data/levels", Config.current.level, window=self) self.switch_level() pyglet.clock.schedule_interval(self.update, 1/100.0) def init_pyglet(self): gl.glLineWidth(4) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) def update(self, dt): self.level.update() def on_draw(self): self.clear() self.batch.draw() if self.DEBUG_GRAPHICS: pymunk.pyglet_util.draw(self.space) def switch_level(self, level=None): """ Switch to level, if level=None switch to next level""" if self.level is not None: self.level.delete() if level is None: level = self.levels.next_level() if level is None: Gui.create_popup(self, self.batch, "Congratulation you have won the game!", on_escape=self.close) else: self.run_level(level) else: self.run_level(level) def run_level(self, level): self.batch = level.batch self.level = level self.space = level.space def reset_level(self): level = self.levels.get_current_level() self.switch_level(level)