setTimeout(\"showNotification('".$note."');\", 1000);
if (getCookie('pref_mute') != 'true') {
setTimeout(\"soundManager.setVolume('achieve', 40);\", 1340);
setTimeout(\"soundManager.play('achieve');\", 1350);
}
";
}
}
?>
//Check that the user is allowed to do the challenges
if (!$accepted) {
echo "
Please login to do the challenges! ";
htmlFooter();
return;
}
//TODO: Uncomment
//if (!hasCompletedTutorial($userID)) {
// echo "Please complete the tutorial to unlock Challenge mode!";
// 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;
}
$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["mapID"]);
$challengeResultset = loadChallengesForMap($_GET["mapID"], $userID);
if($challengeResultset === NULL)
{
//TODO: Redirect to challenge listing also
return;
}
?>
echo $mapContent;
displayChallenges($challengeResultset);
?>
Copyright © 2011-2012 pathery.com
';
echo 'Challenges
'; //TODO: remove number
echo '';
while($challenge = mysql_fetch_array($challengeResultset))
{
$challengeId = $challenge["challengeID"];
echo "- ";
if($challenge["dateSolved"] !== NULL)
$cssClass = "challenge_complete";
else
$cssClass = "challenge_incomplete";
echo "" . getChallengeDisplayString($challenge) . "";
echo "
";
}
echo "
";
}
/**
* 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;
}
//Wall-placement restriction
if($challenge['restrictWallPlacement'] !== NULL)
{
$invalidWalls = explode(".", $challenge['restrictWallPlacement']);
$invalidWallsString = implode(") or (", $invalidWalls);
$restrictions[] = "no walls at (" . $invalidWallsString . ")";
$addUsingToText = true;
}
//Teleport-count
if($challenge['restrictTeleportCount'] !== NULL)
{
if($challenge['restrictTeleportCount'] == 0)
$restrictions[] = "no teleports";
else
$restrictions[] = "exactly " . $challenge['restrictTeleportCount'] . " teleports";
$addUsingToText = true;
}
//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 . ")";
}
//Start point
if($challenge['restrictStartPoint'] !== NULL)
{
$restrictions[] = "starting from (" . $challenge['restrictStartPoint'] . ")";
}
//End point
if($challenge['restrictEndPoint'] !== NULL)
{
$restrictions[] = "ending at (" . $challenge['restrictEndPoint'] . ")";
}
//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;
}
?>