@@ -29,13 +29,11 @@ def set_cell(self, obj, pos, val=True, dirty={}):
29
29
if not dirty [p ]: # check this position is pressed
30
30
continue
31
31
d2 = obj .domino_for_position (p )
32
- if d2 == d1 :
32
+ if d2 == d1 or not d2 in d1 . neighbors () :
33
33
continue
34
34
if d2 in d1 .neighbors ():
35
35
# Do the flip
36
36
obj .flip (d1 , d2 )
37
- #obj.matching[d1.first] = d1
38
- #obj.matching[d2.first] = d2
39
37
return obj
40
38
return Exception ("Please select a second domino!" )
41
39
else :
@@ -201,13 +199,25 @@ def is_pressed(self):
201
199
"""Is the domino pressed?"""
202
200
return self .value
203
201
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
+
204
212
def reset (self ):
205
213
"""Full domino reset"""
206
- self .value = False
214
+ self .set_value ( False )
207
215
self .link .unlink ()
208
216
209
217
def flip (self , other ):
210
218
"""Flip self with some neighboring domino"""
219
+ if other == self or other .geometry == self .geometry :
220
+ return
211
221
self .reset ()
212
222
other .reset ()
213
223
self .geometry .flip (other .geometry )
@@ -253,6 +263,7 @@ def update(self):
253
263
self .apply_matching (self .value .matching )
254
264
for k ,d in self .dominos .items ():
255
265
d .compute (self .css_classes )
266
+ d .set_value (False ) # unpress buttons
256
267
257
268
def match (self , b1 , b2 ):
258
269
"""Match buttons b1 and b2, that is: create a domino"""
0 commit comments