Placing words in table grid in word search puzzle?

一笑奈何 提交于 2019-12-04 12:22:45

First, you need to establish an easy method to locating items in your grid. Use class names:

<input name='charField' class="r_2 c_3" type='text' />

Where "r_" represents rows and "c_" columns.

Then randomly select a direction and a location (row, column). See if the word will fit and that the square isn't already occupied, otherwise choose again.

Then drop letters into the grid using r_ c_ coordinate system.

Repeat.

Fill in unoccupied cells with pseudo-random filler data.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!