def try_to_explode(self, gem): '''If the gem is a crash gem, try to explode it.''' for neighbor in gem.get_neighbors(): if not neighbor is None and neighbor.color == gem.color: if not neighbor.active and not neighbor.counter > 0: exploded = self.explode(gem) return exploded return 0
def explode(self, gem): '''Blows up the gem and nearby gems.''' self.remove(gem) neighbors = gem.get_neighbors() exploded = 0 for neighbor in neighbors: if not neighbor is None and neighbor.color == gem.color: if not neighbor.active and not neighbor.counter > 0: exploded += 1 + self.explode(neighbor) return exploded