From 6b8c58ac2d4de502421acef48f4434bee605633f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 8 Jan 2013 01:53:05 -0800 Subject: Challenges Implementation. LOTS of stuff Fixed an issue with loading best solution from logged out to logged in state. Commented out a lot of firephp stuff; feel free to uncomment. --- css/challenge.css | 15 ++- css/stats.css | 19 +++- do.php | 85 ++++++++++++----- includes/datas.php | 244 +++++++++++++++++++++++++++++++++++++++++------ includes/mapoftheday.php | 2 +- includes/maps.php | 13 +++ index.php | 12 +++ js/mapspecs.js | 46 ++++++--- js/scores.js | 224 +++++++++++++++++++++++++++++++++++++++++-- pages/challenge.php | 17 ++-- pages/challengelist.php | 7 +- pages/faq.php | 4 +- pages/gallery.php | 178 +++++++++++++++++++++++++++++++--- pages/home.php | 21 ++-- pages/tutorial.php | 1 + 15 files changed, 769 insertions(+), 119 deletions(-) diff --git a/css/challenge.css b/css/challenge.css index 12ba61a..399570b 100644 --- a/css/challenge.css +++ b/css/challenge.css @@ -5,11 +5,20 @@ font-weight: bold; } #challenge_wrapper #challenges_listing { } -#challenge_wrapper #challenges_listing .challenge_complete { - text-decoration: line-through; +.challenge_complete { + color:green; + font-weight: normal; } -#challenge_wrapper #challenges_listing .challenge_incomplete { +.challenge_incomplete { font-weight: bold; + color:red; +} + +.challenge_complete a { + display:inline; +} +.challenge_incomplete a { + display: none; } /** Challenge listing page **/ diff --git a/css/stats.css b/css/stats.css index 8d3b361..ab4cb96 100644 --- a/css/stats.css +++ b/css/stats.css @@ -87,10 +87,15 @@ td, th { margin-right:auto; position:relative; } + + .scoreMedal { - text-align:right; - vertical-align:bottom; - background-repeat:no-repeat; + text-align:left; +} +.scoreMedal img { + width:32px; + height:32px; + vertical-align:middle; } .scoreGold { background-image: url(../images/MedalGoldCAb.png); @@ -98,4 +103,12 @@ td, th { .scoreSilver { background-image: url(../images/MedalSilverCAb.png); } +.scoreName { + float:left; + padding: 5px 0px 3px 3px; + width:120px; + overflow:hidden; + text-overflow: ellipsis; + white-space:nowrap; +} diff --git a/do.php b/do.php index c82de22..bbaa665 100644 --- a/do.php +++ b/do.php @@ -56,6 +56,18 @@ if (isset($_GET['checkachieve']) && $_GET['checkachieve'] == 'true' && $_SESSION $json['notificationtext'] = $note; } +if ($_GET['r'] == 'reqMemberPage') { + + $order = 'ORDER BY dateJoined DESC'; + $page = $_GET['reqPage'] + 0; + if (!is_int($page)) + return; + $json = getMembers($order, $page, 4); + $json['page'] = $page; + $encoded = json_encode($json); + die($encoded); +} + if ($_GET['r'] == 'reqScorePage') { $mapID = $_GET['mapid'] + 0; $page = $_GET['reqPage'] + 0; @@ -107,14 +119,14 @@ if ($_GET['r'] == 'getsol') { $userID = $_SESSION['userID']; -///// TODO: FIX FIX FIX FIX FIX FIX ////// - if ($_SESSION['accepted'] == 1) { - $json = getSolution($userID, $mapID); - if ($tmp['moves'] > $_SESSION[$mapID.'sol']) { - $json = $tmp; - } + $json['solution'] = ''; + $json['moves'] = 0; + if ($accepted) { + $sol = getSolution($userID, $mapID); + $json['solution'] = $sol['solution']; + $json['moves'] = $sol['moves']; } - if (isset($_SESSION[$mapID.'sol'])) { + if (isset($_SESSION[$mapID.'sol']) && $_SESSION[$mapID.'moves'] > $json['moves']) { $json['solution'] = $_SESSION[$mapID.'sol']; $json['moves'] = $_SESSION[$mapID.'moves']; } @@ -125,6 +137,22 @@ if ($_GET['r'] == 'getsol') { die($encoded); } +if ($_GET['r'] == 'getChallengeSolution') { + $mapID = $_GET['mapID'] + 0; + $challengeID = $_GET['challengeID'] + 0; + //echo "working..."; + if (!is_int($mapID) OR !is_int($challengeID)) return; + if (!$accepted) return; + + $userID = $_SESSION['userID']; + + $json = getChallengeSolution($userID, $challengeID); + + $json['mapid'] = $mapID; + $encoded = json_encode($json); + die($encoded); +} + // ------------ MAIN; getpath. if ($_GET['r'] == 'getpath') { @@ -137,7 +165,8 @@ if ($_GET['r'] == 'getpath') { // Enables the ability to discover an exact duplicate solution. $solution = formSolution($_GET['solution']); - + $userID = $_SESSION['userID']; + //valid mapID? $mapID = $_GET[mapid] + 0; if (!is_int($mapID)) return; @@ -176,9 +205,15 @@ if ($_GET['r'] == 'getpath') { $encoded = json_encode($json); die($encoded); } + + if ($_GET['isChallenge'] == 'true' AND isChallengeMap($mapID)) { + // $firephp->log('Calling challenges'); + $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']); + // $firephp->log('Challenges called!'); + die(json_encode($json)); + } //Get current score data. - to see if a pertinent score was beat. - $userID = $_SESSION['userID']; $sql = "SELECT `moves` as bestmoves, `displayName`, IFNULL(q1.mymoves, 0) FROM `solutions`, `users` LEFT JOIN ( @@ -203,8 +238,10 @@ if ($_GET['r'] == 'getpath') { $json['best'] = 0; $json['bestby'] = 'no one'; } - - // --------- RUSH THE PATH BACK TO THE USER + + // --------- ------------------------------ --------- + // --------- RUSH THE PATH BACK TO THE USER --------- + // --------- ------------------------------ --------- if (!$debug) { ignore_user_abort(true); $encoded = json_encode($json); @@ -212,22 +249,21 @@ if ($_GET['r'] == 'getpath') { header("Content-Length: " . mb_strlen($encoded)); echo $encoded; flush(); + //The connection is now closed, no further communication to the client can be done! } + // --------- CONTINUE EXECUTION --------- - $json['error'][] = "bestMoves, byName, myMoves: $bestMoves, $byName, $myMoves;"; - - // --------- CONTINUE EXECUTION + // Now we don't have to worry about how long we're taking. + // All of this code will execute without the user waiting on the server. + + //$json['error'][] = "bestMoves, byName, myMoves: $bestMoves, $byName, $myMoves;"; //TODO: Commented this out - temporarly. // $firephp->log('Got this far'); // $firephp->log($_SESSION['accepted'], '$_SESSION["accepted"]'); ////Challenge/Tutorial? - // if ($_GET['isChallenge'] == 'true') { - // $firephp->log('Calling challenges'); - // $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']); - // $firephp->log('Challenges called!'); - // } + ////--------- RUSH THE PATH BACK TO THE USER // ignore_user_abort(true); @@ -255,10 +291,9 @@ if ($_GET['r'] == 'getpath') { $_SESSION['preCompletedTutorialNotified'] = false; } if ($accepted == false) - return; - + die(json_encode($json)); getCompletedChallenges($userID, $mapID, $solution, $moves, $paths); - return; + die(json_encode($json)); } @@ -332,12 +367,12 @@ if ($_GET['r'] == 'getpath') { $json['error'][] = 'Rush-send failed'; -$encoded = json_encode($json); -die($encoded); +//$encoded = json_encode($json); +die(json_encode($json)); function isCurrentMap($mapID) { - // TODO: Broke + // TODO: change methodology include_once('./includes/db.inc.php'); $sql = "SELECT maps.ID FROM `mapOfTheDay` diff --git a/includes/datas.php b/includes/datas.php index fa04300..6cc8f07 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -313,25 +313,25 @@ function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { return; } - $firephp->log($mapID, "mapID"); - $firephp->log($userID, "userID"); + //$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"); + //$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'); + //$firephp->log('Challenge was already completed'); $challengesCompleted[] = $challenge["challengeID"]; } else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths)) { - $firephp->log('Challenge was completed!'); + //$firephp->log('Challenge was completed!'); setChallengeCompleted($challenge, $solution, $userID, $moves); $challengesCompleted[] = $challenge["challengeID"]; } @@ -368,7 +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); + //$firephp = FirePHP::getInstance(true); //Check the maze-length if($challenge['goal'] != 0) { //Er, "greater than" should really be called "greater than or equal to" :\ @@ -376,7 +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"); + //$firephp->log("Failed at distance"); return false; } } @@ -388,7 +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"); + //$firephp->log("Failed at wall-count"); return false; } } @@ -402,8 +402,8 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . "."; if(strpos($solution,$stringToSearchFor) !== false) { - $firephp->log("Failed at wall-placement: " . $invalidWall); - $firephp->log("Solution: " . $solution); + //$firephp->log("Failed at wall-placement: " . $invalidWall); + //$firephp->log("Solution: " . $solution); return false; } } @@ -419,7 +419,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(count($usedTeleports) !== $challenge['restrictTeleportCount'] && ($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != "")) { - $firephp->log("Failed at teleport count"); + //$firephp->log("Failed at teleport count"); return false; } } @@ -434,7 +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"); + //$firephp->log("Failed at teleports used"); return false; } } @@ -454,7 +454,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectStartPoint) { - $firephp->log("Failed at start-point"); + //$firephp->log("Failed at start-point"); return false; } } @@ -471,13 +471,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectEndPoint) { - $firephp->log("Failed at endpoint"); + //$firephp->log("Failed at endpoint"); return false; } } //All of the restrictions were met, meaning the challenge was completed! - $firephp->log("Succeeded!"); + //$firephp->log("Succeeded!"); return true; } @@ -504,6 +504,21 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) { mysql_query($sql); } + +function isChallengeMap($mapID) { + include_once('./includes/db.inc.php'); + $sql = "SELECT ID + FROM `maps` + WHERE + ID = '$mapID' AND `isChallenge` = true; + "; + $result = mysql_query($sql) or die(mysql_error()); + if (mysql_num_rows($result) == 0) + return false; + else + return true; +} + function applyAchievements($userID, $aType) { $amount = getAchievementCurrency($userID, $aType); @@ -768,11 +783,163 @@ function trackMOTDstats($mapType) { +//Select Members +function getMembers($order, $pageNumber = 1, $pageDivide = 50) { + + $top = $pageNumber * $pageDivide; + $bottom = $top - $pageDivide; + + $limitTop = ($pageNumber - 1) * $pageDivide; + + $sql = "SELECT COUNT(*) as 'count' FROM `users`"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $total = $row['count']; + + $output['pageCount'] = $total / $pageDivide; + + $pageRequest = 'all'; + if ($pageRequest == 'all') { + $pageReqStart = 1; + $pageReqEnd = 1000; + } elseif (is_int($pageRequest)) { + $pageReqStart = $pageRequest; + $pageReqEnd = $pageRequest; + } else { + $tmp = explode($pageRequest, "-"); + $pageReqStart = $tmp[0]; + $pageReqEnd = $tmp[1]; + } + + $sql = " + SELECT + users.ID as ID, + users.displayName as display, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMoves, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE) + , 0) AS totalMovesThisWeek, + IfNull( + (SELECT COUNT(*) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMazes, + SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins, + SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies, + IfNull(userData.wallColor, '#666666') as wallColor, + IfNull(userData.displayColor, '#cccccc'), + userData.wallEmblem as wallEmblem, + users.datejoined as dateJoined, + users.dateLogin as dateLogin + FROM `users` + LEFT JOIN `userData` ON users.ID = userData.userID + LEFT JOIN `statistics` ON users.ID = statistics.userID + GROUP BY users.ID + $order + LIMIT $limitTop, $pageDivide + "; + + $result = mysql_query($sql); + //$utime = date("g:i A (T)"); + + $output['updateTime'] = date("g:i A (T)"); + + $i = $limitTop; + $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { + $i++; + + $moves = $row['moves']; + + $userID = $row['ID']; + if ($_SESSION['userID'] == $userID) { + $userPosition = $i; + } + // } else { + // if ($i > $top) + // continue; + // if ($i <= $bottom) + // continue; + // } + + if ($wallEmblem == '') + $wallEmblem = 'blank.png'; + + $cdate = $row['cdate']; + $cdate = date("g:i A (T)", strtotime($cdate)); + + $row['dateJoined'] = Date("Y-m-d", strtotime($row['dateJoined'])); + $row['dateLogin'] = Date("Y-m-d", strtotime($row['dateLogin'])); + + $scoredDate = strtotime($row['cdate']); + $secondsSinceScored = strtotime("now") - $scoredDate ; + + //Alternate background colors + $background = '#262631'; + if ($i % 2 == 1) + $background = '#20202a'; + + if ($userPosition == $i) { + $background = '#343c57'; + $foundUser = true; + } + + // if is blind map. + // $row['moves'] = '???'; + + $output['users'][$i] = $row; + $output['users'][$i]['scoredDate'] = $cdate; + $output['users'][$i]['secondsSinceScored'] = $secondsSinceScored; + $output['users'][$i]['background'] = $background; + $output['users'][$i]['medal'] = $medal; + $output['users'][$i]['isUser'] = $userPosition == $i; + //$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; + } // END WHILE + + //Need to look this up. + //$output['pageCount'] = ceil(($i / $pageDivide)); + //$output['pageCount'] = 5; + if ($prevPage > 0) { + $navi .= " << "; + $navi .= " < "; + } else { + $navi .= " << "; + $navi .= " <"; + } + for ($x = 1; $x <= $pageCount; $x++) { + if ($x < $pageNumber - 3 OR $x > $pageNumber + 3) + continue; + if ($x == $pageNumber) + $navi .= " $x "; + elseif ($userPage == $x) + $navi .= " $x "; + else + $navi .= " $x "; + } + if ($nextPage <= $pageCount) { + $navi .= " > "; + $navi .= " >> "; + } + + return $output; +} + + + //Select Stats/Scores. -function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { +function getScores($mapID, $pageNumber = 1, $pageDivide = 10) { $top = $pageNumber * $pageDivide; $bottom = $top - $pageDivide; + //TODO: !! set to false before uploading. + $isBlindMap = false; + $pageRequest = 'all'; if ($pageRequest == 'all') { @@ -787,6 +954,17 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $pageReqEnd = $tmp[1]; } + $userID = $_SESSION['userID']; + $myBestMoves = 0; + if ($isBlindMap) { + $sql = "SELECT `moves` FROM `solutions` WHERE `mapID` = '$mapID' AND `userID` = '$userID'"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $myBestMoves = $row['moves']; + // echo "XX $myBestMoves XX "; + // echo "XX $userID XX "; + } + $sql = " SELECT timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff, @@ -803,9 +981,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { ON users.ID = solutions.userID LEFT JOIN `userData` ON users.ID = userData.userID - WHERE solutions.mapID = '$mapid' + WHERE solutions.mapID = '$mapID' ORDER BY solutions.moves DESC, solutions.dateModified ASC, solutions.ID DESC "; + // ORDER BY solutions.moves ASC, solutions.dateModified DESC, solutions.ID ASC $result = mysql_query($sql); //$utime = date("g:i A (T)"); @@ -813,19 +992,22 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $i = 0; $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { $i++; $moves = $row['moves']; - $userID = $row['ID']; + + $requestedUserID = $row['ID']; if ($i == 1) { $bestMoves = $moves; $output['bestMoves'] = $bestMoves; $output['bestBy'] = $row['display']; } - if ($_SESSION['userID'] == $userID) { + if ($_SESSION['userID'] == $requestedUserID) { $userPosition = $i; + //$myBestMoves = $moves; } else { if ($i > $top) continue; @@ -857,6 +1039,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $medal = 'silver'; if ($i == 1) $medal = 'gold'; + + // if is blind map. + if ($isBlindMap AND $myBestMoves < $moves) + $row['moves'] = '???'; $output['users'][$i] = $row; $output['users'][$i]['scoredDate'] = $cdate; @@ -864,7 +1050,7 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['users'][$i]['background'] = $background; $output['users'][$i]['medal'] = $medal; $output['users'][$i]['isUser'] = $userPosition == $i; - $output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; + //$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; } // END WHILE if ($foundUser) { @@ -876,8 +1062,8 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['pageCount'] = ceil(($i / $pageDivide)); if ($prevPage > 0) { - $navi .= " << "; - $navi .= " < "; + $navi .= " << "; + $navi .= " < "; } else { $navi .= " << "; $navi .= " <"; @@ -888,13 +1074,13 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { if ($x == $pageNumber) $navi .= " $x "; elseif ($userPage == $x) - $navi .= " $x "; + $navi .= " $x "; else - $navi .= " $x "; + $navi .= " $x "; } if ($nextPage <= $pageCount) { - $navi .= " > "; - $navi .= " >> "; + $navi .= " > "; + $navi .= " >> "; } return $output; @@ -949,7 +1135,7 @@ function loadChallengeListing($userIdUnsanitized) { $userID = mysql_escape_string($userIdUnsanitized); $sql = " - SELECT maps.ID AS mapID, maps.challengeTier, maps.challengeName, challengeSolutions.dateSolved + SELECT maps.ID AS mapID, maps.challengeTier, maps.name, challengeSolutions.dateSolved FROM maps INNER JOIN challenges ON maps.ID = challenges.mapID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 5ae7ebd..d244635 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/includes/maps.php b/includes/maps.php index 431f006..1df258d 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -726,6 +726,19 @@ function getSolution($userID, $mapID) { } } +function getChallengeSolution($userID, $challengeID) { + include_once('db.inc.php'); + $sql = "SELECT `solution`, `moves` + FROM `challengeSolutions` + WHERE `userID` = '$userID' AND + `challengeID` = '$challengeID' + "; + $result = mysql_query($sql); + if (mysql_num_rows($result) > 0) { + return mysql_fetch_assoc($result); + } +} + function getMapCode($mapID) { include_once('db.inc.php'); $sql = "SELECT `code` diff --git a/index.php b/index.php index 60cd81a..9175b30 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,16 @@ BETA!"; //$Links['howtoplay'] = "How to Play"; //$Links['tutorial'] = "Tutorial"; diff --git a/js/mapspecs.js b/js/mapspecs.js index e1def28..ee9759d 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -20,6 +20,7 @@ else if (document.attachEvent) { // IE 8- } var isChallenge = false; +var isTutorial = false; var solution = new Array(); var blocks = new Array(); @@ -190,6 +191,12 @@ function requestSol(mapID) { ajax.runAJAX(); } +function requestChallengeSolution(mapID, challengeID) { + ajax.requestFile = "do.php?r=getChallengeSolution&mapID="+mapID+'&challengeID='+challengeID; //prepare strdata + ajax.onCompletion = requestSolDone; // specify function to be executed on response + ajax.runAJAX(); +} + function requestSolDone() { var JO; JO = decryptJSON(ajax.response); @@ -261,7 +268,10 @@ function request_path_done() { return; } + var disptext = "Record: "+JO.best+" by "+JO.bestby; + if (isChallenge) + disptext = ''; updateDsp(JO.mapid, 'dspID', disptext); mapdata[mapid].moveCount = new Object; @@ -277,18 +287,6 @@ function request_path_done() { mapdata[mapid].pathColor[i] = '#ffffff'; animatePath(JO.path[i].path, mapid, JO.path[i].start, i); } - - //Mark off challenges - //TODO: Temporarly disabled because it breaks the tutorial; - if(isChallenge && 2 == 4) - { - for(var i = 0; i < JO.completedChallenges.length; i++) - { - var challengeId = JO.completedChallenges[i]; - document.getElementById("challenge_id_" + challengeId).className = "challenge_complete"; - } - } - } function decryptJSON(text) { @@ -323,6 +321,22 @@ function animatePathDone(mapid) { if (isChallenge == true) { challengeGo(mapid); } + //Mark off challenges + //TODO: This hack is stupidd :( + if(isChallenge && isTutorial == false) + { + for(var i = 0; i < mapjson[mapid].completedChallenges.length; i++) + { + var challengeId = mapjson[mapid].completedChallenges[i]; + var handle = document.getElementById("challenge_id_" + challengeId); + + if (handle.className.indexOf('challenge_complete') < 0) { + + handle.className = "challenge_complete"; + flashelement("challenge_id_" + challengeId, 4); + } + } + } } function checkSound(mapid) { @@ -597,6 +611,7 @@ function doanimate(x, y, p, c, mapid, pathNumber) { switch (selected) { case '1': rs =120; + rs =0; break; case '2': @@ -670,8 +685,13 @@ function doanimate(x, y, p, c, mapid, pathNumber) { // if (mapdata[mapid].moveCount[1] < mapdata[mapid].moveCount[pathNumber] - 2 // || mapdata[mapid].moveCount[0] < mapdata[mapid].moveCount[pathNumber] - 2) // rs = rs + 100; + + if (count[mapid] % 2 == 1 && rs == 0) + doanimate(x,y,p,t,mapid,pathNumber); + else + setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",rs); + //setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",1); - setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",rs); } diff --git a/js/scores.js b/js/scores.js index 0c1383f..734683a 100644 --- a/js/scores.js +++ b/js/scores.js @@ -28,10 +28,12 @@ function scoresRequestPage(mapid, page) { ajax.runAJAX();// Do it! return true; } + function scoresRequestLoading() { //Signify that it's working in some manner? //console.log("I'm loading teh page..."); } + function scoresRequestPageDone() { //console.log("Request Page Done", ajax.response); var JO = decryptJSON(ajax.response); @@ -46,6 +48,7 @@ function scoresRequestPageDone() { } } } + function scoresUpdatePage(mapid, page, html) { // console.log("Updating Page", mapid, page); scoresPreparePage(mapid, page); @@ -55,6 +58,7 @@ function scoresUpdatePage(mapid, page, html) { scoresShowPage(mapid, page); } } + function scoresShowMyPage(mapid) { //Future use } @@ -101,6 +105,7 @@ function scoresPreparePage (mapid, page) { } return true; } + function scoresFormatPage(JO) { // console.log("Formating page"); @@ -132,14 +137,14 @@ function scoresFormatPage(JO) { styleClass = 'border-top: 6px solid #777799;'; p = p+ ""; - p = p+ ""; + p = p+ ""; if (u.medal == 'gold') { - p = p+ ""; + p = p+ ""; } else if (u.medal == 'silver') { - p = p+ ""; + p = p+ ""; } else { - p = p+ ""; + p = p+ ""; } p = p+ i+ ""; p = p+ ""; @@ -148,7 +153,7 @@ function scoresFormatPage(JO) { p = p+ " "; p = p+ " "; p = p+ ""; - p = p+ ""+u.display+""; + p = p+ ""+u.display+""; p = p+ ""; p = p+ ""+u.moves+""; p = p+ ""; @@ -181,6 +186,7 @@ function scoresFormatPage(JO) { //p = JO.navi+p; return p; } + function scoresFormatPageNavi(JO) { var r = ''; var showedPrevPage = true; @@ -208,4 +214,210 @@ function scoresFormatPageNavi(JO) { } return r; -} \ No newline at end of file +} + + +//Memberlist related functions: +var membersPages = new Object; +var membersCurrentPage = 1; + +function membersRequestPage(page) { + console.log('membersRequestPage', page); + if (typeof(ajax) != 'object') { + setTimeout(function() {membersRequestPage(page)},200); + return false; + } + // Ask again if it's busy. + switch (ajax.xmlhttp.readyState) { + case 4: + case 0: + break; + default: + setTimeout(function() {membersRequestPage(page)},300); + return false; + } + + //console.log("Requesting Page", page, ajax.inUse); + // == Additionally, check for achievements. + ajax.requestFile = "do.php?r=reqMemberPage&reqPage="+page; + ajax.onCompletion = membersRequestPageDone; // Specify function to be executed on response. + //ajax.onLoading = ''; + //ajax.onLoaded = ''; + //ajax.onFail = ''; + ajax.runAJAX();// Do it! + return true; +} + +function membersRequestPageDone() { + //console.log("Request Page Done", ajax.response); + var JO = decryptJSON(ajax.response); + if (JO == undefined) + return; + membersUpdatePage(JO.page, membersFormatPage(JO)); +} + +function membersShowPage(page) { + page = page - 0; + console.log('membersShowPage', page); + if (membersPreparePage(page) == false) { + membersCurrentPage = page; + //Signify some sort of loadingness? + //Request Page + membersRequestPage(page); + return; + } + + if (typeof(membersPages[page].html) === 'undefined') { + membersRequestPage(page); + membersCurrentPage = page; + return; + } + document.getElementById('members').innerHTML = membersPages[page].html + + //Also; update the page + + if (page != membersCurrentPage) { + membersRequestPage(page); + } + membersCurrentPage = page; +} + +function membersPreparePage (page) { + if (typeof(membersPages) != 'object') { + membersPages = new Object; + membersPages[page] = new Object; + return false; + } + if (typeof(membersPages[page]) != 'object') { + membersPages[page] = new Object; + return false; + } + return true; +} + +function membersUpdatePage(page, html) { + console.log("Updating Page", page); + membersPreparePage(page); + membersPages[page].html = html; + if (page == membersCurrentPage) { + membersShowPage(page); + } +} + +function membersFormatPageNavi(JO) { + var r = ''; + var showedPrevPage = true; + for (var i = 1; i <= JO.pageCount; i++) { + if ( + (JO.page > i - 3 && JO.page < i + 3) + || (i == 1) + || (i == JO.pageCount) + || (i == JO.userPage) + ) { + + if (!showedPrevPage) + r = r + ' ... '; + if (JO.page == i) { + r = r + " " + i + ""; + } else if (i == JO.userPage) { + r = r + " " + i + ''; + } else { + r = r + " " + i + ''; + } + showedPrevPage = true; + } else { + showedPrevPage = false; + } + } + + return r; +} + +function membersFormatPage(JO) { + // console.log("Formating page"); + + var p = ""; + if (JO.pageCount > 1) { + var navi = membersFormatPageNavi(JO); + p = p+""; + } + + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + + var showedLastUser = true; + var x = 0; + + var previousI = 0; + + for (var i in JO.users) { + var u = JO.users[i]; + var scoredLocalTime = new Date(); + scoredLocalTime.setTime(scoredLocalTime.getTime() - u.secondsSinceScored * 1000); + + var styleClass = ''; + + if (previousI != i + 1) + if (previousI < i - 1 && previousI != 0) + styleClass = 'border-top: 6px solid #777799;'; + + p = p+ ""; + p = p+ ""; + p = p+ ""; + + p = p+ ""; + p = p+ ""; + p = p+ ""; + p = p+ ""; + p = p+ ""; + p = p+ ""; + p = p+ ""; + p = p+ ""; + + previousI = i; + } + + //p = p+""; + p = p+"
"+navi+"
RankNameMazesMovesPast WeekWinsTiesJoinedLast Login
"; + p = p+ i+ ""; + p = p+ "
"; + p = p+ "
"; + p = p+ "
"; + p = p+ "
"; + p = p+ ""; + p = p+ ""+u.display+""; + p = p+ "
"+u.totalMazes+""+u.totalMoves+""+u.totalMovesThisWeek+""+u.totalWins+""+u.totalTies+""+u.dateJoined+""+u.dateLogin+"
"+navi+"
"; + + var nextPage = JO.page - 0 + 1; + var prevPage = JO.page - 1; + + if (JO.pageCount > 1) { + if (JO.page < JO.pageCount) { + p = p+">"; + } else + p = "
>
"+p; + if (JO.page > 1) { + p = "<"+p; + } else + p = "
<
"+p; + } + p = "
"+p+"
"; + + //console.log(p); + //console.log('jo page', JO.page); + //console.log('jo pagecount', JO.pageCount); + //p = JO.navi+p; + return p; +} + + + diff --git a/pages/challenge.php b/pages/challenge.php index 2ab279d..8d312d1 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -1,5 +1,4 @@ -
- Copyright © 2011-2012 pathery.com -
@@ -135,13 +134,15 @@ function displayChallenges($challengeResultset) echo '
    '; while($challenge = mysql_fetch_array($challengeResultset)) { + $mapID = $_GET["mapID"]; $challengeId = $challenge["challengeID"]; echo "
  1. "; if($challenge["dateSolved"] !== NULL) $cssClass = "challenge_complete"; else $cssClass = "challenge_incomplete"; - echo "" . getChallengeDisplayString($challenge) . ""; + $loadSolutionString = " Load this solution"; + echo "" . getChallengeDisplayString($challenge) . " $loadSolutionString "; echo "
  2. "; } echo "
