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


Python GameState.hasObject方法代码示例

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


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

示例1: GameModel

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

#.........这里部分代码省略.........
            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):                    
                    tmp_attributes = db_attributes[key]
                    tmp_attributes.update(attributes[key])
                    attributes[key] = tmp_attributes
                else:
                    attributes[key] = db_attributes[key]
        return attributes
    
    def isIDUsed(self, ID):
        if self.game_state.hasObject(ID):
            return True
        for namespace in self.agents:
            if ID in self.agents[namespace]:
                return True
        return False
    
    def createUniqueID(self, ID):
        if self.isIDUsed(ID):
            id_number = 1
            while self.isIDUsed(ID + "_" + str(id_number)):
                id_number += 1
                if id_number > self.MAX_ID_NUMBER:
                    raise ValueError(
                        "Number exceeds MAX_ID_NUMBER:" + 
                        str(self.MAX_ID_NUMBER)
                    )
            
            ID = ID + "_" + str(id_number)
        return ID
    
    def moveObject(self, object_id, new_map):
        """Moves the object to a new map, or in a container
        @param object_id: ID of the object
        @type object_id: str 
        @param new_map: ID of the new map, or None
        @type object_id: str """
        game_object = self.deleteObject(object_id)
        self.game_state.addObject(object_id, new_map, game_object)

    def deleteObject(self, object_id):
        """Removes an object from the game
        @param object_id: ID of the object
开发者ID:parpg,项目名称:parpg,代码行数:70,代码来源:gamemodel.py

示例2: GameModel

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import hasObject [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
    
    def __init__(self, engine, settings):
        """Initialize the instance.
        @param engine: A fife.Engine object
        @type emgome: fife.Engine 
        @param setting: The applications settigns
        @type setting: fife_settings.Setting 
        @return: None"""
        self.map_change = False
        self.load_saver = False
        self.savegame = None
        self.game_state = GameState(quests_dir = settings.get("PARPG",
                                                             "QuestsDirectory"))
        #self.game_state.quest_engine = 
        #self.game_state.quest_engine.readQuests()
        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.engine = engine
        self.fife_model = engine.getModel()
        self.game_state.maps_file = "maps/maps.yaml"
        self.all_agents_file = "maps/all_agents.yaml"
        self.object_db_file = "objects/object_database.yaml"
        self.agents_directory = "objects/"
        self.dialogues_directory = "dialogue"
        self.dialogues = {}
        self.agent_import_files = {}
        self.settings = settings
        self.obj_loader = XMLObjectLoader(
                                          self.engine.getImagePool(), 
                                          self.engine.getAnimationPool(), 
                                          self.engine.getModel(),
                                          self.engine.getVFS() 
                                          )

    def checkAttributes(self, attributes):
        """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
        @return: The modified attributes""" 
        if attributes.has_key("object_type"):
            class_name = attributes.pop("object_type")
        else:
            class_name = attributes["type"]
        if not attributes.has_key("type"):
            attributes["type"] = class_name
        if self.object_db.has_key(class_name):
            db_attributes = deepcopy(self.object_db[class_name])
            for key in db_attributes.keys():
                if attributes.has_key(key):
                    attributes[key] = attributes[key] or db_attributes[key]
                else:
                    attributes[key] = db_attributes[key]
        return attributes
    
    def isIDUsed(self, ID):
        if self.game_state.hasObject(ID):
            return True
        for namespace in self.agents:
            if ID in self.agents[namespace]:
                return True
        return False
    
    def createUniqueID(self, ID):
        if self.isIDUsed(ID):
            id_number = 1
            while self.isIDUsed(ID + "_" + str(id_number)):
                id_number += 1
                if id_number > self.MAX_ID_NUMBER:
                    raise ValueError(
                        "Number exceeds MAX_ID_NUMBER:" + str(self.MAX_ID_NUMBER))
            
            ID = ID + "_" + str(id_number)
        return ID

    def createContainerItems(self, container_objs):
        """Create the items of a container from a dictionary
        @param container_objs: Dictionary containing the items
        @type container_objs: dict"""
        items = []
        for container_obj in container_objs:
            items.append(self.createContainerObject(container_obj))
        
        return items

    def createContainerObject(self, attributes):
#.........这里部分代码省略.........
开发者ID:mgeorgehansen,项目名称:PARPG_Technomage,代码行数:103,代码来源:gamemodel.py


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