Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- help = "Commands: " "look"
- room = "start"
- door_status = "closed"
- hatch_status = "closed"
- inventory = "Inventory = " "None"
- look_start #can i have this variable in another file?
- print "Game, created by Mark Veidemanis"
- from Tkinter import *;
- class CommandButton(Button):
- def _on_click ( self, *args, **kw ):
- self.game.run_command(self.ui, self.command);
- #end
- def __init__ ( self, parent, ui, game, text, command ):
- Button.__init__(self, parent, text=text);
- self.ui = ui;
- self.game = game;
- self.command = command;
- self.bind("<Button-1>", self._on_click);
- #end
- #end
- class MainFrame(Frame):
- def _do_send ( self, *args, **kw ):
- self.game.run_command(self, self._invar.get());
- #end
- def _init_widgets ( self ):
- self._toolbar = Frame(self);
- self._toolbar.pack(side=TOP, fill=X);
- self._outvar = StringVar();
- self._textbox = Text(self);
- self._textbox.pack(fill=BOTH);
- self._entrybar = Frame(self);
- self._entrybar.pack(side=BOTTOM, fill=X);
- self._invar = StringVar();
- self._entry = Entry(self._entrybar, textvariable=self._invar);
- self._entry.pack(side=LEFT);
- self._sendbutton = Button(self._entrybar, text="Execute");
- self._sendbutton.pack(side=RIGHT);
- self._sendbutton.bind("<Button-1>", self._do_send);
- #end
- def output ( self, text ):
- self._textbox.insert("end", text + "\n");
- self._invar.set("");
- #end
- def add_button ( self, text, command ):
- self._button = CommandButton(self._toolbar, self, self.game, text, command);
- self._button.pack(side=LEFT);
- #end
- def __init__ ( self, parent, game ):
- Frame.__init__(self, parent);
- self.game = game;
- self._init_widgets();
- #end
- #end
- class Game:
- def run_command ( self, ui, cmd ):
- if (cmd == "help"):
- ui.output(help);
- if (cmd == "inv"):
- ui.output(inventory);
- if (cmd == "look") and (room == "start"):
- ui.output(look_start)
- else:
- ui.output("Unknown command `%s'" % cmd);
- #end
- #end
- #end
- if __name__ == "__main__":
- mainwin = Tk();
- game = Game();
- mainwin.title("Game");
- mainfrm = MainFrame(mainwin, game);
- mainfrm.add_button("Help", "help");
- mainfrm.add_button("Inv", "inv");
- mainfrm.add_button("Look", "look") #- this bit and...
- mainfrm.pack();
- mainwin.mainloop();
- #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement