wordPuzzle
Kind: global class
- wordPuzzle
- new wordPuzzle()
- instance
- .wordList
- .placeWordInPuzzle(puzzle, opts, word) ⇒
boolean
- .newPuzzle([wordList], [options]) ⇒
Array.<Array>
- .newPuzzleLax(opts)
- .solve(puzzle, words) ⇒
Array.<{x: number, y: number, orientation: string, word: string, overlap: number}>
- .print(puzzle) ⇒
string
- .drawPuzzle([domElem], [puzzle])
- .setEventHandlers([domElem])
- static
new wordPuzzle()
Create a words puzzle game
wordPuzzle.wordList
Kind: instance property of wordPuzzle
Param | Type | Description |
---|---|---|
wordList | Array.<string> |
copy and sort the words by length, inserting words into the puzzle from longest to shortest works out the best |
boolean
wordPuzzle.placeWordInPuzzle(puzzle, opts, word) ⇒ Adds the specified word to the puzzle by finding all of the possible locations where the word will fit and then randomly selecting one
Kind: instance method of wordPuzzle
Returns: boolean
- true if the word was successfully placed, false otherwise
Param | Type | Description |
---|---|---|
puzzle | Array.<Array> |
current state of the puzzle |
opts | Object |
controls whether or not word overlap should be maximized |
word | string |
word to fit into the puzzle |
Array.<Array>
wordPuzzle.newPuzzle([wordList], [options]) ⇒ Kind: instance method of wordPuzzle
Param | Type | Default |
---|---|---|
[wordList] | Array.<string> |
this.wordList |
[options] | Object |
this.opts |
wordPuzzle.newPuzzleLax(opts)
Wrapper around newPuzzle
allowing to find a solution without some words
Kind: instance method of wordPuzzle
Param | Type | Description |
---|---|---|
opts | Object |
options to use for this puzzle |
Array.<{x: number, y: number, orientation: string, word: string, overlap: number}>
wordPuzzle.solve(puzzle, words) ⇒ Returns the starting location and orientation of the specified words within the puzzle. Any words that are not found are returned in the notFound array
Kind: instance method of wordPuzzle
Access: public
Param | Type |
---|---|
puzzle | Array.<Array> |
words | Array.<string> |
string
wordPuzzle.print(puzzle) ⇒ Outputs a puzzle to the console, useful for debugging
Kind: instance method of wordPuzzle
Returns: string
- formatted string representing the puzzle
Param | Type | Description |
---|---|---|
puzzle | Array.<Array> |
current state of the puzzle |
wordPuzzle.drawPuzzle([domElem], [puzzle])
Draws the puzzle by inserting rows of buttons into the DOM Element
Kind: instance method of wordPuzzle
Param | Type | Default |
---|---|---|
[domElem] | HTMLElement |
this.domElem |
[puzzle] | Array.<Array> |
this.finalPuzzle |
wordPuzzle.setEventHandlers([domElem])
Set the event handlers that will trigger the recognition of the words
Kind: instance method of wordPuzzle
Param | Type | Default |
---|---|---|
[domElem] | HTMLElement |
this.domElem |
wordPuzzle.wordPuzzle
Kind: static class of wordPuzzle
new wordPuzzle(words, domElem, [opts])
Creates an instance of wordPuzzle.
Param | Type | Default | Description |
---|---|---|---|
words | Array.<string> |
list of words to include in the puzzle | |
domElem | HTMLElement |
HTML DOM Element that will contain the game | |
[opts] | Object |
{} |
game options |
[opts.lang] | string |
define the letters set to use, depending on the words language, must be the ISO 639-1 language code, default: EN | |
[opts.heigth] | number |
desired height of the puzzle, default: smallest possible | |
[opts.width] | number |
desired width of the puzzle, default: smallest possible | |
[opts.orientations] | Array.<string> |
allOrientations |
list the authorized orientations in which the words can be formed, default: allOrientations |
[opts.fillBlanks] | boolean |
true |
do the game must fill the spaces not used to form a word with random letters, default: true |
[opts.allowExtraBlanks] | boolean |
true |
can the game add additional blanks, default: true |
[opts.maxAttempts] | number |
3 |
number of tries before increasing puzzle size, default: 3 |
[opts.maxGridGrowth] | number |
10 |
number of puzzle grid increases, default: 10 |
[opts.preferOverlap] | boolean |
true |
maximize word overlap or not, default: true |
[opts.debug] | boolean |
false |
wether or not to print the puzzle to the console, default: false |