本文整理汇总了Python中Resources.unit方法的典型用法代码示例。如果您正苦于以下问题:Python Resources.unit方法的具体用法?Python Resources.unit怎么用?Python Resources.unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resources
的用法示例。
在下文中一共展示了Resources.unit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generateUnit
# 需要导入模块: import Resources [as 别名]
# 或者: from Resources import unit [as 别名]
def generateUnit(faction):
unitTemplates = ['archer1', 'fighter1', 'defender1',
'rogue1', 'healer1', 'mage1']
unitTemplate = random.choice(unitTemplates)
u = Resources.unit(unitTemplate)
u.setFaction(faction)
#u.setFaction(0)
return u
示例2: load
# 需要导入模块: import Resources [as 别名]
# 或者: from Resources import unit [as 别名]
def load(scenarioFilename):
scenarioFile = file(scenarioFilename, "rU")
scenarioText = scenarioFile.read()
scenarioFile.close()
globalVars = {}
localVars = {}
module = compile("from engine.Unit import numpy.oldnumeric.ma as MALE, FEMALE, NEUTER",
"Unit.py", "exec")
eval(module, globalVars)
module = compile("from engine.Faction import Faction",
"Faction.py", "exec")
eval(module, globalVars)
for m in ["Light", "Battle"]:
module = compile("import engine.%s as %s" % (m, m), m, "exec")
eval(module, globalVars)
compiled = compile(scenarioText, scenarioFilename, 'exec')
eval(compiled, globalVars, localVars)
scenarioData = localVars
if scenarioData['VERSION'] != 1:
raise Exception("Scenario version %d not supported" %
scenarioData["VERSION"])
# Required fields: map
m = Resources.map(scenarioData['MAP'])
# Load ending conditions
endingConditions = [Battle.NEVER_ENDING]
if scenarioData.has_key('ENDING_CONDITIONS'):
endingConditions = scenarioData['ENDING_CONDITIONS']
# Load lights
if scenarioData.has_key('LIGHTING'):
lightEnv = scenarioData['LIGHTING']
else:
lightEnv = Light.defaultEnvironment()
# Load units
units = []
if scenarioData.has_key('FACTIONS'):
for f in scenarioData['FACTIONS']:
faction = f.faction()
for u in f.units():
(unitFile, (x, y)) = u
u = Resources.unit(unitFile)
m.squares[x][y].setUnit(u)
u.setFaction(faction)
units.append(u)
# Music
music = 'barbieri-battle'
if scenarioData.has_key('MUSIC'):
music = scenarioData['MUSIC']
# Create battle
battle = Battle.Battle(endingConditions, units, m)
return Scenario(m, units, lightEnv, battle, None, music)