def on_touch_down(self, touch): """ :param touch: :rtype: void """ # Save current path. self.player_path = [] # get if player can draw here self.tile_identifier = get_tile_identifier(self, touch.x, touch.y) if self.tile_identifier is None: can_draw = False else: can_draw = can_start_stop(self.tile_identifier, self.map_canvas.points) if not can_draw: self.failed_attempts += 1 self.canvas.after.clear() return self.canvas.after.add( Point(points=(touch.x, touch.y), texture=self.trace_texture, pointsize=self.touch_width) ) # Save tile. self.old_tile_identifier = self.tile_identifier[:] self.player_path.append((self.tile_identifier[0], self.tile_identifier[1])) self.old_point = [touch.x, touch.y] touch.grab(self)
def on_touch_up(self, touch): """ :param touch: :rtype: void """ if touch.grab_current is not self: return # get if player can draw here self.tile_identifier = get_tile_identifier(self, touch.x, touch.y) if self.tile_identifier is None: can_draw = False else: can_draw = can_start_stop(self.tile_identifier, self.map_canvas.points) if can_draw: # Delete touch if player loose. if self.is_path_correct(): return self.propagate_level_up() else: self.failed_attempts += 1 touch.ungrab(self) self.canvas.after.clear() return