Problems with Tic-Tac-Toe after Reset

Problems with Tic-Tac-Toe after Reset
0

#1

Hi There,
I was trying to build the Tic-TacToe game. For the first time while playing with the Computer, everything seems to work fine. Once you press the “Reset All” button, and play again with the computer, It looks like robots took over the game. There are multiple clicks automatically, and sometime you seem to win the game only after one click due to these automatic clicks. Little help would be highly appreciated. :frowning:

Full Page View


#2

My guess would be that you’re not resetting the event handlers properly, those that need it. Stick some debugging in your ai function to see what’s going on and from where.


#3

Yup, found that out.
I was using

$('td').on('click', function () 
{
    tdClicked(this);
});

function tdClicked(obj)
{
	alert(obj.id);
}

 $('td').off('click');

After switching it off in the last line, there were two methods setting it back on, hence resetting was not happening properly. Hence, now the resetting is done by switching all others handlers off, and then setting a new one.

$('td').off().on('click', function() 
{
       tdClicked(this);
});

Thanks for the help.