本文整理汇总了Python中field.Field.loadField方法的典型用法代码示例。如果您正苦于以下问题:Python Field.loadField方法的具体用法?Python Field.loadField怎么用?Python Field.loadField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field.Field
的用法示例。
在下文中一共展示了Field.loadField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameManager
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import loadField [as 别名]
class GameManager(Runnable):
def __init__(self,settingFileName = "setting/gameSettings.conf"):
super().__init__()
#self.testInitialize()
self.initialize(settingFileName)
time.sleep(2)
def defaultInitialize(self):
# self.specialUnit = GameObject(move = MoveByKeyAsUnit(velocity = 50))
self._viewPoint = None
self.bullets = RunnableList()
self.units = RunnableList()
self.items = RunnableList()
self.bases = RunnableList()
self.debugObjects = RunnableList()
self.field = Field(self)
def initialize(self,settingFilename):
self.defaultInitialize()
file = open(settingFilename, "r")
self.field.loadField(file.readline().strip())
for team in (0,1):
gen = self.field.getUnitPosition(team)
for aiName,(point,direction) in zip(file.readline().split(),gen):
if aiName == "debug":
unit = Unit(point,direction,self,team,len(self.units))
self.addDebugUnit(unit)
self.units.append(unit)
continue
elif aiName == "player":
unit = Unit(point,direction,self,team,len(self.units), aiManager = PlayerManager())
self._viewPoint = unit
# self.addDebugUnit(unit,UNIT_MAX_ROLL_ANGLE,UNIT_MAX_SPEED)
self.units.append(unit)
continue
else:
self.units.append(Unit(point,direction,self,team,len(self.units),AiManager(aiName)))
self.debugmode = eval(file.readline())
if self.debugmode:
pass
for i in self.units:
i.sendStartingMessage()
if self._viewPoint is None:
self._viewPoint = GameObject(direction = -1.57079633, move = MoveByKey(speed = 5))
self.debugObjects.append(self._viewPoint)
self._defeatTeam = 0
def addDebugUnit(self,unit,angle = 0.3,velocity = 10):
self.debugUnit = unit
self.debugUnit.setMove(MoveByKeyAsUnit(angle = angle, velocity = velocity))
self._viewPoint = self.debugUnit
def writeEndMessage(self,unit,file):
file.write("endGame")
if self._defeatTeam == 3:
file.write("drawGame")
elif self._defeatTeam == 0:
file.write("canceled this Game")
else:
file.write("team ")
file.write(self._defeatTeam)
file.write(" win")
def writeStartingMessage(self,unit,file):
file.write("startInit")
self.writeMessageUnit(unit,file)
self.writeMessageField(self.field,file)
file.write("endInit\n")
self.writeMessage(unit,file)
def writeMessage(self,unit,file):
file.write("start")
for i in self.bases:
self.writeMessageBase(i,file)
for i in self.units:
if i.getTeamFlag() == unit.getTeamFlag():
self.writeMessageUnit(i,file)
continue
if abs(i.getPosition() - unit.getPosition()) < RADIUS_OF_THE_VISILITY_ARIA:
self.writeMessageUnit(i,file)
continue
for i in self.bullets:
if abs(i.getPosition() - unit.getPosition()) <RADIUS_OF_THE_VISILITY_ARIA:
self.writeMessageBullet(i,file)
for i in self.items:
if i.checkAvailable:
if abs(i.getPosition() - unit.getPosition()) <RADIUS_OF_THE_VISILITY_ARIA:
self.writeMessageItem(i,file)
file.write("end")
def writeMessageUnit(self,unit,file):
file.write("unit")
for i in unit.encode():
file.write(str(i))
def writeMessageBullet(self,bullet,file):
file.write("bullet")
for i in bullet.encode():
file.write(str(i))
def writeMessageBase(self,base,file):
file.write("base")
for i in base.encode():
file.write(str(i))
def writeMessageItem(self,item,file):
file.write("item")
for i in item.encode():
#.........这里部分代码省略.........