示例#1
0
    def reload_gui(self):
        if self.gui_container is None:
            return
        gui_elements = list()
        #Update existing elements
        index = 0
        for button in list(self.gui_container.content):
            element = button.element
            count = self.content[button.element]
            if (element in self.content.keys() and
                button.count != count):
                new_btn = Gui.MoleculeButton(element, count, self.get_callback)
                self.gui_container.remove(button)
                offset =len(self.gui_container.content)
                self.gui_container.add(new_btn, offset - index)
            if element not in self.content.keys():
                self.gui_container.remove(button)
            index += 1
            gui_elements.append(button.element)

        #Add new elements
        for element, count in self.content.items():
            if element in gui_elements:
                continue
            button = Gui.MoleculeButton(element, count, self.get_callback)
            self.gui_container.add(button)
示例#2
0
 def update(self):
     self.space.step(1 / 120.0)
     if self.victory() and self.finished == False:
         Gui.create_popup(
             self.window, self.batch, "Congratulation, you finished the level", on_escape=self.window.switch_level
         )
         self.finished = True
     for element in self.elements:
         element.update()
     for area in self.areas:
         area.update()
示例#3
0
 def update(self):
     self.space.step(1 / 120.0)
     if self.victory() and self.finished == False:
         Gui.create_popup(self.window,
                          self.batch,
                          "Congratulation, you finished the level",
                          on_escape=self.window.switch_level)
         self.finished = True
     for element in self.elements:
         element.update()
     for area in self.areas:
         area.update()
示例#4
0
文件: Game.py 项目: Norberg/molecule
 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)
示例#5
0
文件: Game.py 项目: Norberg/molecule
 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)
示例#6
0
    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.M:
            import objgraph

            objgraph.show_growth()
            m = objgraph.by_type("Molecule")
            print("nr of Molecule:", len(m))
            # for n in m:
            #    objgraph.show_backrefs(n)
        elif symbol == pyglet.window.key.ESCAPE:
            self.window.close()
        elif symbol == pyglet.window.key.S:
            Gui.create_popup(self.window, self.batch, "Skipping level, Cheater!", on_escape=self.window.switch_level)
        elif symbol == pyglet.window.key.R:
            self.window.reset_level()
        elif symbol == pyglet.window.key.D:
            self.window.DEBUG_GRAPHICS = not self.window.DEBUG_GRAPHICS
示例#7
0
 def on_key_press(self, symbol, modifiers):
     if symbol == pyglet.window.key.M:
         import objgraph
         objgraph.show_growth()
         m = objgraph.by_type("Molecule")
         print("nr of Molecule:", len(m))
         #for n in m:
         #    objgraph.show_backrefs(n)
     elif symbol == pyglet.window.key.ESCAPE:
         self.window.close()
     elif symbol == pyglet.window.key.S:
         Gui.create_popup(self.window,
                          self.batch,
                          "Skipping level, Cheater!",
                          on_escape=self.window.switch_level)
     elif symbol == pyglet.window.key.R:
         self.window.reset_level()
     elif symbol == pyglet.window.key.D:
         self.window.DEBUG_GRAPHICS = not self.window.DEBUG_GRAPHICS
     elif symbol == pyglet.window.key.H:
         hint = self.window.level.cml.hint
         Gui.create_popup(self.window, self.batch, hint)