Commits

Chas Leichner  committed e98d76c

removed buggy end game code, now it just quits when the game is over

  • Participants
  • Parent commits 095ab9e

Comments (0)

Files changed (1)

File games/mole/mole.py

+import sys
 import time
 import random
 from pymt import *
 
     def on_touch_down(self, *largs):
         self.parent.remove_widget(self)
+#kills the game, this should go you can easily restart the game
+        sys.exit(0)
         self.game.restart()
         return True
 
         self.score = 0
 
     def restart(self):
-        pass
+        self.start_time = self.time = time.time()
+        self.done = False
+        self.density = 0.1
+        self.matrix = [[generate_num(self.density) for i in range(self.matrix_size[0])] for j in range(self.matrix_size[1])]
+        self.done = False
+        self.score = 0
+        self.reset()
 
     def show_gameover(self, text):
         popup = GameOver(game=self, text=text)
         self.get_parent_window().add_widget(popup)
 
-    def matrix_proportion(self, matrix):
-        size = len(matrix) * len(matrix[0])
-        on = 0.0
-        for row in self.matrix:
-            for cell in row:
-                if cell:
-                    on+=1
-        return on/size
-
     def on_touch_down(self, touch):
         if self.done:
             return True
         destroy_color = (1,0,0,1)
         if self.matrix[i][j] == 0:
             set_color(*self.buttoncolor)
+#mark as killed
         elif self.matrix[i][j] == -2:
             set_color(*destroy_color)
             self.matrix[i][j]+=1
             self.time = current_time
             self.matrix = self.random_matrix(self.density)
 
-        if current_time - self.start_time > 3 and self.matrix_proportion(self.matrix) < 0.5:
+        if current_time - self.start_time > 60:
             high_score = get_high_score()
-            self.show_gameover("Game Over!\nYour Score: %d\nHigest Score:%d" % (self.score, high_score))
+            self.show_gameover("Time Up!\nYour Score: %d\nHigest Score:%d" % (self.score, high_score))
             if self.score > high_score:
                 write_high_score(self.score)
             self.done = True
             for j in range (self._matrix_size[1]):
                 self.draw_tile(i, j)
 
-    def restart(self):
-        self.start_time = self.time = time.time()
-        self.done = False
-        self.density = 0.1
-        self.matrix = [[generate_num(self.density) for i in range(self.matrix_size[0])] for j in range(self.matrix_size[1])]
-        self.done = False
-        self.score = 0
-        self.reset()
-    
-    # def show_winner(self, text):
-    #     popup = MoleWinner(game=self,text=text)
-    #     self.get_parent_window().add_widget(popup)
-
 def pymt_plugin_activate(w,ctx):
     ctx.game = Mole( size = w.size, matrix_size=(6,6), buttoncolor=(0,0,0,0), downcolor=(1,1,1,1) )
     w.add_widget( ctx.game )