def reloadterritories(newmapfile): """Reload the list of territories""" global totim riskengine.openworldfile(newmapfile) riskengine.loadterritories() canvas.delete("bgr") for n in territories.values(): canvas.delete(n.name) canvas.delete(n.name + "-a") graphics = xml.dom.minidom.parseString(riskengine.zfile.read("territory_graphics.xml")) loadterritorygraphics(graphics) canvas.configure(height=graphics.childNodes[0].getAttribute("height"), width=graphics.childNodes[0].getAttribute("width")) boardname = graphics.getElementsByTagName("board")[0].childNodes[0].data total = opengraphic(boardname) totim = ImageTk.PhotoImage(total) canvas.create_image(0, 0, anchor=Tkinter.NW, image=totim, tags=("bgr",)) for terr in riskengine.territories.values(): drawterritory(terr, 0) riskengine.closeworldfile()
def setupdata(): """Start the game""" global territories, canvas, root, statuswind, gameMenu, playerMenu global entrystr, armieslabel, totim, scrlbr, zfile, plist root = Tkinter.Tk() root.title("PyRisk") graphics = xml.dom.minidom.parseString(riskengine.zfile.read("territory_graphics.xml")) loadterritorygraphics(graphics) menuBar = Tkinter.Menu(root) root["menu"] = menuBar gameMenu = Tkinter.Menu(menuBar, tearoff=0) gameMenu.add_command(label="Start Game", command=startgame) gameMenu.add_separator() gameMenu.add_command(label="Load a Map", command=load_new_world) gameMenu.add_command(label="Start Server", command=risknetwork.start_server) gameMenu.add_command(label="Connect to Server", command=serverconnect) gameMenu.add_separator() gameMenu.add_command(label="Save Game", command=save_game) gameMenu.add_command(label="Load Game", command=load_game) gameMenu.add_separator() gameMenu.add_command(label="Exit", command=lambda:root.destroy()) playerMenu = Tkinter.Menu(menuBar, tearoff=0) playerMenu.add_command(label="New Player", command=newplayer) playerMenu.add_separator() playerMenu.add_command(label="Next Turn", command=riskengine.nextturn) playerMenu.add_command(label="Show Cards", command=showcards) playerMenu.add_command(label="Fortify", command=riskengine.startfortifying) helpMenu = Tkinter.Menu(menuBar, tearoff=0) helpMenu.add_command(label="Help text", command=showhelp) menuBar.add_cascade(label="Game", menu=gameMenu) menuBar.add_cascade(label="Player", menu=playerMenu) menuBar.add_cascade(label="Help", menu=helpMenu) totalframe = Tkinter.Frame(root) lframe = Tkinter.Frame(totalframe) plist = PlayerList(lframe, bd=2, relief=Tkinter.SUNKEN) plist.pack(anchor=Tkinter.N, fill=Tkinter.Y, expand=Tkinter.YES) armieslabel = Tkinter.Label(lframe, text="Armies:") armieslabel.pack() Tkinter.Button(lframe, text="Next Turn", command = riskengine.nextturn).pack(padx=5, pady=5) Tkinter.Button(lframe, text="Fortify", command = riskengine.startfortifying).pack(padx=5, pady=5) Tkinter.Button(lframe, text="Next State", command = riskengine.nextturn).pack(padx=5,pady=5) lframe.pack(side=Tkinter.LEFT, anchor=Tkinter.N, fill=Tkinter.Y) canvas = Tkinter.Canvas(totalframe, height=graphics.childNodes[0].getAttribute("height"), width=graphics.childNodes[0].getAttribute("width")) boardname = graphics.getElementsByTagName("board")[0].childNodes[0].data total = opengraphic(boardname) totim = ImageTk.PhotoImage(total) canvas.create_image(0, 0, anchor=Tkinter.NW, image=totim, tags=("bgr",)) for terr in riskengine.territories.values(): drawterritory(terr, 0) del total canvas.bind("<Button-1>", handleclick) canvas.bind("<Button-3>", handleclick) canvas.pack(side=Tkinter.RIGHT, expand=Tkinter.YES, fill=Tkinter.BOTH) totalframe.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)#set up message area statusframe = Tkinter.Frame(root, bd=2, relief=Tkinter.SUNKEN) statuswind = Tkinter.Text(statusframe, bd=0, height=4) scrlbr = Tkinter.Scrollbar(statusframe, orient=Tkinter.VERTICAL) scrlbr["command"] = statuswind.yview statuswind["yscrollcommand"] = scrlbr.set scrlbr.pack(fill=Tkinter.Y, side=Tkinter.RIGHT) statuswind.pack(fill=Tkinter.BOTH, expand=Tkinter.YES, side=Tkinter.LEFT) statusframe.pack(fill=Tkinter.BOTH, expand=Tkinter.YES) entrystr = Tkinter.StringVar()#set up message entry entrybar = Tkinter.Entry(root, textvariable=entrystr) entrybar.pack(side=Tkinter.BOTTOM, fill=Tkinter.X) entrybar.bind("<Return>", handlemessage) riskengine.closeworldfile() gc.collect()