我正在尝试创建一个由脚本生成的单词搜索谜题。单词应水平,垂直或对角放置。我可能需要设置是否允许它们仅向前或向后读取的选项。我有一系列需要放在桌子上的单词,例如(苹果、香蕉、葡萄、柠檬、梨)。我已经创建了表格,但我被困在如何将单词放在网格中。
我正在寻找一些解释的例子。
请在下面查看我的代码:
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);