summaryrefslogtreecommitdiffstats
path: root/pages/challengelist.php
diff options
context:
space:
mode:
Diffstat (limited to 'pages/challengelist.php')
-rw-r--r--pages/challengelist.php66
1 files changed, 64 insertions, 2 deletions
diff --git a/pages/challengelist.php b/pages/challengelist.php
index 364209f..ade47b6 100644
--- a/pages/challengelist.php
+++ b/pages/challengelist.php
@@ -9,6 +9,7 @@ include_once ('./includes/mapoftheday.php');
include_once ('./includes/sqlEmbedded.php');
include_once ('./includes/datas.php');
include_once ('./includes/mapclass.php');
+include_once ('./includes/constants.php');
topbar($Links);
?>
@@ -25,8 +26,15 @@ if (!$accepted) {
htmlFooter();
return;
}
+
$userID = $_SESSION['userID'];
+if (!hasCompletedTutorial($userID)) {
+ echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
+ htmlFooter();
+ return;
+}
+
//TODO: Uncomment
//if (!hasCompletedTutorial($userID)) {
// echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
@@ -43,7 +51,7 @@ $userID = $_SESSION['userID'];
//Display the actual challenge list
$challengeListResultset = loadChallengeListing($userID);
//displayChallengeList($challengeListResultset);
-echo ChallengeList($challengeListResultset);
+echo getChallengeListHtml($challengeListResultset);
?>
@@ -55,7 +63,7 @@ htmlFooter();
<?php
-function ChallengeList($challengeListResultset) {
+function getChallengeListHtml($challengeListResultset) {
//First gather data to a more useful form.
$r = '';
while($data = mysql_fetch_array($challengeListResultset)) {
@@ -65,6 +73,7 @@ function ChallengeList($challengeListResultset) {
$challenges[$tier][$challengeSuborder][$ordering] = $data;
}
+ $numCompletedChallenges = 0;
foreach ($challenges as $tier => $challengeMap) {
$r .= "<b>Section $tier</b> levels:<div class='challengelist_tier' style='border: 1px solid yellow; overflow: auto;'>";
foreach ($challengeMap as $challengeSuborder => $challenge) {
@@ -84,9 +93,14 @@ function ChallengeList($challengeListResultset) {
foreach ($challenge as $ordering => $content) {
//Each challenge gets its own star
if($content["dateSolved"] !== NULL)
+ {
$cssClass = "challengelist_complete";
+ $numCompletedChallenges++;
+ }
else
+ {
$cssClass = "challengelist_incomplete";
+ }
$r .= "<div class='$cssClass'></div>";
}
$r .= "</div>";
@@ -94,9 +108,57 @@ function ChallengeList($challengeListResultset) {
}
$r .= "</div>";
}
+
+ $r .= getNextChallengeTierHtml($numCompletedChallenges);
return $r;
}
+function getNextChallengeTierHtml($numCompletedChallenges)
+{
+ global $tierChallengeRequirements, $userID;
+
+ for($nextTier = 0; $nextTier < count($tierChallengeRequirements); $nextTier++)
+ {
+ $numChallengesForNextTier = numChallengesRemainingForTier($nextTier, $numCompletedChallenges);
+ if($numChallengesForNextTier > 0)
+ break;
+ }
+
+ //We've found the tier they're at - verify this matches up with what's in the DB
+ //This probably belongs somewhere else, but whatever
+ $userCurrentTier = getUserChallengeTier($userID);
+ if($userCurrentTier != $nextTier - 1)
+ {
+ //TODO: Display some sort of "tier XY unlocked" or something
+ setUserChallengeTier($userID, $nextTier -1);
+ }
+
+ //Return the tiers-left html
+ if($numChallengesForNextTier == 0)
+ return "<div class='challengelist_nexttier>All tiers have been unlocked!</div>";
+
+ return "<div class='challengelist_nexttier'>Next tier unlocked in <span class='challengelist_nexttier_requirement'>$numChallengesForNextTier</span>"
+ . "<span class='challengelist_complete'></span></div>";
+}
+
+function numChallengesRemainingForTier($tier, $numCompletedChallenges)
+{
+ global $tierChallengeRequirements;
+
+ if($tier >= maxTier())
+ return -1;
+ if($tierChallengeRequirements[$tier] <= $numCompletedChallenges)
+ return 0;
+ return ($tierChallengeRequirements[$tier] - $numCompletedChallenges);
+}
+
+function maxTier()
+{
+ global $tierChallengeRequirements;
+
+ return (count($tierChallengeRequirements) - 1);
+}
+
// TODO: !! Depreciate
/**
* Outputs the list of all challenges to the page