I am trying to create a words search puzzle generated by script. The words should be placed horizontally, vertically or diagonally. I might need the option to set whether they are allowed to read only forward or backward. I have an array of words such as (apple, banana, grape, lemon, pear) which needs to be placed in the table. I have already created the table but I am stuck at how to place the words in the grid.
I am looking for examples with some explanation.
Please see my code below:
var wordsList =[
"apple",
"banana",
"grape",
"lemon",
"pear" ];
var cells = 10; // Numbers of cells horizontally and vertically in table grid
var cellSize = 15; // in pixels
var cellSpace = 2; // cell spacing in pixels
function createPuzzleTable(cells) {
var totalNumRows = "";
var totalNumColumns = "";
//creating rows
for (r=1;r<=cells;r++){
//creating cells
var oneCell = "<td width='" + cellSize + "' height='"+ cellSize + "'><input name='charField' type='text' /></td>";
totalNumRows += oneCell;
}
//creating columns
for (c=1;c<=cells;c++){
totalNumColumns += "<tr>" + totalNumRows + "</tr>";
}
var puzzleTableContent = "<div id='puzzleCont'><table id='puzzleTable' border='0' cellspacing='" + cellSpace +"' cellpadding='0'>"+ totalNumColumns +"</table></div>";
$("#wPuzzle").append(puzzleTableContent);
}
createPuzzleTable(cells);