From 726c52191b687252d447dd92122f74653c3271b8 Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Thu, 20 Mar 2014 09:12:42 -0700 Subject: Fixed spelling - renamed wordseach occurrences to wordsearch. --- js/utility.min.js | 2 +- js/wordsearch.js | 34 +++++++++++++++++----------------- js/wordsearch.min.js | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'js') diff --git a/js/utility.min.js b/js/utility.min.js index 5f5a5f6..a8b0a58 100644 --- a/js/utility.min.js +++ b/js/utility.min.js @@ -1 +1 @@ -if(typeof Math.rangeInt!="function"){Math.rangeInt=function(b,a){if(a==undefined){a=b;b=0}return Math.floor(Math.random()*(a-b+1))+b}}if(typeof Object.merge!="function"){Object.merge=function(c,b){for(var a in c){b[a]=c[a]}return b}}; \ No newline at end of file +"function"!=typeof Math.rangeInt&&(Math.rangeInt=function(n,t){return void 0==t&&(t=n,n=0),Math.floor(Math.random()*(t-n+1))+n}),"function"!=typeof Object.merge&&(Object.merge=function(n,t){for(var e in n)t[e]=n[e];return t}); \ No newline at end of file diff --git a/js/wordsearch.js b/js/wordsearch.js index 37dfa25..222b94f 100644 --- a/js/wordsearch.js +++ b/js/wordsearch.js @@ -2,8 +2,8 @@ 'use strict'; // Extend the element method - Element.prototype.wordSeach = function(settings) { - return new WordSeach(this, settings); + Element.prototype.wordSearch = function(settings) { + return new WordSearch(this, settings); } /** @@ -13,7 +13,7 @@ * @param {Array} settings * constructor */ - function WordSeach(wrapEl, settings) { + function WordSearch(wrapEl, settings) { this.wrapEl = wrapEl; // Add `.ws-area` to wrap element @@ -55,7 +55,7 @@ * @param {Number} Max size * @return {Boolean} */ - WordSeach.prototype.parseWords = function(maxSize) { + WordSearch.prototype.parseWords = function(maxSize) { var itWorked = true; for (var i = 0; i < this.settings.words.length; i++) { @@ -76,7 +76,7 @@ /** * Put the words into the matrix */ - WordSeach.prototype.addWords = function() { + WordSearch.prototype.addWords = function() { var keepGoing = true, counter = 0, isWorked = true; @@ -107,7 +107,7 @@ * @param {String} word * @param {Number} direction */ - WordSeach.prototype.addWord = function(word, direction) { + WordSearch.prototype.addWord = function(word, direction) { var itWorked = true, directions = { 'W': [0, 1], // Horizontal (From left to right) @@ -166,7 +166,7 @@ /** * Initialize the application */ - WordSeach.prototype.initialize = function() { + WordSearch.prototype.initialize = function() { /** * Letter matrix * @@ -192,7 +192,7 @@ * Fill default items into the matrix * @param {Number} size Grid size */ - WordSeach.prototype.initmatrix = function(size) { + WordSearch.prototype.initmatrix = function(size) { for (var row = 0; row < size; row++) { for (var col = 0; col < size; col++) { var item = { @@ -213,7 +213,7 @@ /** * Draw the matrix */ - WordSeach.prototype.drawmatrix = function() { + WordSearch.prototype.drawmatrix = function() { for (var row = 0; row < this.settings.gridSize; row++) { // New row var divEl = document.createElement('div'); @@ -250,7 +250,7 @@ /** * Fill up the remaining items */ - WordSeach.prototype.fillUpFools = function() { + WordSearch.prototype.fillUpFools = function() { for (var row = 0; row < this.settings.gridSize; row++) { for (var col = 0; col < this.settings.gridSize; col++) { if (this.matrix[row][col].letter == '.') { @@ -269,7 +269,7 @@ * @param colTo * @return {Array} */ - WordSeach.prototype.getItems = function(rowFrom, colFrom, rowTo, colTo) { + WordSearch.prototype.getItems = function(rowFrom, colFrom, rowTo, colTo) { var items = []; if ( rowFrom === rowTo || colFrom === colTo || Math.abs(rowTo - rowFrom) == Math.abs(colTo - colFrom) ) { @@ -295,14 +295,14 @@ * @param {Number} col * @return {*} */ - WordSeach.prototype.getItem = function(row, col) { + WordSearch.prototype.getItem = function(row, col) { return (this.matrix[row] ? this.matrix[row][col] : undefined); } /** * Clear the exist highlights */ - WordSeach.prototype.clearHighlight = function() { + WordSearch.prototype.clearHighlight = function() { var selectedEls = document.querySelectorAll('.ws-selected'); for (var i = 0; i < selectedEls.length; i++) { selectedEls[i].classList.remove('ws-selected'); @@ -313,7 +313,7 @@ * Lookup if the wordlist contains the selected * @param {Array} selected */ - WordSeach.prototype.lookup = function(selected) { + WordSearch.prototype.lookup = function(selected) { var words = ['']; for (var i = 0; i < selected.length; i++) { @@ -337,7 +337,7 @@ * MouseĀ event - Mouse down * @param {Object} item */ - WordSeach.prototype.onMousedown = function(item) { + WordSearch.prototype.onMousedown = function(item) { var _this = this; return function() { _this.selectFrom = item; @@ -348,7 +348,7 @@ * Mouse event - Mouse move * @param {Object} */ - WordSeach.prototype.onMouseover = function(item) { + WordSearch.prototype.onMouseover = function(item) { var _this = this; return function() { if (_this.selectFrom) { @@ -371,7 +371,7 @@ /** * Mouse event - Mouse up */ - WordSeach.prototype.onMouseup = function() { + WordSearch.prototype.onMouseup = function() { var _this = this; return function() { _this.selectFrom = null; diff --git a/js/wordsearch.min.js b/js/wordsearch.min.js index 76854e3..a825a89 100644 --- a/js/wordsearch.min.js +++ b/js/wordsearch.min.js @@ -1 +1 @@ -(function(){Element.prototype.wordSeach=function(b){return new a(this,b)};function a(b,d){this.wrapEl=b;this.wrapEl.classList.add("ws-area");var c={"directions":["W","N","WN","EN"],"gridSize":10,"words":["one","two","three","four","five"],"debug":false};this.settings=Object.merge(d,c);if(this.parseWords(this.settings.gridSize)){var e=false;while(e==false){this.initialize();e=this.addWords()}if(!this.settings.debug){this.fillUpFools()}this.drawmatrix()}}a.prototype.parseWords=function(e){var b=true;for(var c=0;ce){alert("The length of word `"+d+"` is overflow the gridSize.");console.error("The length of word `"+d+"` is overflow the gridSize.");b=false}}return b};a.prototype.addWords=function(){var e=true,c=0,f=true;while(e){var d=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],b=this.addWord(this.settings.words[c],d),f=true;if(b==false){e=false;f=false}c++;if(c>=this.settings.words.length){e=false}}return f};a.prototype.addWord=function(b,j){var d=true,g={"W":[0,1],"N":[1,0],"WN":[1,1],"EN":[1,-1]},m,e;switch(j){case"W":var m=Math.rangeInt(this.settings.gridSize-1),e=Math.rangeInt(this.settings.gridSize-b.length);break;case"N":var m=Math.rangeInt(this.settings.gridSize-b.length),e=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var m=Math.rangeInt(this.settings.gridSize-b.length),e=Math.rangeInt(this.settings.gridSize-b.length);break;case"EN":var m=Math.rangeInt(this.settings.gridSize-b.length),e=Math.rangeInt(b.length-1,this.settings.gridSize-1);break;default:var h="UNKNOWN DIRECTION "+j+"!";alert(h);console.log(h);break}for(var f=0;fe)?1:-1,g=(c===h)?0:(h>c)?1:-1,j=e,b=c;d.push(this.getItem(j,b));do{j+=f;b+=g;d.push(this.getItem(j,b))}while(j!==i||b!==h)}return d};a.prototype.getItem=function(c,b){return(this.matrix[c]?this.matrix[c][b]:undefined)};a.prototype.clearHighlight=function(){var b=document.querySelectorAll(".ws-selected");for(var c=0;c-1||this.settings.words.indexOf(g[1])>-1){for(var c=0;ct&&(alert("The length of word `"+r+"` is overflow the gridSize."),console.error("The length of word `"+r+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,i=!0;t;){var r=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],r),i=!0;0==s&&(t=!1,i=!1),e++,e>=this.settings.words.length&&(t=!1)}return i},t.prototype.addWord=function(t,e){var i,r,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var i=Math.rangeInt(this.settings.gridSize-1),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var i=0;t>i;i++){var r={letter:".",row:e,col:i};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][i]=r}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===r?0:r>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==i||h!==r)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1)for(var i=0;i Date: Thu, 20 Mar 2014 09:31:21 -0700 Subject: Updated lookup so that it crosses word off list if found. --- js/wordsearch.js | 9 +++++++++ js/wordsearch.min.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/wordsearch.js b/js/wordsearch.js index 222b94f..17b54d8 100644 --- a/js/wordsearch.js +++ b/js/wordsearch.js @@ -330,6 +330,15 @@ el.classList.add('ws-found'); } + + //Cross word off list. + var wordList = document.querySelector(".ws-words"); + var wordListItems = wordList.getElementsByTagName("li"); + for(var i=0; i"; + } + } } } diff --git a/js/wordsearch.min.js b/js/wordsearch.min.js index a825a89..8bc3957 100644 --- a/js/wordsearch.min.js +++ b/js/wordsearch.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e){this.wrapEl=t,this.wrapEl.classList.add("ws-area");var i={directions:["W","N","WN","EN"],gridSize:10,words:["one","two","three","four","five"],debug:!1};if(this.settings=Object.merge(e,i),this.parseWords(this.settings.gridSize)){for(var r=!1;0==r;)this.initialize(),r=this.addWords();this.settings.debug||this.fillUpFools(),this.drawmatrix()}}Element.prototype.wordSearch=function(e){return new t(this,e)},t.prototype.parseWords=function(t){for(var e=!0,i=0;it&&(alert("The length of word `"+r+"` is overflow the gridSize."),console.error("The length of word `"+r+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,i=!0;t;){var r=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],r),i=!0;0==s&&(t=!1,i=!1),e++,e>=this.settings.words.length&&(t=!1)}return i},t.prototype.addWord=function(t,e){var i,r,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var i=Math.rangeInt(this.settings.gridSize-1),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var i=0;t>i;i++){var r={letter:".",row:e,col:i};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][i]=r}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===r?0:r>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==i||h!==r)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1)for(var i=0;it&&(alert("The length of word `"+i+"` is overflow the gridSize."),console.error("The length of word `"+i+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,r=!0;t;){var i=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],i),r=!0;0==s&&(t=!1,r=!1),e++,e>=this.settings.words.length&&(t=!1)}return r},t.prototype.addWord=function(t,e){var r,i,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var r=Math.rangeInt(this.settings.gridSize-1),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var r=0;t>r;r++){var i={letter:".",row:e,col:r};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][r]=i}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===i?0:i>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==r||h!==i)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1){for(var r=0;r"+a[r].innerHTML+"")}},t.prototype.onMousedown=function(t){var e=this;return function(){e.selectFrom=t}},t.prototype.onMouseover=function(t){var e=this;return function(){if(e.selectFrom){e.selected=e.getItems(e.selectFrom.row,e.selectFrom.col,t.row,t.col),e.clearHighlight();for(var r=0;r Date: Thu, 20 Mar 2014 14:16:50 -0700 Subject: Added very simple solved word tracker and Game Over overlay. --- css/style.css | 1 + css/style.min.css | 2 +- css/wordsearch.css | 37 +++++++++++++++++++++++++++++++++++++ css/wordsearch.min.css | 2 +- js/wordsearch.js | 31 +++++++++++++++++++++++++++++++ js/wordsearch.min.js | 2 +- 6 files changed, 72 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/css/style.css b/css/style.css index f68994c..6c4a5ef 100644 --- a/css/style.css +++ b/css/style.css @@ -32,6 +32,7 @@ body { margin: 0 auto; padding: 40px 0; text-align: center; + position:relative; } .logo, #gameArea { diff --git a/css/style.min.css b/css/style.min.css index 36d31ef..98940d1 100644 --- a/css/style.min.css +++ b/css/style.min.css @@ -1 +1 @@ -body,h1{margin:0;padding:0}h1{text-transform:uppercase}body{color:#333}.wrap{width:960px;margin:0 auto;padding:40px 0;text-align:center}.logo,#gameArea{margin-bottom:40px}.ws-area,.ws-words{display:inline-block;vertical-align:top}.ws-words{margin-left:20px;text-align:left}.ws-word{margin-bottom:4px} \ No newline at end of file +body,h1{margin:0;padding:0}h1{text-transform:uppercase}body{color:#333}.fix{zoom:1}.fix:after{display:table;clear:both;content:''}.wrap{width:960px;text-align:center;position:relative;margin:0 auto;padding:40px 0}.logo,#gamearea{margin-bottom:40px}.ws-area,.ws-words{display:inline-block;vertical-align:top}.ws-words{margin-left:20px;text-align:left}.ws-word{margin-bottom:4px} \ No newline at end of file diff --git a/css/wordsearch.css b/css/wordsearch.css index 02853f0..149c36e 100644 --- a/css/wordsearch.css +++ b/css/wordsearch.css @@ -25,4 +25,41 @@ .ws-found { background: yellow; +} + +.ws-game-over-outer { + background: rgba(0, 0, 0, 0.85); + height: 100%; + left: 0; + position: absolute; + top: 0; + width: 100%; +} + +.ws-game-over-inner { + width:100%; + height:100%; + padding:0; + margin:0; + display:table; +} + +.ws-game-over { + display:table-cell; + vertical-align:middle; +} + +.ws-game-over h2 { + color:#FFFFFF; + font-size:2em; + text-transform:uppercase; + padding:0; + margin:0 0 9px 0; +} + +.ws-game-over p { + color:#FFFFFF; + font-size:1em; + padding:0; + margin:0; } \ No newline at end of file diff --git a/css/wordsearch.min.css b/css/wordsearch.min.css index ac2f261..0e49dc3 100644 --- a/css/wordsearch.min.css +++ b/css/wordsearch.min.css @@ -1 +1 @@ -.ws-area{background:#fafafa;display:inline-block;padding:20px;border-radius:10px;-moz-user-select:-moz-none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none}.ws-row{line-height:0}.ws-col{cursor:pointer}.ws-col.ws-selected{background:#eee}.ws-found{background:yellow} \ No newline at end of file +.ws-area{background:#fafafa;display:inline-block;border-radius:10px;-moz-user-select:0;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;padding:20px}.ws-row{line-height:0}.ws-col{cursor:pointer}.ws-col.ws-selected{background:#eee}.ws-found{background:#FF0}.ws-game-over-outer{background:rgba(0,0,0,0.85);height:100%;left:0;position:absolute;top:0;width:100%}.ws-game-over-inner{width:100%;height:100%;display:table;margin:0;padding:0}.ws-game-over{display:table-cell;vertical-align:middle}.ws-game-over h2{color:#FFF;font-size:2em;text-transform:uppercase;margin:0 0 9px;padding:0}.ws-game-over p{color:#FFF;font-size:1em;margin:0;padding:0} \ No newline at end of file diff --git a/js/wordsearch.js b/js/wordsearch.js index 17b54d8..964f61d 100644 --- a/js/wordsearch.js +++ b/js/wordsearch.js @@ -19,6 +19,9 @@ // Add `.ws-area` to wrap element this.wrapEl.classList.add('ws-area'); + //Words solved. + this.solved = 0; + // Default settings var default_settings = { 'directions': ['W', 'N', 'WN', 'EN'], @@ -339,9 +342,37 @@ wordListItems[i].innerHTML = ""+wordListItems[i].innerHTML+""; } } + + //Increment solved words. + this.solved++; + + //Game over? + if(this.solved == this.settings.words.length){ + this.gameOver(); + } } } + /** + * Game Over + */ + WordSearch.prototype.gameOver = function() { + //Create overlay. + var overlay = document.createElement("div"); + overlay.setAttribute("id", "ws-game-over-outer"); + overlay.setAttribute("class", "ws-game-over-outer"); + this.wrapEl.parentNode.appendChild(overlay); + + //Create overlay content. + var overlay = document.getElementById("ws-game-over-outer"); + overlay.innerHTML = "
"+ + "
"+ + "

