예제 #1
0
 def __init__(self, setting):
     """Initialise the instance.
        @return: None"""
     super(PARPGApplication, self).__init__(setting)
     pychan.init(self.engine, debug = True)
     #self.engine.getModel(self)
     self.model = GameModel(self.engine, setting)
     self.model.maps_file = self._setting.get("PARPG", "MapsFile")
     self.model.readMapFiles()
     self.model.object_db_file = self._setting.get("PARPG", 
                                                   "ObjectDatabaseFile") 
     self.model.readObjectDB()
     self.model.agents_directory = self._setting.get("PARPG",
                                                     "AgentsDirectory") 
     self.model.getAgentImportFiles()
     self.model.all_agents_file = self._setting.get("PARPG", "AllAgentsFile")
     self.model.readAllAgents()
     self.model.dialogues_directory = self._setting.get("PARPG", 
                                                        "DialoguesDirectory")
     self.model.getDialogues()
     self.view = MainMenuView(self.engine, self.model)
     self.event_listener = EventListener(self.engine)
     self.controllers = []
     controller = MainMenuController(self.engine, 
                                                     self.view, 
                                                     self.model,
                                                     self)
     #controller.initHud()
     self.controllers.append(controller)
     self.listener = ApplicationListener(self.event_listener,
                                         self.engine, 
                                         self.view, 
                                         self.model)
예제 #2
0
class PARPGApplication(ApplicationBase):
    """Main Application class
       We use an MVC model model
       self.gamesceneview is our view,self.model is our model
       self.controller is the controller"""
       
    def __init__(self, setting):
        """Initialise the instance.
           @return: None"""
        super(PARPGApplication, self).__init__(setting)
        pychan.init(self.engine, debug = True)
        #self.engine.getModel(self)
        self.model = GameModel(self.engine, setting)
        self.model.maps_file = self._setting.get("PARPG", "MapsFile")
        self.model.readMapFiles()
        self.model.object_db_file = self._setting.get("PARPG", 
                                                      "ObjectDatabaseFile") 
        self.model.readObjectDB()
        self.model.agents_directory = self._setting.get("PARPG",
                                                        "AgentsDirectory") 
        self.model.getAgentImportFiles()
        self.model.all_agents_file = self._setting.get("PARPG", "AllAgentsFile")
        self.model.readAllAgents()
        self.model.dialogues_directory = self._setting.get("PARPG", 
                                                           "DialoguesDirectory")
        self.model.getDialogues()
        self.view = MainMenuView(self.engine, self.model)
        self.event_listener = EventListener(self.engine)
        self.controllers = []
        controller = MainMenuController(self.engine, 
                                                        self.view, 
                                                        self.model,
                                                        self)
        #controller.initHud()
        self.controllers.append(controller)
        self.listener = ApplicationListener(self.event_listener,
                                            self.engine, 
                                            self.view, 
                                            self.model)
        #start_map = self._setting.get("PARPG", "Map")
        #self.model.changeMap(start_map)

    def createListener(self):
        """@return: None"""
        # already created in constructor
        # but if we don't put one here, Fife gets all fussy :-)
        pass
    
    def pushController(self, controller):
        """Adds a controller to the list to be the current active one."""
        self.controllers[-1].pause(True)
        self.controllers.append(controller)
    
    def popController(self):
        """Removes and returns the current active controller, unless its the last one"""
        ret_controller = None
        if self.controllers.count > 1:
            ret_controller = self.controllers.pop()
            self.controllers[-1].pause(False)
        ret_controller.onStop()
        return ret_controller
    
    def switchController(self, controller):
        """Clears the controller list and adds a controller to be the current active one"""
        for old_controller in self.controllers:
            old_controller.onStop()
        self.controllers = []
        self.controllers.append(controller)
    
    def _pump(self):
        """Main game loop.
           There are in fact 2 main loops, this one and the one in GameSceneView.
           @return: None"""
        if self.listener.quit:
            self.breakRequested = True #pylint: disable-msg=C0103
        else:
            for controller in self.controllers:
                controller.pump()