将表格网格中的单词放置在单词搜索难题中?

编程入门 行业动态 更新时间:2024-10-22 02:43:24
本文介绍了将表格网格中的单词放置在单词搜索难题中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建由脚本生成的单词搜索难题.单词应水平,垂直或对角放置.我可能需要选项来设置是否允许它们仅向前或向后读取. 我有一些单词(例如,苹果,香蕉,葡萄,柠檬,梨)需要放在桌子上.我已经创建了表格,但是我仍然坚持如何将单词放置在网格中.

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);

推荐答案

已经有一个执行此操作的jquery小部件: code.google/p/jquery-wordsearch-game/

There's already a jquery widget that does this: code.google/p/jquery-wordsearch-game/

看看此代码.它使用策略模式在向前,向后,向上,向下和两个对角线方向上将单词放置在网格上.具体来说,请看第547行.

Have a look at this code. It uses the Strategy Pattern to place words on the grid in the forward, backward, up, down and both diagonal directions. Specifically, look at line 547 onwards.

由于学习是您的强项,所以您可能会发现它很有趣..并且可能提出了一种更好的方法.

Since learning is your strong point, you might find it fun.. and probably come up with an even better way of doing it.

更多推荐

将表格网格中的单词放置在单词搜索难题中?

本文发布于:2023-11-23 04:48:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   网格   表格   难题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!