Dinesh Manajipet avatar Dinesh Manajipet committed 21d818d

Fixed all the Minor Annoyances before I put a(indefinite) pause to the work :D

Comments (0)

Files changed (14)

+# use glob syntax.
+syntax: glob
+
+*.xcf
+*.pyc
+*.png
+*~ 
Added
New image
Added
New image
Added
New image
Added
New image
Added
New image
+#Brings down an Overlay Button and the MineFieldWidget into 1 single Widget.. one might want to add Timer, Score etc.. too
+
+from PySide.QtGui import *
+from PySide.QtCore import *
+from MineFieldWidget import *
+from Overlay import *
+
+class GameWidget(QWidget):
+  @Signal
+  def resetGame():
+    pass
+  
+  def __init__(self, rows = 10, columns = 10, mines =10 ,parent = None):
+    QWidget.__init__(self,parent)
+    self._rows = rows
+    self._columns = columns
+    self._mines = mines
+    
+    self._overlay = None
+    self._mineFieldWidget = None
+        
+    self.initializeGui()
+    
+    
+  def gameWon(self):
+    self._overlay.setState("won")
+    
+  def gameLost(self):
+    self._overlay.setState("lost")    
+    
+  def newGame(self):
+    self.resetGame.emit()
+   
+  def initializeGui(self):    
+    self._overlay = Overlay("start")
+    self._overlay.clicked.connect(self.newGame)
+
+    self._mineFieldWidget = MineFieldWidget(self._rows ,self._columns, self._mines)
+    self._mineFieldWidget.gameWon.connect(self.gameWon)
+    self._mineFieldWidget.gameLost.connect(self.gameLost)
+    
+    self._layout = QVBoxLayout()
+    self._layout.addWidget(self._overlay)
+    self._layout.addWidget(self._mineFieldWidget)
+    self.setLayout(self._layout)
 from PySide.QtGui import *
-from MineFieldWidget import *
-from Overlay import *
+from GameWidget import *
 
 class MainWindow(QMainWindow):
-  def __init__(self, parent = None):
+  def __init__(self,rows,columns,mines, parent = None):
     QMainWindow.__init__(self,parent)
-    self._rows = 10
-    self._columns = 10
-    self._mines = 10
-    self._overlay = Overlay ("start")
-    self.setCentralWidget(self._overlay)
-    self._overlay.clicked.connect(self.newGame)
+    
+    self._rows = rows
+    self._columns = columns
+    self._mines = mines
+    
+    self.newGame()
     
   def newGame(self):
-    print "new Game!"
-    self._mineFieldWidget = MineFieldWidget(self._rows ,self._columns, self._mines)
-    self._mineFieldWidget.gameWon.connect(self.gameWon)
-    self._mineFieldWidget.gameLost.connect(self.gameLost)
-    self.setCentralWidget(self._mineFieldWidget)
-  
-  def gameWon(self):
-    self._overlay = Overlay ("won")
-    self._overlay.clicked.connect(self.newGame)
-    self.setCentralWidget (self._overlay)
-    
-  def gameLost(self):
-    self._overlay = Overlay ("lost")
-    self._overlay.clicked.connect(self.newGame)
-    self.setCentralWidget (Overlay ("lost"))
+    self._gameWidget = GameWidget(self._rows,self._columns, self._mines)
+    self._gameWidget.resetGame.connect(self.newGame)
+    self.setCentralWidget(self._gameWidget)
       return
     self.setEnabled(False)
     #uncover
-    status = self._mineField.uncover(self._row,self._column)
-    #print self._row, self._column, ":" , status
+    status = self._mineField.uncover(self._row,self._column)    
+    #Don't display value even for zero surrounding Mines
+    if (not status == 0):
+      self.setStatus( status )
+    
+    #Let the MineField Widget Know about it
     self.uncovered.emit(self._row,self._column , status)
-    
-    #Don't display value even for zero surrounding Mines
-    if (status == 0):
-      return
-    self.setStatus( status )
+
     
   def setStatus(self, status):
     if (status > 0 ):
     '''if there is a Mine in a block, show it as a mine'''
     if (self._mineField.reveal(self._row, self._column)):
     #If already exploded, do nothing , cuz we already have a shiny image for the Explosion in place
-      if (self._mineField.status(self._row, self._column) == self._mineField.blockState["mine"]):
-        return
-      self.clearMe()
-      self.setIcon(QPixmap("./Artwork/Mine.png"))
+      if (not self._mineField.status(self._row, self._column) == self._mineField.blockState["mine"]):
+        self.clearMe()
+        self.setIcon(QPixmap("./Artwork/Mine.png"))
       
   def explodeMe(self):
     self.clearMe()

MineFieldWidget.py

         
   def boom(self):
     ''' If the user tripped on a single Mine, then reveal all the Mines'''
-    
     for row in range (0, self._rows):
       for column in range (0 , self._columns):
         self._mineLayout.itemAtPosition(row , column).widget().reveal()
-        
-    msgBox = QMessageBox(self)
-    msgBox.setText("That Was a mine!! You lost :(")
-    msgBox.exec_()
-    
+
     self.gameLost.emit()
         
   def phew(self):
     ''' If the user uncovered all the free blocks, then game is Won '''
     
     # additional things like score etc... ?
-            
-    msgBox = QMessageBox(self)
-    msgBox.setText("Yayy! You Won :D")
-    msgBox.exec_()
     
     self.gameWon.emit()
     
     #if the uncovered block is a mine, BOOM!
     if (status == self._mineField.blockState["mine"]):
       self.boom()
+      return
     #if the uncovered mine has no mines in it's neighbours, uncover them too :)
     if (status == 0):
       for i in range (-1,2):
       self.setText("Yayy!! You ve WON!!!")
     elif(state == "lost"):
       self.setIcon(self._frown)
-      self.setText("Oops! that wasn't a mine!!")
+      self.setText("Oops! That was a mine!!")
     elif (state == "start"):
       self.setIcon(self._pause)
-      self.setText( "Click Me to go on with the game!!")
+      self.setText( "Click Me to start a game!!")
 from PySide.QtGui import *
 import sys
 
-from MineFieldWidget import *
-
-def newGame():
-  global myMainWindow
-  myMainWindow = MineFieldWidget(10,10,10)
-  myMainWindow.gameWon.connect(newGame)
-  myMainWindow.gameLost.connect(newGame)
-  myMainWindow.show()
+from MainWindow import *
 
 app = QApplication(sys.argv)
-myMainWindow = MineFieldWidget(10,10,10)
-newGame()
+myMainWindow = MainWindow(10,10,10)
+myMainWindow.show()
 app.exec_()
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.