Advertisement
Guest User

Game setup

a guest
Jun 28th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. # makes a game by showing 2 dialogs
  2. # after dialogs have been answered, starts the game by drawing the canvas.
  3.  
  4. # imports  
  5. import wx
  6. import Board
  7.  
  8. # globals
  9. SCRWIDTH = 950
  10. SCRHEIGHT = 700
  11.  
  12. # dialogbox class
  13. class MyDialog1(wx.Dialog):
  14.     def __init__(self, parent):
  15.         wx.Dialog.__init__(self, parent)
  16.  
  17.         self.username = wx.TextCtrl(self)
  18.         self.okButton = wx.Button(self, wx.ID_OK, "OK")
  19.  
  20. class MyDialog2(wx.Dialog):
  21.     def __init__(self, parent):
  22.         wx.Dialog.__init__(self, parent)
  23.  
  24.         self.canvasWidth = wx.TextCtrl(self)
  25.         self.okButton = wx.Button(self, wx.ID_OK, "OK")
  26.  
  27. # main class
  28. class Game(wx.Frame):
  29.     def __init__(self):
  30.         wx.Frame.__init__(self, None, -1, title='My game', size=(SCRWIDTH, SCRHEIGHT))
  31.         self.username = ""
  32.         self.canvasWidth = 10
  33.         # hide the frame for now
  34.         self.Hide()
  35.  
  36. def OnInit(self):
  37.     #Make your dialogs
  38.     dlg1 = MyDialog1(self)
  39.     #if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
  40.     if dlg1.ShowModal() == wx.ID_OK:
  41.         #get the username from the dialog
  42.         self.username = dlg1.username.GetValue()
  43.     #clean up the dialog (AFTER you get the username)
  44.     dlg1.Destroy()
  45.  
  46.     dlg2 = MyDialog2(self)
  47.     #if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
  48.     if dlg2.ShowModal() == wx.ID_OK:
  49.         #get the username from the dialog
  50.         self.canvasWidth = dlg2.canvasWidth.GetValue()
  51.     #clean up the dialog (AFTER you get the username)
  52.     dlg2.Destroy()
  53.  
  54.    
  55.  
  56.     # Now that you have your settings, Make the gameboard
  57.     # THIS PART IS STILL BROKEN!
  58.     # I can paste the whole board class (structure of it is taken from the tetris tutorial)
  59.     # but that seems a bit much tbh...
  60.     self.gameBoard = Board.Board(self)
  61.     self.gameBoard = SetFocus()
  62.     self.gameBoard.start()
  63.  
  64.     self.Centre()
  65.     self.Show(True) #show the frame
  66.  
  67.  
  68.  
  69.  
  70.  
  71. if __name__ == '__main__':
  72. # how can I start the game here?
  73.     app = wx.App()
  74.     app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement