diff options
| author | Steven Thomas <[email protected]> | 2014-03-20 14:16:50 -0700 |
|---|---|---|
| committer | Steven Thomas <[email protected]> | 2014-03-20 14:16:50 -0700 |
| commit | 8c81bfbcdf3451ae634927a1270c40941ba02d5e (patch) | |
| tree | d094af77cc9a17bbfaa7ac0d68040f5d4c91a7a7 /js/wordsearch.js | |
| parent | 6e28e7607bd492c960f40260d1de64e26652e2ba (diff) | |
| download | word-search-game-8c81bfbcdf3451ae634927a1270c40941ba02d5e.tar.gz word-search-game-8c81bfbcdf3451ae634927a1270c40941ba02d5e.zip | |
Added very simple solved word tracker and Game Over overlay.
Diffstat (limited to 'js/wordsearch.js')
| -rw-r--r-- | js/wordsearch.js | 31 |
1 files changed, 31 insertions, 0 deletions
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,10 +342,38 @@ wordListItems[i].innerHTML = "<del>"+wordListItems[i].innerHTML+"</del>"; } } + + //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 = "<div class='ws-game-over-inner' id='ws-game-over-inner'>"+ + "<div class='ws-game-over' id='ws-game-over'>"+ + "<h2>Congratulations!</h2>"+ + "<p>You've found all of the words!</p>"+ + "</div>"+ + "</div>"; + } + + /** * MouseĀ event - Mouse down * @param {Object} item */ |
