previous

page 25

next
click on lots of cards rapidly and many are turned

This occurs because the player is able to click while the timers are running so what we need is a way to disallow clicking when we start the timers.

I came up with the idea of a click_ok variable which is set to true at the start but is set to false when we start a timer.
The functions called by the timer will set it back to true.

<script>
var click_ok=true;

... and then just before calling the timers, I set it to false:

click_ok=false;
if (n1==n2) {
setTimeout(clear,1000,card1);
setTimeout(clear,1000,image);
} else {
setTimeout(turn,2000,card1);
setTimeout(turn,2000,image);
}

All that remains is to make use of click_ok in the card_clicked function.
&& is JavaScript for and

if (image.src==back_src && click_ok) {

Don't forget to set click_ok back to true in both turn and clear.

previous
next