I am trying to make a fairly simple grid game where users have to click tiles to reveal content underneath. The first issue i’m struggling with is implementing a click function that would remove not only the tile clicked but also a few tiles around it, preferably random.
My current code:
$('.layer img').click(function() {
$(this).css ('display', 'none');
});
Any help extending my simple code much appreciated.
You can count the siblings and randomly hide some of them, like so:
I’m adding here enhanced version, as OP commented, to randomly select previous or next siblings, up to 5 five of them in total:
the code grew a bit because we have to control whether there are no more previous or next siblings, and in that case revert to the other.