1.0.0 • Published 6 years ago

wordpuzzle v1.0.0

Weekly downloads
7
License
-
Repository
github
Last release
6 years ago

wordPuzzle

Kind: global class

new wordPuzzle()

Create a words puzzle game

wordPuzzle.wordList

Kind: instance property of wordPuzzle

ParamTypeDescription
wordListArray.<string>copy and sort the words by length, inserting words into the puzzle from longest to shortest works out the best

wordPuzzle.placeWordInPuzzle(puzzle, opts, word) ⇒ boolean

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

ParamTypeDescription
puzzleArray.<Array>current state of the puzzle
optsObjectcontrols whether or not word overlap should be maximized
wordstringword to fit into the puzzle

wordPuzzle.newPuzzle(wordList, options) ⇒ Array.<Array>

Kind: instance method of wordPuzzle

ParamTypeDefault
wordListArray.<string>this.wordList
optionsObjectthis.opts

wordPuzzle.newPuzzleLax(opts)

Wrapper around newPuzzle allowing to find a solution without some words

Kind: instance method of wordPuzzle

ParamTypeDescription
optsObjectoptions to use for this puzzle

wordPuzzle.solve(puzzle, words) ⇒ Array.<{x: number, y: number, orientation: string, word: string, overlap: number}>

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

ParamType
puzzleArray.<Array>
wordsArray.<string>

wordPuzzle.print(puzzle) ⇒ string

Outputs a puzzle to the console, useful for debugging

Kind: instance method of wordPuzzle Returns: string - formatted string representing the puzzle

ParamTypeDescription
puzzleArray.<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

ParamTypeDefault
domElemHTMLElementthis.domElem
puzzleArray.<Array>this.finalPuzzle

wordPuzzle.setEventHandlers(domElem)

Set the event handlers that will trigger the recognition of the words

Kind: instance method of wordPuzzle

ParamTypeDefault
domElemHTMLElementthis.domElem

wordPuzzle.wordPuzzle

Kind: static class of wordPuzzle

new wordPuzzle(words, domElem, opts)

Creates an instance of wordPuzzle.

ParamTypeDefaultDescription
wordsArray.<string>list of words to include in the puzzle
domElemHTMLElementHTML DOM Element that will contain the game
optsObject{}game options
opts.langstringdefine the letters set to use, depending on the words language, must be the ISO 639-1 language code, default: EN
opts.heigthnumberdesired height of the puzzle, default: smallest possible
opts.widthnumberdesired width of the puzzle, default: smallest possible
opts.orientationsArray.<string>allOrientationslist the authorized orientations in which the words can be formed, default: allOrientations
opts.fillBlanksbooleantruedo the game must fill the spaces not used to form a word with random letters, default: true
opts.allowExtraBlanksbooleantruecan the game add additional blanks, default: true
opts.maxAttemptsnumber3number of tries before increasing puzzle size, default: 3
opts.maxGridGrowthnumber10number of puzzle grid increases, default: 10
opts.preferOverlapbooleantruemaximize word overlap or not, default: true
opts.debugbooleanfalsewether or not to print the puzzle to the console, default: false
1.0.0

6 years ago