本文整理汇总了Python中XML.parse_figures方法的典型用法代码示例。如果您正苦于以下问题:Python XML.parse_figures方法的具体用法?Python XML.parse_figures怎么用?Python XML.parse_figures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML.parse_figures方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadGames
# 需要导入模块: import XML [as 别名]
# 或者: from XML import parse_figures [as 别名]
def loadGames():
try:
f = open("./xml/packlist.chess", "r")
except FileNotFoundError:
return
saves = f.readlines()
for save in saves:
save = save.rstrip()
gameID = save[:save.find(":")]
lastNum = save[save.find(":")+1:]
g = Game()
g.id = int(gameID)
xmlPath = "./xml/"+gameID+"/"+lastNum+".xml"
try:
m = XML.parse_meta(xmlPath)
g.password = m["password"]
g.board.whoseTurn = WHITE if m["turn"] == "white" else BLACK
g.board.xSize = int(m["sizeX"])
g.board.ySize = int(m["sizeY"])
g.movesmade = int(m["movesmade"])
g.board.setup_fields()
except KeyError:
continue
figures = XML.parse_figures(xmlPath)
for figure in figures:
g.board.getFieldByCords(figure.posx, figure.posy).figure = figure
g.board.postMoveUpdate()
if g.password is None:
g.password = ""
if g.movesmade > 3:
glist.append(g)
print("Loaded Game:", g.id)
else:
removeLine("./xml/packlist.chess", str(g.id)+":"+str(g.movesmade)+"\n")
rmdir("./xml/"+str(g.id))
print("Removed SaveGame:", g.id)