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;
}
if (!hasCompletedTutorial($userID)) {
echo "Please complete the tutorial to unlock Challenge mode!";
htmlFooter();
return;
}
if(!isset($_GET["challengeMapID"]) OR !is_int($_GET["challengeMapID"] + 0))
{
redirectToChallengeListing();
return;
}
$mapCode = loadChallengeMapCode($_GET["challengeMapID"]);
if($mapCode === NULL)
{
redirectToChallengeListing();
return;
}
$challengeMapID = $_GET["challengeMapID"] + 0;
if (!is_int($challengeMapID))
return;
$challengeID = $_GET["challengeMapID"];
//$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["challengeMapID"]);
$mapContent .= "\n";
$mapContent .= "
\n";
$mapContent .= "";
$challengeResultset = loadChallengesForMap($challengeMapID, $userID);
if($challengeResultset === NULL)
{
redirectToChallengeListing();
return;
}
?>
echo $mapContent;
displayChallenges($challengeResultset);
?>
';
echo 'Challenges
';
echo '';
while($challenge = mysql_fetch_array($challengeResultset))
{
$challengeMapID = $_GET["challengeMapID"];
$challengeId = $challenge["challengeID"];
if($challenge["dateSolved"] !== NULL)
$cssClass = "challenge_complete";
else
$cssClass = "challenge_incomplete";
$loadSolutionString = " Load this solution";
echo "- " . getChallengeDisplayString($challenge) . " $loadSolutionString
";
}
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'] . ' or more';
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[] = "only " . $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;
}
function redirectToChallengeListing()
{
header("Location: /challengelist");
die();
}
?>