本文整理汇总了Python中gamestate.GameState.addObject方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.addObject方法的具体用法?Python GameState.addObject怎么用?Python GameState.addObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.addObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import addObject [as 别名]
#.........这里部分代码省略.........
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
@type object_id: str """
if self.agents["All"].has_key(object_id):
del self.agents["All"][object_id]
else:
del self.items[object_id]
return 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"] = self.agents
save_state["Items"] = self.items
save_state["GameState"] = self.game_state.getStateForSaving()
yaml.dump(save_state, save_file)
save_file.close()
示例2: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import addObject [as 别名]
#.........这里部分代码省略.........
return items
def createContainerObject(self, attributes):
"""Create an object that can be stored in
an container and return it
@param attributes: Dictionary of all object attributes
@type attributes: Dictionary
@return: The created object """
# create the extra data
extra = {}
extra['controller'] = self
attributes = self.checkAttributes(attributes)
info = {}
info.update(attributes)
info.update(extra)
ID = info.pop("id") if info.has_key("id") else info.pop("ID")
if not info.has_key("item_type"):
info["item_type"] = info["type"]
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: