当前位置: 首页>>代码示例>>Python>>正文


Python GameState.deleteObject方法代码示例

本文整理汇总了Python中gamestate.GameState.deleteObject方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.deleteObject方法的具体用法?Python GameState.deleteObject怎么用?Python GameState.deleteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gamestate.GameState的用法示例。


在下文中一共展示了GameState.deleteObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GameModel

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import deleteObject [as 别名]
class GameModel(object):
    """GameModel holds the logic for the game.
       Since some data (object position and so forth) is held in the
       fife, and would be pointless to replicate, we hold a instance of
       the fife view here. This also prevents us from just having a
       function heavy controller."""
    ALL_AGENTS_KEY = "All"
    MAX_ID_NUMBER = 1000
    GENERIC_ITEM_GFX = "generic_item"
    DEFAULT_STAT_VALUE = 50
    
    def __init__(self, engine, settings):
        """Initialize the instance.
        @param engine: A fife.Engine object
        @type emgome: fife.Engine 
        @param setting: The applications settings
        @type setting: parpg.settings.Settings object
        @return: None"""
        self.settings = settings

        self.map_change = False
        self.load_saver = False
        self.savegame = None
        quests_directory = settings.get("parpg", "QuestsPath")
        #setup functions for the GameEnvironment        
        self.game_state = GameState(quests_dir=quests_directory)
        funcs = {
                 "moveObject":self.moveObject, 
                 "deleteObject":self.deleteObject, 
                 "putItemIntoContainer":container.put_item,
                 "equipItem":equip.equip, 
                 }
        self.game_state.funcs.update(funcs)
        self.pc_run = 1
        self.target_position = None
        self.target_map_name = None
        self.object_db = {}
        self.active_map = None
        self.map_files = {}
        self.agents = {}
        self.agents[self.ALL_AGENTS_KEY] = {}
        self.items = {}
        self.engine = engine
        self.fife_model = engine.getModel()

        # set values from settings
        maps_directory = settings.get("parpg", "MapsPath")
        self.game_state.maps_file = '/'.join([maps_directory,
                                              settings.get("parpg", "MapsFile")])
        self.all_agents_file = '/'.join([maps_directory,
                                         settings.get("parpg", "AllAgentsFile")])
        objects_directory = self.settings.get("parpg", "ObjectsPath")
        self.objects_directory = objects_directory
        self.object_db_file = '/'.join([objects_directory,
                                        settings.get("parpg", "ObjectDatabaseFile")])
        self.dialogue_directory = settings.get("parpg", "DialoguesPath")
        self.dialogues = {}
        self.agent_import_files = {}
        self.obj_loader = XMLObjectLoader(self.engine)
        # FIXME M. George Hansen 2011-06-06: character stats scripts aren't
        #     finished, unfortunately.
        # NOTE Beliar 2011-11-05 Activated the stats. Testing needed if it 
        # works correctly, or if they are still unfinished.
        primary_stats_file = (
            vfs.VFS.open('character_scripts/primary_stats.xml')
        )
        self.primary_stats = XmlSerializer.deserialize(primary_stats_file)
        secondary_stats_file = (
            vfs.VFS.open('character_scripts/secondary_stats.xml')
        )
        self.secondary_stats = XmlSerializer.deserialize(secondary_stats_file)        

        
    def create_stats(self, entity):
        for primary_stat in self.primary_stats:
            long_name = primary_stat.long_name
            entity.characterstats.primary_stats[long_name] = (
                char_stats.PrimaryStatisticValue(
                    primary_stat, entity.characterstats, 
                    self.DEFAULT_STAT_VALUE)
            )
        for secondary_stat in self.secondary_stats:
            name = secondary_stat.name            
            entity.characterstats.secondary_stats[name] = (
                char_stats.SecondaryStatisticValue(secondary_stat, 
                                                   entity.characterstats
                                                   )
            )
            
    def checkAttributes(self, attributes, template):
        """Checks for attributes that where not given in the map file
        and fills them with values from the object database
        @param attributes: attributes to check        
        @type attributes: Dictionary
        @param template: Template from which the values will be used
        @return: The modified attributes""" 
        if self.object_db.has_key(template):
            db_attributes = deepcopy(self.object_db[template])
            for key in db_attributes.keys():
                if attributes.has_key(key):                    
#.........这里部分代码省略.........
开发者ID:parpg,项目名称:parpg,代码行数:103,代码来源:gamemodel.py

示例2: GameModel

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import deleteObject [as 别名]

#.........这里部分代码省略.........
        ID = self.createUniqueID(ID)
        if info.has_key("attributes"):
            attributes = info["attributes"]
            if "Container" in attributes:
                info["actions"]["Open"] = ""
                if info.has_key("Items"):
                    inventory_objs = info["Items"]
                    info["items"] = self.createContainerItems(inventory_objs)
                
                new_item = CarryableContainer(ID = ID, **info) 
            else:
                new_item = CarryableItem(ID = ID, **info) 
        else:
            new_item = CarryableItem(ID = ID, **info) 
        self.game_state.addObject(None, new_item)
        return new_item
      
    def createInventoryObject(self, container, attributes):
        """Create an inventory object and place it into a container
           @type container: base.Container
           @param container: Container where the item is on
           @type attributes: Dictionary
           @param attributes: Dictionary of all object attributes
           @return: None"""
        index = attributes.pop("index") if attributes.has_key("index") else None
        slot = attributes.pop("slot") if attributes.has_key("slot") else None
        obj = self.createContainerObject(attributes)        
        #obj = createObject(attributes, extra)
        if slot:
            container.moveItemToSlot(obj, slot)
        else:
            container.placeItem(obj, index)
    
    def deleteObject(self, object_id):
        """Removes an object from the game
        @param object_id: ID of the object
        @type object_id: str """
        del self.agents["All"][object_id]
        self.game_state.deleteObject(object_id)
        
    def save(self, path, filename):
        """Writes the saver to a file.
           @type filename: string
           @param filename: the name of the file to write to
           @return: None"""
        fname = '/'.join([path, filename])
        try:
            save_file = open(fname, 'w')
        except(IOError):
            sys.stderr.write("Error: Can't create save game: " + fname + "\n")
            return
        save_state = {}
        save_state["Agents"] = {}
        for map_name in self.agents:
            if map_name == self.ALL_AGENTS_KEY:
                continue
            agents_dict = {}
            for agent in self.agents[map_name]:
                agent_obj = self.game_state.getObjectById(agent, map_name)
                agent_inst = self.game_state.maps[map_name].\
                                    agent_layer.getInstance(agent)
                agent_dict = self.agents[map_name][agent]
                agent_dict.update(agent_obj.getStateForSaving())
                agent_dict["Rotation"] = agent_inst.getRotation()
                agents_dict[agent] = agent_dict
            save_state["Agents"][map_name] = agents_dict
开发者ID:mgeorgehansen,项目名称:PARPG_Technomage,代码行数:70,代码来源:gamemodel.py


注:本文中的gamestate.GameState.deleteObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。