Congratulations!

"+ + "

You've found all of the words!

"+ + "
"+ + "
"; + } + /** * MouseĀ event - Mouse down * @param {Object} item diff --git a/js/wordsearch.min.js b/js/wordsearch.min.js index 8bc3957..2511d88 100644 --- a/js/wordsearch.min.js +++ b/js/wordsearch.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e){this.wrapEl=t,this.wrapEl.classList.add("ws-area");var r={directions:["W","N","WN","EN"],gridSize:10,words:["one","two","three","four","five"],debug:!1};if(this.settings=Object.merge(e,r),this.parseWords(this.settings.gridSize)){for(var i=!1;0==i;)this.initialize(),i=this.addWords();this.settings.debug||this.fillUpFools(),this.drawmatrix()}}Element.prototype.wordSearch=function(e){return new t(this,e)},t.prototype.parseWords=function(t){for(var e=!0,r=0;rt&&(alert("The length of word `"+i+"` is overflow the gridSize."),console.error("The length of word `"+i+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,r=!0;t;){var i=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],i),r=!0;0==s&&(t=!1,r=!1),e++,e>=this.settings.words.length&&(t=!1)}return r},t.prototype.addWord=function(t,e){var r,i,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var r=Math.rangeInt(this.settings.gridSize-1),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var r=0;t>r;r++){var i={letter:".",row:e,col:r};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][r]=i}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===i?0:i>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==r||h!==i)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1){for(var r=0;r"+a[r].innerHTML+"")}},t.prototype.onMousedown=function(t){var e=this;return function(){e.selectFrom=t}},t.prototype.onMouseover=function(t){var e=this;return function(){if(e.selectFrom){e.selected=e.getItems(e.selectFrom.row,e.selectFrom.col,t.row,t.col),e.clearHighlight();for(var r=0;rt&&(alert("The length of word `"+i+"` is overflow the gridSize."),console.error("The length of word `"+i+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,r=!0;t;){var i=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],i),r=!0;0==s&&(t=!1,r=!1),e++,e>=this.settings.words.length&&(t=!1)}return r},t.prototype.addWord=function(t,e){var r,i,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var r=Math.rangeInt(this.settings.gridSize-1),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var r=0;t>r;r++){var i={letter:".",row:e,col:r};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][r]=i}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===i?0:i>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==r||h!==i)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1){for(var r=0;r"+a[r].innerHTML+"");this.solved++,this.solved==this.settings.words.length&&this.gameOver()}},t.prototype.gameOver=function(){var t=document.createElement("div");t.setAttribute("id","ws-game-over-outer"),t.setAttribute("class","ws-game-over-outer"),this.wrapEl.parentNode.appendChild(t);var t=document.getElementById("ws-game-over-outer");t.innerHTML="

Congratulations!

You've found all of the words!

"},t.prototype.onMousedown=function(t){var e=this;return function(){e.selectFrom=t}},t.prototype.onMouseover=function(t){var e=this;return function(){if(e.selectFrom){e.selected=e.getItems(e.selectFrom.row,e.selectFrom.col,t.row,t.col),e.clearHighlight();for(var r=0;r