本文整理汇总了Python中Resources.map方法的典型用法代码示例。如果您正苦于以下问题:Python Resources.map方法的具体用法?Python Resources.map怎么用?Python Resources.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resources
的用法示例。
在下文中一共展示了Resources.map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generateMapAndUnits
# 需要导入模块: import Resources [as 别名]
# 或者: from Resources import map [as 别名]
def generateMapAndUnits():
map_ = Resources.map('random')
units = []
nUnits = random.randint(4, 8)
startColumn = random.randint(0, map_.width - (nUnits + 1) / 2)
for i in xrange(0, nUnits):
u = generateUnit(PLAYER_FACTION)
if i < nUnits / 2:
row = map_.height-1
column = startColumn + i
else:
row = map_.height-2
column = startColumn + (i - nUnits/2)
map_.squares[column][row].setUnit(u)
units.append(u)
nUnits += additionalAIUnits
startColumn = random.randint(0, map_.width - (nUnits + 1) / 2)
for i in xrange(0, nUnits):
u = generateUnit(NPC_HOSTILE_FACTION)
if i < nUnits / 2:
row = 0
column = startColumn + i
else:
row = 1
column = startColumn + (i - nUnits/2)
map_.squares[column][row].setUnit(u)
units.append(u)
return (map_, units)
示例2: load
# 需要导入模块: import Resources [as 别名]
# 或者: from Resources import map [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)