From aeacdd6ac410d4b576cf9e804d709cd64fa00384 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Fri, 25 Jan 2013 19:27:51 -0600 Subject: Tiers are now unlocked as the user players through challenges; challenges left to next tier displayed on challengelist page (untested) --- pages/challenge.php | 14 ++++++------- pages/challengelist.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 9 deletions(-) (limited to 'pages') diff --git a/pages/challenge.php b/pages/challenge.php index ceefebe..e5fcd45 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -69,16 +69,16 @@ topbar($Links); //Check that the user is allowed to do the challenges if (!$accepted) { - echo "
Please login to do the challenges!"; + echo "
Please login to do the challenges!
"; + htmlFooter(); + return; +} + +if (!hasCompletedTutorial($userID)) { + echo "
Please complete the tutorial to unlock Challenge mode!"; htmlFooter(); return; } -//TODO: Uncomment -//if (!hasCompletedTutorial($userID)) { -// echo "
Please complete the tutorial to unlock Challenge mode!"; -// htmlFooter(); -// return; -//} if(!isset($_GET["mapID"])) { diff --git a/pages/challengelist.php b/pages/challengelist.php index db20081..b252c38 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); ?> @@ -43,7 +44,7 @@ $userID = $_SESSION['userID']; //Display the actual challenge list $challengeListResultset = loadChallengeListing($userID); //displayChallengeList($challengeListResultset); -echo ChallengeList($challengeListResultset); +echo getChallengeListHtml($challengeListResultset); ?> @@ -55,7 +56,7 @@ htmlFooter(); $challengeMap) { $r .= "Section $tier levels:
"; foreach ($challengeMap as $challengeSuborder => $challenge) { @@ -83,9 +85,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 .= "
"; } $r .= "
"; @@ -93,9 +100,51 @@ function ChallengeList($challengeListResultset) { } $r .= ""; } + + $r .= getNextChallengeTierHtml($numCompletedChallenges); return $r; } +function getNextChallengeTierHtml($numCompletedChallenges) +{ + for(int $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 "
Next tier unlocked in $numChallengesForNextTier" + . "!
"; +} + +function numChallengesRemainingForTier($tier, $numCompletedChallenges) +{ + if($tier >= maxTier()) + return -1; + if($tierChallengeRequirements[$tier] <= $numCompletedChallenges) + return 0; + return ($numCompletedChallenges - $tierChallengeRequirements[$tier]); +} + +function maxTier() +{ + return (count($tierChallengeRequirements) - 1); +} + // TODO: !! Depreciate /** * Outputs the list of all challenges to the page -- cgit v1.2.3