@@ -29,13 +29,11 @@ def set_cell(self, obj, pos, val=True, dirty={}):
2929 if not dirty [p ]: # check this position is pressed
3030 continue
3131 d2 = obj .domino_for_position (p )
32- if d2 == d1 :
32+ if d2 == d1 or not d2 in d1 . neighbors () :
3333 continue
3434 if d2 in d1 .neighbors ():
3535 # Do the flip
3636 obj .flip (d1 , d2 )
37- #obj.matching[d1.first] = d1
38- #obj.matching[d2.first] = d2
3937 return obj
4038 return Exception ("Please select a second domino!" )
4139 else :
@@ -201,13 +199,25 @@ def is_pressed(self):
201199 """Is the domino pressed?"""
202200 return self .value
203201
202+ def set_value (self , value ):
203+ """Set domino value
204+ As we have a directional link,
205+ the domino value will also be set.
206+ """
207+ self .link .unlink ()
208+ self .first .value = value
209+ self .second .value = value
210+ self .link = ddlink (((self .first , 'value' ), (self .second , 'value' )), (self , 'value' ), logic = 'and' , set_at_init = False ) # Fresh ddlink
211+
204212 def reset (self ):
205213 """Full domino reset"""
206- self .value = False
214+ self .set_value ( False )
207215 self .link .unlink ()
208216
209217 def flip (self , other ):
210218 """Flip self with some neighboring domino"""
219+ if other == self or other .geometry == self .geometry :
220+ return
211221 self .reset ()
212222 other .reset ()
213223 self .geometry .flip (other .geometry )
@@ -253,6 +263,7 @@ def update(self):
253263 self .apply_matching (self .value .matching )
254264 for k ,d in self .dominos .items ():
255265 d .compute (self .css_classes )
266+ d .set_value (False ) # unpress buttons
256267
257268 def match (self , b1 , b2 ):
258269 """Match buttons b1 and b2, that is: create a domino"""
0 commit comments