From 79d84f2040068424994eecf542fee3686849845c Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Mon, 27 Aug 2012 00:36:38 -0500 Subject: Created remanants of a challenge page (loaded completely from the database). Kept the old challenge page, because Snap will probably want to reuse the Javascript. --- pages/challenge.php | 513 +++++++++++++++++++--------------------------------- 1 file changed, 187 insertions(+), 326 deletions(-) (limited to 'pages/challenge.php') diff --git a/pages/challenge.php b/pages/challenge.php index c34a621..1fa420a 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -1,362 +1,223 @@ +setTimeout(\"showNotification('".$note."');\", 1000); +if (getCookie('pref_mute') != 'true') { + setTimeout(\"soundManager.setVolume('achieve', 40);\", 1340); + setTimeout(\"soundManager.play('achieve');\", 1350); +} + + "; + } +} + ?> + - - - + + -challenge5.start = "Now for a difficult one. The goal for this one is 75 moves.
Press Go! to check your path."; -challenge5.complete = "Look at you, so pro.
Go play the game!"; -challenge5.help = "Try placing the walls as highlighted."; + -function challengeGo(mapid) { - var moves = mapjson[mapid].moves; - var tiles; - - switch (mapid) { - case '1': - if (moves >= 32) { - updateDsp(1, 'instructions', challenge1.complete); - tv.unlock(2); - } else { - updateDsp(1, 'instructions', challenge1.help); - } - break; - - case '2': - if (moves >= 22) { - updateDsp(1, 'instructions', challenge2.complete); - tv.unlock(3); - } else { - updateDsp(1, 'instructions', challenge2.help); - //var tiles = ["2,3,5","2,4,6"]; - //markTiles(tiles); - } - break; - - case '3': - if (moves >=39) { - updateDsp(1, 'instructions', challenge3.complete); - tv.unlock(4); - } else { - updateDsp(1, 'instructions', challenge3.help); - } - break; - - case '4': - if (moves >= 33) { - updateDsp(1, 'instructions', challenge4.complete); - tv.unlock(5); - } else { - updateDsp(1, 'instructions', challenge4.help); - tiles = ["4,1,5","4,2,6","4,3,7","4,4,9"]; - markTiles(tiles); - } - break; - - case '5': - if (moves >= 75) { - updateDsp(1, 'instructions', challenge5.complete); - //Unlock next button. - } else { - updateDsp(1, 'instructions', challenge5.help); - tiles = ["5,1,5","5,2,6","5,3,3","5,4,2","5,3,1"]; - markTiles(tiles); - } - break; - +"; + while($challenge = mysql_fetch_array($challengeResultset)) + { + if($challenge["dateCompleted"] !== NULL) + echo "" . getChallengeDisplayString($challenge) . ""; + else + echo getChallengeDisplayString($challenge); + echo "
"; } + echo ""; } - - -function markTiles(tiles) { - for(var i in tiles) { - var tmp = tiles[i]; - setTimeout('document.getElementById("'+tiles[i]+'").style.backgroundColor = "#ccccdd"', i*150 + 900); +/** + * Returns a user-friendly string describing the challenge. + * Example: "Get at least 245, using at most 10 walls and starting from (6,2) + */ +function getChallengeDisplayString($challenge) +{ + $returnMe = ""; + if($challenge['goal'] == 0) + $returnMe .= "Complete the maze"; + else if ($challenge['inequality'] == "greater than") + $returnMe .= "Get " . $challenge['goal']; + else if ($challenge['inequality'] == "less than") + $returnMe .= "Get LESS THAN " . $challenge['goal']; + else //inequality == "equal" + $returnMe .= "Get EXACTLY " . $challenge['goal']; + + $restrictions = array(); + $addUsingToText = false; //Grammar hack - specifies whether we want to add the word "using" to $returnMe + + //Wall-count restriction + if($challenge['restrictWallCount'] !== NULL) + { + $restrictions[] = "at most " . $challenge['restrictWallCount'] . " wall" . ($challenge['restrictWallCount'] == 1 ? "" : "s"); + $addUsingToText = true; } -} - -//TODO: -function challengeWall(mapid) { - //Disable function - return; - //Required walls: - var reqwall = new Array(); - reqwall[0] = "3,5."; - reqwall[1] = "4,6."; - for(var i in reqwall) { - if (solution[mapid].indexOf(reqwall[i]) == -1) { - //Failed - return; - } + //Wall-placement restriction + if($challenge['restrictWallPlacement'] !== NULL) + { + $invalidWalls = explode(".", $challenge['restrictWallPlacement']); + $invalidWallsString = implode(") or (", $invalidWalls); + $restrictions[] = "no walls at (" . $invalidWallsString . ")"; + $addUsingToText = true; } - updateDsp(1, 'instructions', challenge2.wallstext) -} -function highlightElement(Eid) { -} - - -function startChallenge(mapid) { - //console.log("start challenge", mapid); - switch (mapid) { - case 1: - updateDsp(1, 'instructions', challenge1.start); - var goBtn = document.getElementById('1,btn'); - var interval1 = setInterval(function() { - goBtn.className += ' flash'; - }, 1200), - interval2; - setTimeout(function() { - interval2 = setInterval(function() { - goBtn.className = goBtn.className.replace(' flash', ''); - }, 1200); - }, 600); - var prevHandler = goBtn.onclick; - goBtn.onclick = function() { - clearInterval(interval1); - clearInterval(interval2); - goBtn.className = goBtn.className.replace(' flash', ''); - prevHandler.apply(this, arguments); - } - break; - case 2: - updateDsp(1, 'instructions', challenge2.start); - break; - case 3: - updateDsp(1, 'instructions', challenge3.start); - break; - case 4: - updateDsp(1, 'instructions', challenge4.start); - break; - case 5: - updateDsp(1, 'instructions', challenge5.start); - break; + + //Teleport-count + if($challenge['restrictTeleportCount'] !== NULL) + { + if($challenge['restrictTeleportCount'] == 0) + $restrictions[] = "no teleports"; + else + $restrictions[] = "exactly " . $challenge['restrictTeleportCount'] . " teleports"; + $addUsingToText = true; } -} - -function TutorialView(low, high) { - this.low = low; - this.high = high; - this.cur = low; - //Lock them all. - this.locked = low; - //Override hack to unlock all the levels. - //this.locked = high; + //Teleport points + if($challenge['restrictTeleportsUsed'] !== NULL) + { + $invalidTeleports = explode(".", $challenge['restrictTeleportsUsed']); + $invalidTeleportsString = implode(") or (", $invalidTeleports); + $restrictions[] = "without using the teleport" . (count($invalidTeleports) == 1 ? "" : "s") . " at (" . $invalidTeleportsString . ")"; + } - this.nextbtn = document.getElementById('nextbtn'); - this.prevbtn = document.getElementById('prevbtn'); - this.interval1 = this.interval2 = null; -} -TutorialView.prototype.showTutorial = function(num) { - for (var i = this.low; i <= this.high; i++) { - var elem = document.getElementById("tut-" + i); - if (elem.className.indexOf('hidden') < 0) - elem.className += 'hidden'; + //Start point + if($challenge['restrictStartPoint'] !== NULL) + { + $restrictions[] = "starting from (" . $challenge['restrictStartPoint'] . ")"; } - elem = document.getElementById("tut-" + num); - elem.className = elem.className.replace('hidden', ''); - //Is the map after this disabled? - this.nextbtn.className = this.nextbtn.className.replace(' disabled', ''); - if (this.locked <= this.cur) - this.nextbtn.className += ' disabled'; - startChallenge(num); - tv.nextbtn.className = tv.nextbtn.className.replace(' flash', ''); -} -TutorialView.prototype.next = function() { - clearInterval(this.interval1); - clearInterval(this.interval2); - if (this.nextbtn.className.indexOf(' disabled') > -1) - return; - this.showTutorial(++this.cur); - if (this.cur == this.high) { - if (this.nextbtn.className.indexOf('hidden') < 0) - this.nextbtn.className += ' hidden'; - } else { - this.nextbtn.className = this.nextbtn.className.replace(' hidden', ''); - //this.nextbtn.className += ' disabled'; + + //End point + if($challenge['restrictEndPoint'] !== NULL) + { + $restrictions[] = "ending at (" . $challenge['restrictEndPoint'] . ")"; } - this.prevbtn.className = this.prevbtn.className.replace(' hidden', ''); -} -TutorialView.prototype.prev = function() { - this.showTutorial(--this.cur); - if (this.cur == this.low) { - if (this.prevbtn.className.indexOf('hidden') < 0) - this.prevbtn.className += ' hidden'; - } else - this.prevbtn.className = this.prevbtn.className.replace(' hidden', ''); - this.nextbtn.className = this.nextbtn.className.replace(' hidden', ''); -} -TutorialView.prototype.unlock = function(n) { - if (n > this.locked) { - this.locked = n; - if (this.locked >= this.cur) { - this.nextbtn.className = this.nextbtn.className.replace(' disabled', ''); - this.interval1 = setInterval(function() { - tv.nextbtn.className += ' flash'; - }, 1200); - setTimeout(function() { - tv.interval2 = setInterval(function() { - tv.nextbtn.className = tv.nextbtn.className.replace(' flash', ''); - }, 1200); - }, 600); + + //Here comes the tricky part: we want to join all the $restriction strings with commas, EXCEPT for the last + //two, which should be separated by " and ". + $restrictionCount = count($restrictions); + if($restrictionCount > 0) + { + if($restrictionCount == 1) + { + $restrictionString = $restrictions[0]; } + else + { + $lastRestriction = $restrictions[$restrictionCount - 1]; + unset($restrictions[$restrictionCount - 1]); + $restrictionString = implode(", ", $restrictions) . " and " . $lastRestriction; + } + + $returnMe .= ", " . ($addUsingToText ? "using " : "") . $restrictionString; } - + $returnMe .= "."; + return $returnMe; } - - - -
-
- Welcome to Advanced Training #1. Help for these puzzles will be limited.
Goal: 32 or more. -
-'; -echo DisplayMap($map1, 1, 'puzzle'); -echo '
'; - -?> - -
- - -
- - - - - -- cgit v1.2.3