I'm trying to make a simple numbers games using jQuery. I built a 7x7 grid using an html table. I created some jQuery functions to allow the user to highlight and un-highlight cells in the table. I would like to make it so that the first cell the user selects must be in the far left column, and then each subsequent cell selected must be adjacent to one that is highlighted, until they connect cells all the way to the right side of the table. The cells will have numbers in them and there will be some gamey functionality that I haven't set in stone yet.
With a simple boolean and some if-logic I established that the first cell must be from the left column, but now I'm having trouble making sure that each subsequent cell be one that is adjacent to a highlighted cell. I have given each td in the table a numbered id, from 1-49 (7 rows of 7). When a user selects a cell I capture that cell's id in an array called cellCoord. I was hoping that something like this might work:
var thisCell = parseInt($(this).attr('id'));
if (thisCell == (cellCoord[i]+1) || thisCell == (cellCoord[i]-1) ||
thisCell == (cellCoord[i]+7) || thisCell == (cellCoord[i]-7))
Unfortunately it doesn't. Any suggestions?
An early draft of my efforts can be found here.