Beispiel #1
0
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)