"; @@ -157,7 +158,7 @@ function getChallengeDisplayString($challenge) if($challenge["goal"] == 0) $returnMe .= "Complete the maze"; else if ($challenge['inequality'] == "greater than") - $returnMe .= "Get " . $challenge['goal']; + $returnMe .= "Get " . $challenge['goal'] . ' or more'; else if ($challenge['inequality'] == "less than") $returnMe .= "Get LESS THAN " . $challenge['goal']; else //inequality == "equal" @@ -169,7 +170,7 @@ function getChallengeDisplayString($challenge) //Wall-count restriction if($challenge['restrictWallCount'] !== NULL) { - $restrictions[] = "at most " . $challenge['restrictWallCount'] . " wall" . ($challenge['restrictWallCount'] == 1 ? "" : "s"); + $restrictions[] = "only " . $challenge['restrictWallCount'] . " wall" . ($challenge['restrictWallCount'] == 1 ? "" : "s"); $addUsingToText = true; } diff --git a/pages/challengelist.php b/pages/challengelist.php index e3f057a..03dfdb3 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -1,5 +1,4 @@ -
- Copyright © 2011-2012 pathery.com -
- @@ -84,7 +79,7 @@ function displayChallengeList($challengeListResultset) echo ''; } $currentMap = $challenge["mapID"]; - $mapName = $challenge["challengeName"]; + $mapName = $challenge["name"]; if($mapName == NULL || $mapName == "") $mapName = "(unknown)"; echo "$mapName"; diff --git a/pages/faq.php b/pages/faq.php index 7b3c09c..3df08eb 100644 --- a/pages/faq.php +++ b/pages/faq.php @@ -124,8 +124,8 @@ Likewise, the Red Path noted by red in the arrow may pass over Red Allow blocks:

The pathing is very greedy. It's only looking at it's next target. It does not look at the big-picture. You can use this to your advantage. When there's more than one checkpoint, you can completely wall one off. -
Not many maps contain will more than one of any checkpoint. -
The below demo demonstrates it's greed. - The path will actually be shorter if you wall the bottom A. +
Not many maps will contain more than one of any checkpoint. +
The below demo demonstrates it's greed. - The path will actually be shorter if you wall the bottom A!

Demo 3

diff --git a/pages/gallery.php b/pages/gallery.php index 098cf74..9df059a 100644 --- a/pages/gallery.php +++ b/pages/gallery.php @@ -28,17 +28,171 @@ topbar($Links); include('./includes/maps.php'); include('./includes/mapoftheday.php'); +//$map = getRandomSpecialMap(); +//$map = getRandomWeeklyMap(); +//$map = getRandomComplexMap(); +echo "
"; +echo soundManager2(); + + +$spin[] = 'ooooooooooooooo'; +$spin[] = 'oooooororoooooo'; +$spin[] = 'ooooooooooooooo'; +$spin[] = 'uoooroormoroooo'; +$spin[] = 'soooooratooooof'; +$spin[] = 'noooooororooooo'; +$spin[] = 'ooooorooooooooo'; +$spin[] = 'oooooooroororoo'; +$spin[] = 'ooooooooooooooo'; + + +$myparams['checkpoints'] = 3; +$myparams['teleports'] = 1; +$myparams['rockchance'] = 2000; +$myparams['walls'] = 12; +$myparams['name'] = 'Round and Round'; + +$map = GenerateShapedMap($spin, $myparams); + +echo DisplayMap($map, 2); + +//addNewChallengeMap($map, 0, 0, 'Round and Round'); + +//addNewChallenge(1194, "greater than", 163, 1, "Make it go around and around and around"); +//addNewChallenge(1194, "greater than", 161, 1, "Make it go around and around and around", 11); +//addNewChallenge(1194, "greater than", 173, 1, "Make it go around and around and around"); + +exit; + + +//Add's a new custom challenge map - returns mapid +function addNewChallengeMap($map, $tier, $subOrder, $name) { + $mapcode = GenerateMapCode($map); + + $sql = "INSERT INTO `maps` + (`code`, `isChallenge`, `ChallengeTier`, `ChallengeSuborder`, `ChallengeName`) + VALUES + ('$mapcode', true, $tier, $subOrder, '$name')"; + + echo $sql; + mysql_query($sql); + $mapID = mysql_insert_id(); + return $mapID; +} + +//Returns challenge ID +function addNewChallenge($mapID, $inequality, $goal, $ordering, $hint, + $restrictWallCount = null, $restrictWallPlacement = null, $restrictTeleportCount = null, + $restrictTeleportsUsed = null, $restrictStartPoint = null, $restrictEndPoint = null) { + + $sql = "INSERT INTO `challenges` ( + `mapID`, `inequality`, `goal`, `ordering`, `hint`, + `restrictWallCount`, `restrictWallPlacement`, `restrictTeleportCount`, + `restrictTeleportsUsed`, `restrictStartPoint`, `restrictEndPoint` + ) + VALUES ( + '$mapID', '$inequality', $goal, $ordering, '$hint', + '$restrictWallCount', '$restrictWallPlacement', '$restrictTeleportCount', + '$restrictTeleportsUsed', '$restrictStartPoint', '$restrictEndPoint' + )"; + + echo $sql; + mysql_query($sql); + $challengeID = mysql_insert_id(); + return $challengeID; +} + + +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; +$reversePath[] = 'fo????????????oS'; + +$reversePath = insertPoint($reversePath, 'abc'); + +$myparams['checkpoints'] = 3; +$myparams['teleports'] = 0; +$myparams['rockchance'] = 7; +$myparams['walls'] = 12; +$myparams['name'] = 'Dualing paths'; + +//$map = GenerateShapedMap($reversePath, $myparams); -$openmaps[] = 'Souxoooooooooooooooooooo'; -$openmaps[] = 'ooxoooXooooooooooooooooo'; -$openmaps[] = 'oxooooXoooooooooeocooooo'; -$openmaps[] = 'oxooooXooooooooooooooooo'; -$openmaps[] = 'oxooooXoooaoootooooooooo'; -$openmaps[] = 'oxooooXooooooooooooooooo'; -$openmaps[] = 'oxooooXooooooooooooooooo'; -$openmaps[] = 'oxooooXooooooooooooooooo'; -$openmaps[] = 'oxoooXbdoooooooooooooooo'; -$openmaps[] = 'fooooXooooooooooooooooos'; +$dualingPaths[] = 'so??????????????xf'; +$dualingPaths[] = 'so??????????????xf'; +$dualingPaths[] = 'so??????????????xf'; +$dualingPaths[] = 'so??????????????xf'; +$dualingPaths[] = 'Xo??????????????ox'; +$dualingPaths[] = 'fX??????????????oS'; +$dualingPaths[] = 'fX??????????????oS'; +$dualingPaths[] = 'fX??????????????oS'; +$dualingPaths[] = 'fX??????????????oS'; + +$dualingPaths = insertPoint($dualingPaths, 'abc'); +$dualingPaths = insertPoint($dualingPaths, weight('x', 'xx', 'xxx').weight('X', 'XX', 'XXX')); + +$myparams['checkpoints'] = 3; +$myparams['teleports'] = 0; +$myparams['rockchance'] = 9; +$myparams['walls'] = 12; +$myparams['name'] = 'Dualing paths'; + +$map = GenerateShapedMap($dualingPaths, $myparams); +echo DisplayMap($map, 1); + + + +$unlimited[] = 'so?o?o?o?o?o?o?of'; +$unlimited[] = 's???????????????f'; +$unlimited[] = 'so?????????????of'; +$unlimited[] = 's???????????????f'; +$unlimited[] = 'so?????????????of'; +$unlimited[] = 's???????????????f'; +$unlimited[] = 'so?????????????of'; +$unlimited[] = 's???????????????f'; +$unlimited[] = 'so?o?o?o?o?o?o?of'; + +$unlimited = insertPoint($unlimited, 'abc'); +$unlimited = insertPoint($unlimited, weight('tu', 'dtu')); + +$myparams['checkpoints'] = 3; +$myparams['teleports'] = 1; +$myparams['rockchance'] = 9; +$myparams['walls'] = 999; +$myparams['name'] = 'Unlimited'; + +$map = GenerateShapedMap($unlimited, $myparams); + + +echo "
"; +echo soundManager2(); +echo DisplayMap($map, 2); + +htmlfooter(); +exit; + +//$map = GenerateShapedMap($dualingPaths, $myparams); + +//$map = getRandomSpecialMap(); +//$map = getRandomComplexMap(); + + // DUALING PATHS MAP + + + +$openmaps[] = 'SouooooooXoooooooXooooxf'; +$openmaps[] = 'oooooooooXoooooooXooooox'; +$openmaps[] = 'oooooooooxooooooeXcooooo'; +$openmaps[] = 'oooooooooxoooooooXoooooo'; +$openmaps[] = 'oooooooooxaoootooXoooooo'; +$openmaps[] = 'oooooooooxxxxxxxxxoooooo'; +$openmaps[] = 'oooooooooooooooooooooooo'; +$openmaps[] = 'oooooooooooooooooooooooo'; +$openmaps[] = 'Xooooobdoooooooooooooooo'; +$openmaps[] = 'fXooooooooooooooooooooos'; $myparams['checkpoints'] = 5; $myparams['teleports'] = 0; @@ -46,9 +200,9 @@ $myparams['rockchance'] = 15; $myparams['walls'] = 38; $myparams['name'] = 'Dualing Starts'; -$map = GenerateShapedMap($openmaps, $myparams); +//$map = GenerateShapedMap($openmaps, $myparams); -echo DisplayMap($map, 1); +//echo DisplayMap($map, 1); ?> diff --git a/pages/home.php b/pages/home.php index 7a197aa..37a94c3 100644 --- a/pages/home.php +++ b/pages/home.php @@ -124,6 +124,7 @@ Schick mir einfach eine Zeile auf der Feedback-Seite.
+ '; foreach ($mapNames as $key => $value) { @@ -210,14 +209,14 @@ function displayMaze($motd, $mapType) { "; $mysolution = ''; - $mymoves = ''; + $mymoves = 0; if ($accepted) { $sol = getSolution($userID, $mapID); $mysolution = $sol['solution']; //TODO: implement mymoves $mymoves = $sol['moves']; } - if (isset($_SESSION[$mapID.'sol']) && $mysolution == '') { + if (isset($_SESSION[$mapID.'sol']) && $_SESSION[$mapID.'moves'] > $mymoves) { $mysolution = $_SESSION[$mapID.'sol']; $mymoves = $_SESSION[$mapID.'moves']; } diff --git a/pages/tutorial.php b/pages/tutorial.php index 6854be8..4d2446f 100644 --- a/pages/tutorial.php +++ b/pages/tutorial.php @@ -36,6 +36,7 @@ playerWallEmblem = '';