From 9da319e2a2bed9ea3fab92b4e6b799bb9eb16632 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Mon, 1 Oct 2012 01:25:48 -0500 Subject: Fixed a few bugs with challenges, and added some debugging code (which still needs to be removed) --- includes/datas.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'includes/datas.php') diff --git a/includes/datas.php b/includes/datas.php index 676e68b..d1e2618 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -4,6 +4,10 @@ include_once('db.inc.php'); +//FirePHP stuff - TODO: Delete +require_once('includes/FirePHPCore/FirePHP.class.php'); +//FirePHP stuff - TODO: Delete + //Select Stats/Scores. function topScores($mapid, $top = 5, $bottom = 0) { $sql = " @@ -298,8 +302,10 @@ function applyCareerMazesAchievements($userID) { * @param type $moves The total number of moves in the solution, for all paths * @param type $paths An array of path-objects, each as returned by routePath(). */ -function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { +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 == 5) { if ($moves == 75) { onCompletedTutorial($userID); @@ -307,15 +313,31 @@ function checkForCompletedChallenges($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["dateCompleted"] !== NULL) - continue; + 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"]; + } } + + return $challengesCompleted; } /** @@ -346,6 +368,7 @@ function onCompletedTutorial($userID) { * Checks if the given solution meets the requirements for the given challenge */ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { + $firephp = FirePHP::getInstance(true); //Check the maze-length if($challenge['goal'] != 0) { //Er, "greater than" should really be called "greater than or equal to" :\ @@ -353,6 +376,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { || ($challenge['inequality'] == "less than" && $moves >= $challenge['goal']) || ($challenge['inequality'] == "equal" && $moves != $challenge['goal'])) { + $firephp->log("Failed at distance"); return false; } } @@ -364,6 +388,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $temp = count_chars($solution, 1); //$temp needed due to extreme PHP-stupidity $numWalls = $temp[ord(",")]; if($numWalls > $challenge['restrictWallCount']) { + $firephp->log("Failed at wall-count"); return false; } } @@ -374,8 +399,11 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $invalidWalls = explode(".", $challenge['restrictWallPlacement']); foreach($invalidWalls as $invalidWall) { - if(strpos($solution,$invalidWall) !== false) + $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . "."; + if(strpos($solution,$stringToSearchFor) !== false) { + $firephp->log("Failed at wall-placement: " . $invalidWall); + $firephp->log("Solution: " . $solution); return false; } } @@ -385,12 +413,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if($challenge['restrictTeleportCount'] !== NULL || $challenge['restrictTeleportsUsed'] !== NULL) { //Check teleport count - $usedTeleports = explode(".", getUsedTeleports($paths)); + $usedTeleports = explode(".", getUsedTeleports($paths)); //TODO: Implement if($challenge['restrictTeleportCount'] !== NULL) { if(count($usedTeleports) !== $challenge['restrictTeleportCount'] && ($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != "")) { + $firephp->log("Failed at teleport count"); return false; } } @@ -405,6 +434,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { //Check each path to see if it walks over that teleport if(strpos($path['path'], $usedTeleport) !== false) { + $firephp->log("Failed at teleports used"); return false; } } @@ -423,7 +453,10 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { } if(!$usesCorrectStartPoint) + { + $firephp->log("Failed at start-point"); return false; + } } //Check end points @@ -437,13 +470,26 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { } if(!$usesCorrectEndPoint) + { + $firephp->log("Failed at endpoint"); return false; + } } //All of the restrictions were met, meaning the challenge was completed! + $firephp->log("Succeeded!"); return true; } +/** + * Hack, due to positions being stored as x,y in some places and y,x in others + */ +function swapXandYCoordinates($position) +{ + $coords = explode(",", $position); + return $coords[1] . "," . $coords[0]; +} + /** * Sets the given challenge as completed by the user in the database */ @@ -884,6 +930,7 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) FROM challenges LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.mapID = '$mapID' AND challenges.enabled = 1 + ORDER BY challenges.ordering "; $result = mysql_query($sql); -- cgit v1.2.3 From 8fd6ea8061418b8058dc5aba5d71e4cc0f6182f9 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Mon, 1 Oct 2012 01:43:55 -0500 Subject: Fixing tutorial --- includes/datas.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'includes/datas.php') diff --git a/includes/datas.php b/includes/datas.php index d1e2618..952f903 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -306,8 +306,8 @@ 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 == 5) { - if ($moves == 75) { + if($mapID < 10) { + if ($mapID == 5 && $moves == 75) { onCompletedTutorial($userID); } return; -- cgit v1.2.3 From 7a60127a4b17e74860a80a62cdfc53ca37cbff19 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Mon, 1 Oct 2012 14:50:10 -0500 Subject: Added a challenge-listing page, and skeleton code for the listing itself --- includes/datas.php | 10 ++++++++ index.php | 4 ++++ pages/challenge.php | 14 +++++++---- pages/challengelist.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 pages/challengelist.php (limited to 'includes/datas.php') diff --git a/includes/datas.php b/includes/datas.php index 952f903..e8d5871 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -940,6 +940,16 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) return NULL; } +/** + * Loads a listing of all maps and challenges for display, along with which ones the user has completed + * @param type $userIdUnsanitized The userID. Assumed to be unsanitized. + * @return Returns a MySQL resultset with the columns listed in the code, or NULL if nothing found + */ +function loadChallengeListing($userIdUnsanitized) +{ + //TODO: Implement +} + /** * Returns the map "code" for the given mapId */ diff --git a/index.php b/index.php index 2046aa7..c1491e5 100644 --- a/index.php +++ b/index.php @@ -130,6 +130,10 @@ switch ($request) { require 'pages/challenge.php'; break; + case "challengelist": + require 'pages/challengelist.php'; + break; + case "home": //No break here Default: diff --git a/pages/challenge.php b/pages/challenge.php index 9690edd..2ab279d 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -83,14 +83,14 @@ if (!$accepted) { if(!isset($_GET["mapID"])) { - //TODO: Redirect to challenge listing + redirectToChallengeListing(); return; } $mapCode = loadMapCode($_GET["mapID"]); if($mapCode === NULL) { - //TODO: Redirect to challenge listing also + redirectToChallengeListing(); return; } @@ -98,7 +98,7 @@ $mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["mapID"]); $challengeResultset = loadChallengesForMap($_GET["mapID"], $userID); if($challengeResultset === NULL) { - //TODO: Redirect to challenge listing also + redirectToChallengeListing(); return; } @@ -131,7 +131,7 @@ htmlFooter(); function displayChallenges($challengeResultset) { echo '
'; - echo '
Challenges
'; //TODO: remove number + echo '
Challenges
'; echo '
    '; while($challenge = mysql_fetch_array($challengeResultset)) { @@ -234,4 +234,10 @@ function getChallengeDisplayString($challenge) $returnMe .= "."; return $returnMe; } + +function redirectToChallengeListing() +{ + header("Location: /challengelist"); + die(); +} ?> \ No newline at end of file diff --git a/pages/challengelist.php b/pages/challengelist.php new file mode 100644 index 0000000..e7ade3c --- /dev/null +++ b/pages/challengelist.php @@ -0,0 +1,63 @@ + + +
    + +Please login to do the challenges!
    "; + htmlFooter(); + return; +} + +//TODO: Uncomment +//if (!hasCompletedTutorial($userID)) { +// echo "
    Please complete the tutorial to unlock Challenge mode!
