summaryrefslogtreecommitdiffstats
path: root/pages/challenge.php
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2012-08-27 00:36:38 -0500
committerBlueRaja <BlueRaja.admin@gmail.com>2012-08-27 00:36:38 -0500
commit79d84f2040068424994eecf542fee3686849845c (patch)
treee785a3fc0280a61fade600e4ead8b649aaec14ec /pages/challenge.php
parent9f7611ee27cec55de6c697312389d8fd0bc072ff (diff)
downloadpathery-79d84f2040068424994eecf542fee3686849845c.tar.xz
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.
Diffstat (limited to 'pages/challenge.php')
-rw-r--r--pages/challenge.php513
1 files changed, 187 insertions, 326 deletions
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 @@
<?php
-htmlHeader(array('tutorial'), 'Pathery Challenges', 'Challenges', array('scores'));
+ob_start("ob_gzhandler");
+htmlHeader(
+ array('tutorial'), 'Pathery Challenges',
+ 'Challenges', array('scores', 'dateformat')
+);
+
+include_once ('./includes/maps.php');
+include_once ('./includes/mapoftheday.php');
+include_once ('./includes/db.inc.php');
+include_once ('./includes/datas.php');
+
+//Get custom wall colors;
+$wallColor = '';
+$wallEmblem = '';
+$noteScript = '';
+if ($accepted) {
+ $userID = $_SESSION['userID'];
+
+ $sql = "
+ SELECT
+ userData.wallColor,
+ userData.wallEmblem
+ FROM `userData`
+ WHERE userID = '$userID' ";
+ $result = mysql_query($sql);
+ if ($result)
+ list($wallColor, $wallEmblem) = mysql_fetch_row($result);
+
+ //$note = getNotified($userID);
+ $note = false;
+ if ($note !== false) {
+ //$note = str_replace("'", "\'", $note);
+ //Double your slashes double your fun (Required)
+ $note = addslashes($note);
+ $note = addslashes($note);
+ $noteScript = "
+<script type='text/javascript'>
+setTimeout(\"showNotification('".$note."');\", 1000);
+if (getCookie('pref_mute') != 'true') {
+ setTimeout(\"soundManager.setVolume('achieve', 40);\", 1340);
+ setTimeout(\"soundManager.play('achieve');\", 1350);
+}
+</script>
+ ";
+ }
+}
+
?>
<body>
+<script type="text/javascript">
+playerWallColor = '<?PHP echo isset($wallColor) ? $wallColor : ''; ?>';
+playerWallEmblem = '<?PHP echo isset($wallEmblem) ? $wallEmblem : ''; ?>';
+</script>
<?php
topbar($Links);
?>
-<script src="sounds/script/soundmanager.js"></script>
-
-<script>
-isChallenge = true;
+<div class="wrapper">
+<?
-function challengeLoad() {}
+//Check that the user is allowed to do the challenges
+if (!$accepted) {
+ echo "<center>Please <a href='login'>login</a> to do the challenges!</div>";
+ htmlFooter();
+ return;
+}
+//TODO: Uncomment
+//if (!hasCompletedTutorial($userID)) {
+// echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
+// htmlFooter();
+// return;
+//}
+
+if(!isset($_GET["mapID"]))
+{
+ //TODO: Redirect to challenge listing
+ return;
+}
+$mapCode = loadMapCode($_GET["mapID"]);
+if($mapCode === NULL)
+{
+ //TODO: Redirect to challenge listing also
+ return;
+}
-challenge1 = new Object();
-challenge2 = new Object();
-challenge3 = new Object();
-challenge4 = new Object();
-challenge5 = new Object();
+$mapContent = displayMap(GenerateMapByCode($mapCode), 1);
+$challengeResultset = loadChallengesForMap($_GET["mapID"], $userID);
+if($challengeResultset === NULL)
+{
+ //TODO: Redirect to challenge listing also
+ return;
+}
-challenge1.start = "Welcome to Advanced Training #1. Help for these puzzles will be limited.<br /><i>Goal: 32</i> or more.";
-challenge1.help = "If that was wrong, then try the right.<br /><i>Goal: 32</i> or more.";
-challenge1.complete = "Great, I hope we discovered some things about the pathing.<br/>Press <b>Next</b>";
+displayChallenges($challengeResultset);
-challenge2.start = "Round 2! What does it do when there's 2 outs?<br><i>Goal: 22</i> or more.";
-challenge2.complete = "Yup, you can just block things off when there's more than one. This holds true for checkpoints too.<br/>Press <b>Next</b>";
-challenge2.help = "This might be something you didn't know you could do<br /><i>Goal: 22</i> or more.";
+?>
+ <noscript>Sorry, this game requires scripts to run. Please enable javascript and <a href='home'>Reload this site</a>
+ <br />This game is best viewed in <a href='http://www.google.com/chrome'>Google Chrome</a>
+ </noscript>
+ <? echo $mapContent; ?>
+</div>
-challenge3.start = "Round 3! We're really getting to know that clock-wise path-priority thing aren't we.<br><i>Goal: 39</i> or more.";
-//challenge3.complete = "What did you decide to do with that 4th wall? <br/>Press <b>Next</b>";
-challenge3.complete = "I wonder what you decided to do with that 4th wall... That's it for now. Go play the game! (press home)";
-challenge3.bonus = "Bonus Level unlocked. 'cMeInDtDeLrE'<br/>Press <b>Next</b>";
-challenge3.help = "I believe in this case, less is more.<br><i>Goal: 39</i> or more.";
+<div id="copy" style='width:100%;clear: both'>
+ Copyright &copy; 2011-2012 pathery.com
+</div>
-challenge4.start = "Teleports are traps you can use to your advantage. See if you can use the teleport to reach 33 moves!<br>Press <b>Go!</b>";
-challenge4.complete = "Well done!<br>Teleports add extra intrigue to the game.";
-challenge4.help = "Let's use that teleport to block the way to the <i>A</i>!<br>We can make the path take longer to get to <i>A</i> in the process.";
+<script src="sounds/script/soundmanager.js"></script>
+<script type="text/javascript">soundManagerInit();</script>
+<?PHP echo $noteScript; ?>
-challenge5.start = "Now for a difficult one. The goal for this one is 75 moves.<br>Press <b>Go!</b> to check your path.";
-challenge5.complete = "Look at you, so pro.<br><a href='home'>Go play the game!</a>";
-challenge5.help = "Try placing the walls as highlighted.";
+<?php
+htmlFooter();
+?>
-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;
-
+<?php
+function displayChallenges($challengeResultset)
+{
+ echo "<div>";
+ while($challenge = mysql_fetch_array($challengeResultset))
+ {
+ if($challenge["dateCompleted"] !== NULL)
+ echo "<strike>" . getChallengeDisplayString($challenge) . "</strike>";
+ else
+ echo getChallengeDisplayString($challenge);
+ echo "<br />";
}
+ echo "</div>";
}
-
-
-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;
}
-</script>
-
-<?php
-include('./includes/maps.php');
-//include('./includes/datas.php');
-
-//Page Load;
-//STAGE 1:
-//Intro and Instructions; press go!
-//Lightup; Go-button.
-
-//Go is done animating and GOAL is unachieved.
-//STAGE 2:
-//Show where walls go, and/or encourage them.
-//Lightup; Wall Spots
-
-//All walls have been placed correctly.
-//STAGE 3:
-//'That looks good, try pressing Go!'
-//Lightup; Go-Button
-
-//Go is done animating, and goal is achieved:
-//STAGE 4:
-//Horray! Move on to next - highlight 'Next'
-//Lightup; Next-Button
-
-?>
-<div id="tut-wrapper">
- <div style='height:80px;' id='1,instructions'>
- Welcome to Advanced Training #1. Help for these puzzles will be limited.<br /><i>Goal: 32</i> or more.
- </div>
-<?
-
-//Prepare maps.
-$example1[] = "ootooooooooo";
-$example1[] = "oofooooooooo";
-$example1[] = "oooooooooooo";
-$example1[] = "oooooooooooo";
-$example1[] = "oooooooousoo";
-
-$myparams['teleports'] = 1;
-$myparams['walls'] = 5;
-$map1 = GenerateShapedMap($example1, $myparams);
-
-$challenge2[] = "oooooooou";
-$challenge2[] = "ooooooooo";
-$challenge2[] = "ooooooooo";
-$challenge2[] = "oroooooos";
-$challenge2[] = "ooroooooo";
-$challenge2[] = "ftoooooou";
-$myparams['checkpoints'] = 1;
-$myparams['teleports'] = 1;
-$myparams['walls'] = 2;
-$map2 = GenerateShapedMap($challenge2, $myparams);
-
-$challenge3[] = "otoooooooooan";
-$challenge3[] = "ooooooooooooo";
-$challenge3[] = "ooooooooooooo";
-$challenge3[] = "ooooooooooooo";
-$challenge3[] = "osuofoooooomo";
-
-$myparams['checkpoints'] = 2;
-$myparams['teleports'] = 0;
-$myparams['walls'] = 4;
-$map3 = GenerateShapedMap($challenge3, $myparams);
-
-$challenge4[] = "suooooaooof";
-$challenge4[] = "sooooooooof";
-$challenge4[] = "sooooooooof";
-$challenge4[] = "sooooooorof";
-$challenge4[] = "soooooootof";
-$myparams['checkpoints'] = 1;
-$myparams['teleports'] = 1;
-$myparams['walls'] = 4;
-$map4 = GenerateShapedMap($challenge4, $myparams);
-
-$challenge5[] = "soooaobtorf";
-$challenge5[] = "soocrooooof";
-$challenge5[] = "souooooooof";
-$challenge5[] = "sooooooooof";
-$challenge5[] = "sooooooooof";
-$myparams['checkpoints'] = 3;
-$myparams['teleports'] = 1;
-$myparams['walls'] = 5;
-$map5 = GenerateShapedMap($challenge5, $myparams);
-
-//Display maps.
-echo '<div id="tut-1" class="hidden">';
-echo DisplayMap($map1, 1, 'puzzle');
-echo '</div><div id="tut-2" class="hidden">';
-echo DisplayMap($map2, 2, 'puzzle');
-echo '</div><div id="tut-3" class="hidden">';
-echo DisplayMap($map3, 3, 'puzzle');
-echo '</div><div id="tut-4" class="hidden">';
-echo DisplayMap($map4, 4, 'puzzle');
-echo '</div><div id="tut-5" class="hidden">';
-echo DisplayMap($map5, 5, 'puzzle');
-echo '</div>';
-
-?>
-
- <div class="wrapper">
- <a href="javascript:tv.next()" id="nextbtn" class="next disabled">Next</a>
- <a href="javascript:tv.prev()" id="prevbtn" class="next hidden">Previous</a>
- </div>
-</div>
-
-<script>
-var tv = new TutorialView(1, 3);
-tv.showTutorial(1);
-soundManagerInit();
-</script>
-
-<?php
-htmlFooter(array('tutorial'));
?>