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.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'js/wordsearch.js') 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 -- cgit v1.2.3