"; +// htmlFooter(); +// return; +//} + +?> + + +
+ +
+ Copyright © 2011-2012 pathery.com +
+ + + + \ No newline at end of file -- cgit v1.2.3 From 6b490faf136fedaee9759a1b6164a90dcdb0f408 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Mon, 1 Oct 2012 21:12:59 -0500 Subject: Completed an ugly but functional draft of the challenge-listing page --- css/challenge.css | 24 +++++++++++++++++++++++ images/challenge_complete.png | Bin 0 -> 850 bytes images/challenge_incomplete.png | Bin 0 -> 993 bytes includes/datas.php | 18 ++++++++++++++++- pages/challengelist.php | 42 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 images/challenge_complete.png create mode 100644 images/challenge_incomplete.png (limited to 'includes/datas.php') diff --git a/css/challenge.css b/css/challenge.css index f12cec4..12ba61a 100644 --- a/css/challenge.css +++ b/css/challenge.css @@ -1,3 +1,4 @@ +/** Challenges page **/ #challenge_wrapper #challenges { } #challenge_wrapper #challenges_title { font-size: 1.3em; @@ -9,4 +10,27 @@ } #challenge_wrapper #challenges_listing .challenge_incomplete { font-weight: bold; +} + +/** Challenge listing page **/ +#challengelist_wrapper #challengelist {} +#challengelist_wrapper #challengelist .challengelist_tier { + font-size: 1.3em; + font-weight: bold; + text-decoration: underline; +} +#challengelist_wrapper #challengelist .challengelist_table {} +#challengelist_wrapper #challengelist .challengelist_table .challengelist_link {} +#challengelist_wrapper #challengelist .challengelist_table .challengelist_stars {} +#challengelist_wrapper #challengelist .challengelist_table .challengelist_complete { + width: 32px; + height: 32px; + background-image: url("../images/challenge_complete.png"); + float: right; +} +#challengelist_wrapper #challengelist .challengelist_table .challengelist_incomplete { + width: 32px; + height: 32px; + background-image: url("../images/challenge_incomplete.png"); + float: right; } \ No newline at end of file diff --git a/images/challenge_complete.png b/images/challenge_complete.png new file mode 100644 index 0000000..f0e1b26 Binary files /dev/null and b/images/challenge_complete.png differ diff --git a/images/challenge_incomplete.png b/images/challenge_incomplete.png new file mode 100644 index 0000000..5b9b130 Binary files /dev/null and b/images/challenge_incomplete.png differ diff --git a/includes/datas.php b/includes/datas.php index e8d5871..fa8bfb0 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -947,7 +947,23 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) */ function loadChallengeListing($userIdUnsanitized) { - //TODO: Implement + $userID = mysql_escape_string($userIdUnsanitized); + $sql = " + SELECT maps.ID AS mapID, maps.challengeTier, maps.challengeName, challengeSolutions.dateSolved + FROM maps + INNER JOIN challenges ON maps.ID = challenges.mapID + LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID + WHERE maps.isChallenge = 1 AND challenges.enabled = 1 + AND (challengeSolutions.userID IS NULL OR challengeSolutions.userID = '$userID') + AND maps.challengeTier <= (SELECT challengeTier FROM users WHERE users.ID = '$userID') + ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering + "; + + $result = mysql_query($sql); + echo mysql_error(); + if (mysql_num_rows($result) >= 1) + return $result; + return NULL; } /** diff --git a/pages/challengelist.php b/pages/challengelist.php index e7ade3c..e3f057a 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -23,6 +23,7 @@ if (!$accepted) { htmlFooter(); return; } +$userID = $_SESSION['userID']; //TODO: Uncomment //if (!hasCompletedTutorial($userID)) { @@ -58,6 +59,45 @@ htmlFooter(); */ function displayChallengeList($challengeListResultset) { - //TODO: implement + echo '
'; + $currentTier = -1; + $currentMap = -1; + while($challenge = mysql_fetch_array($challengeListResultset)) + { + //Each challenge gets its own header/table + if($challenge["challengeTier"] != $currentTier) + { + if($currentTier >= 0) + { + echo ''; + } + $currentTier = $challenge["challengeTier"]; + echo "
Tier $currentTier
"; + echo ""; + } + + //Each map gets it own row + if($challenge["mapID"] != $currentMap) + { + if($currentMap >= 0) + { + echo ''; + } + $currentMap = $challenge["mapID"]; + $mapName = $challenge["challengeName"]; + if($mapName == NULL || $mapName == "") + $mapName = "(unknown)"; + echo ""; + echo "
"; + } + + //Each challenge gets its own star + if($challenge["dateSolved"] !== NULL) + $cssClass = "challengelist_complete"; + else + $cssClass = "challengelist_incomplete"; + echo "
"; + } + echo "
"; } ?> \ No newline at end of file -- cgit v1.2.3