From 8c81bfbcdf3451ae634927a1270c40941ba02d5e Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Thu, 20 Mar 2014 14:16:50 -0700 Subject: Added very simple solved word tracker and Game Over overlay. --- js/wordsearch.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/wordsearch.min.js') 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