Commits

Chas Leichner  committed 6c02f21

mole representation working with percentage dependent regeneration

  • Participants
  • Parent commits 989f734

Comments (0)

Files changed (1)

File games/mole/mole.py

+import time
+import random
 from pymt import *
 from OpenGL.GL import *
 
 class Mole( MTButtonMatrix ):
     
     def __init__(self,**kwargs):
-        kwargs.setdefault('matrix_size', (3, 3))
+        kwargs.setdefault('matrix_size', (5, 5))
         super(Mole, self).__init__(**kwargs)
+        self.matrix = [[1 for x in xrange(kwargs.get('matrix_size')[0])] for y in xrange(kwargs.get('matrix_size')[1])]
         #TODO
         #self.player_images = (MTWidget(),MTSvg(filename='cross.svg'),MTSvg(filename='circle.svg') )
-        self.player = 1
         self.done = False
-        self.testpoint = (0,0)
-    
+
+    def matrix_proportion(self):
+        size = len(self.matrix) * len(self.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.collide_point(touch.x, touch.y):
+            i, j = self.collide_point(touch.x, touch.y)
+            #print i, j
+            if self.matrix[i][j]:
+                self.matrix[i][j] = 0
+
+            if self.matrix_proportion() < 0.5:
+                self.matrix = [[1 for x in xrange(len(self.matrix))] for y in xrange(len(self.matrix[0]))]
+            '''
+            else:
+                self.matrix[i][j] = 1
+            '''
+            self.dispatch_event('on_value_change', self.matrix)
+            self.dispatch_event('on_press', (i, j, self.matrix[i][j]))
+            self.last_tile = (i, j)
+
+    def draw(self):
+        #print time.time()
+        for i in range (self._matrix_size[0]):
+            for j in range (self._matrix_size[1]):
+                self.draw_tile(i, j)
+
     def restart(self):
         self.done = False
         self.player = 1
     #     self.get_parent_window().add_widget(popup)
 
 def pymt_plugin_activate(w,ctx):
-    ctx.game = Mole( size = w.size )
+    ctx.game = Mole( size = w.size, buttoncolor=(0,0,0,0), downcolor=(1,1,1,1) )
     w.add_widget( ctx.game )
 
 def pymt_plugin_deactivate(w, ctx):