SHARE
TWEET

Untitled

a guest Mar 2nd, 2013 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. help = "Commands: " "look"
  2. room = "start"
  3. door_status = "closed"
  4. hatch_status = "closed"
  5. inventory = "Inventory = " "None"
  6. look_start #can i have this variable in another file?
  7.  
  8. print "Game, created by Mark Veidemanis"
  9. from Tkinter import *;
  10.  
  11. class CommandButton(Button):
  12.     def _on_click ( self, *args, **kw ):
  13.         self.game.run_command(self.ui, self.command);
  14.     #end
  15.     def __init__ ( self, parent, ui, game, text, command ):
  16.         Button.__init__(self, parent, text=text);
  17.         self.ui = ui;
  18.         self.game = game;
  19.         self.command = command;
  20.         self.bind("<Button-1>", self._on_click);
  21.     #end
  22. #end
  23.  
  24. class MainFrame(Frame):
  25.     def _do_send ( self, *args, **kw ):
  26.         self.game.run_command(self, self._invar.get());
  27.     #end
  28.     def _init_widgets ( self ):
  29.         self._toolbar = Frame(self);
  30.         self._toolbar.pack(side=TOP, fill=X);
  31.  
  32.         self._outvar = StringVar();
  33.         self._textbox = Text(self);
  34.         self._textbox.pack(fill=BOTH);
  35.  
  36.         self._entrybar = Frame(self);
  37.         self._entrybar.pack(side=BOTTOM, fill=X);
  38.  
  39.         self._invar = StringVar();
  40.         self._entry = Entry(self._entrybar, textvariable=self._invar);
  41.         self._entry.pack(side=LEFT);
  42.  
  43.         self._sendbutton = Button(self._entrybar, text="Execute");
  44.         self._sendbutton.pack(side=RIGHT);
  45.  
  46.         self._sendbutton.bind("<Button-1>", self._do_send);
  47.     #end
  48.     def output ( self, text ):
  49.         self._textbox.insert("end", text + "\n");
  50.         self._invar.set("");
  51.     #end
  52.     def add_button ( self, text, command ):
  53.         self._button = CommandButton(self._toolbar, self, self.game, text, command);
  54.         self._button.pack(side=LEFT);
  55.     #end
  56.     def __init__ ( self, parent, game ):
  57.         Frame.__init__(self, parent);
  58.         self.game = game;
  59.         self._init_widgets();
  60.     #end
  61. #end
  62.  
  63. class Game:
  64.     def run_command ( self, ui, cmd ):
  65.         if (cmd == "help"):
  66.             ui.output(help);
  67.         if (cmd == "inv"):
  68.             ui.output(inventory);
  69.         if (cmd == "look") and (room == "start"):
  70.             ui.output(look_start)
  71.         else:
  72.             ui.output("Unknown command `%s'" % cmd);
  73.         #end
  74.     #end
  75. #end
  76.  
  77. if __name__ == "__main__":
  78.     mainwin = Tk();
  79.     game = Game();
  80.     mainwin.title("Game");
  81.     mainfrm = MainFrame(mainwin, game);
  82.     mainfrm.add_button("Help", "help");
  83.     mainfrm.add_button("Inv", "inv");
  84.     mainfrm.add_button("Look", "look") #- this bit and...
  85.     mainfrm.pack();
  86.     mainwin.mainloop();
  87. #end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top