summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2013-01-25 19:27:51 -0600
committerBlueRaja <BlueRaja.admin@gmail.com>2013-01-25 19:27:51 -0600
commitaeacdd6ac410d4b576cf9e804d709cd64fa00384 (patch)
tree44fd65a626b44eb5e099e2cf2525ef11cef20def
parentfed89ebc174dda0963856f992f6f9a26bbe1b182 (diff)
downloadpathery-aeacdd6ac410d4b576cf9e804d709cd64fa00384.tar.xz
Tiers are now unlocked as the user players through challenges; challenges left to next tier displayed on challengelist page
(untested)
-rw-r--r--css/challenge.css24
-rw-r--r--includes/constants.php6
-rw-r--r--includes/datas.php43
-rw-r--r--pages/challenge.php14
-rw-r--r--pages/challengelist.php53
5 files changed, 102 insertions, 38 deletions
diff --git a/css/challenge.css b/css/challenge.css
index 16c7357..ff0589a 100644
--- a/css/challenge.css
+++ b/css/challenge.css
@@ -40,21 +40,6 @@
display: none;
}
-.challengelist_map {
- float:left;
- padding: 15px;
- background-color:#333;
- margin: 20px;
- border-radius:10px;
- cursor:pointer;
-}
-.challengelist_map:hover {
- background-color:#444;
-}
-.challengelist_tier {
- border-width: 0px 0px 1px 1px;
-}
-
/** Challenge listing page **/
#challengelist_wrapper #challengelist {}
#challengelist_wrapper #challengelist .challengelist_tier {
@@ -87,4 +72,13 @@
}
.challengelist_map:hover {
background-color:#444;
+}
+.challengelist_tier {
+ border-width: 0px 0px 1px 1px;
+}
+.challengelist_nexttier {
+
+}
+.challengelist_nexttier_requirement {
+
} \ No newline at end of file
diff --git a/includes/constants.php b/includes/constants.php
index 0658725..7774aa4 100644
--- a/includes/constants.php
+++ b/includes/constants.php
@@ -68,4 +68,10 @@ class MapType
const Special = 4;
const Weekly = 5;
}
+
+/**
+ * Required number of challenges beaten to move up to each tier.
+ * Make sure the first one is always 0...
+ */
+$tierChallengeRequirements = array(0, 5, 10, 15, 20, 25, 30);
?>
diff --git a/includes/datas.php b/includes/datas.php
index 62f664e..11a130c 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -3,6 +3,7 @@
//
include_once('sqlEmbedded.php');
+include_once('constants.php');
//FirePHP stuff - TODO: Delete
//require_once('includes/FirePHPCore/FirePHP.class.php');
@@ -114,7 +115,7 @@ function getNotified($userID) {
$aTypeCurrency[1] = "total moves mazed";
$aTypeCurrency[2] = "mazes played";
$aTypeCurrency[3] = "mazes with (tied) top score";
- $aTypeCurrency[4] = "challenge points";
+ $aTypeCurrency[4] = "champion points";
$aName = $aTypeNames[$aType];
$currency = $aTypeCurrency[$aType];
@@ -303,8 +304,6 @@ function applyCareerMazesAchievements($userID) {
*/
function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
//mapID 5 is the tutorial, and is treated specially
- //$firephp = FirePHP::getInstance(true);
- //$firephp->log("In challenges");
if($mapID <= 10) {
if ($mapID == 5 && $moves == 75) {
onCompletedTutorial($userID);
@@ -312,25 +311,17 @@ function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
return;
}
- //$firephp->log($mapID, "mapID");
- //$firephp->log($userID, "userID");
-
$challengeResultset = loadChallengesForMap($mapID, $userID);
$challengesCompleted = array();
while($challenge = mysql_fetch_array($challengeResultset))
{
- //$firephp->log("Checking a challenge");
- //$firephp->log("Checking challenge number" . $challenge['challengeID']);
- //$firephp->log($challenge["dateSolved"], "dateCompleted");
//Skip checking challenges which have already been completed
if($challenge["dateSolved"] !== NULL)
{
- //$firephp->log('Challenge was already completed');
$challengesCompleted[] = $challenge["challengeID"];
}
else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths))
{
- //$firephp->log('Challenge was completed!');
setChallengeCompleted($challenge, $solution, $userID, $moves);
$challengesCompleted[] = $challenge["challengeID"];
}
@@ -517,9 +508,7 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) {
mysql_query($sql);
}
-
function isChallengeMap($mapID) {
- include_once('./includes/sqlEmbedded.php');
$sql = "SELECT ID
FROM `maps`
WHERE
@@ -529,6 +518,31 @@ function isChallengeMap($mapID) {
return (mysql_num_rows($result) != 0);
}
+function getUserChallengeTier($userID)
+{
+ $userID = mysql_escape_string($userID);
+
+ $sql = "SELECT challengeTier
+ FROM users
+ WHERE users.ID = '$userID'";
+
+ $result = mysql_query($sql);
+ $row = mysql_fetch_row($result);
+ return $row[0];
+}
+
+function setUserChallengeTier($userID, $challengeTier)
+{
+ $userID = mysql_escape_string($userID);
+ $challengeTier = mysql_escape_string($challengeTier);
+
+ $sql = "UPDATE users
+ SET challengeTier = '$challengeTier'
+ WHERE users.ID = '$userID'";
+
+ mysql_query($sql);
+}
+
function applyAchievements($userID, $aType) {
$amount = getAchievementCurrency($userID, $aType);
@@ -1079,9 +1093,10 @@ function loadChallengeListing($userIdUnsanitized)
challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID,
maps.challengeSuborder, challenges.ordering
FROM challenges
- LEFT JOIN maps ON challenges.mapID = maps.ID
+ INNER JOIN maps ON challenges.mapID = maps.ID
LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID'
WHERE challenges.enabled = 1
+ AND maps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID')
ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering";
$result = mysql_query($sql);
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 "<center>Please <a href='login'>login</a> to do the challenges!</div>";
+ echo "<center>Please <a href='login'>login</a> to do the challenges!</center></div>";
+ htmlFooter();
+ return;
+}
+
+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>";
-// 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();
<?php
-function ChallengeList($challengeListResultset) {
+function getChallengeListHtml($challengeListResultset) {
//First gather data to a more useful form.
$r = '';
while($data = mysql_fetch_array($challengeListResultset)) {
@@ -65,6 +66,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) {
@@ -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 .= "<div class='$cssClass'></div>";
}
$r .= "</div>";
@@ -93,9 +100,51 @@ function ChallengeList($challengeListResultset) {
}
$r .= "</div>";
}
+
+ $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 "<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)
+{
+ 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