将表格网格中的单词放置在单词搜索难题中? [英] Placing words in table grid in word search puzzle?

查看:90
本文介绍了将表格网格中的单词放置在单词搜索难题中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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小部件: http://code.google.com/p/jquery-wordsearch-game/

There's already a jquery widget that does this: http://code.google.com/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.

这篇关于将表格网格中的单词放置在单词搜索难题中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