diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index a42c7dc..f94f4b1 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -22,13 +22,13 @@ const GAME_SCREEN_SIZE = { x: 1024, y: 768 } let sessionStorageManager = new SessionStorageManager(); { - if(isDebugMode()) { - sessionStorageManager.playerName = "부현율"; - sessionStorageManager.playerUserID = 8; - sessionStorageManager.playingAppName = "space_invaders"; - sessionStorageManager.score = 1000; - sessionStorageManager.highScore = 2000; - } + // if(isDebugMode()) { + // sessionStorageManager.playerName = "부현율"; + // sessionStorageManager.playerUserID = 8; + // sessionStorageManager.playingAppName = "space_invaders"; + // sessionStorageManager.score = 1000; + // sessionStorageManager.highScore = 2000; + // } console.log("maestroID : " + sessionStorageManager.maestroID); console.log("playerName : " + sessionStorageManager.playerName); diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index aa841f1..2111c7e 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -1,16 +1,21 @@ class DBConnectManager { constructor() { + this.path = this.getPath(); + this.directoryName = this.getDirectoryName(this.path); + this.phpPath = this.getPHPPath(this.directoryName); + this.maestroID = 0; this.playerUserID = 0; this.appName = ""; + this.dateAndTime = null; } - setMaestro(maestroID) { + setMaestroID(maestroID) { this.maestroID = maestroID; } - setPlayer(userID) { + setPlayerID(userID) { this.playerUserID = userID; } @@ -18,9 +23,33 @@ class DBConnectManager { this.appName = appName; } + setDateTime(date, time) { + this.dateAndTime = date + time; + } + + resetDateTime() { + this.dateAndTime = null; + } + + getPath() { + return window.location.pathname; + } + + getDirectoryName(path) { + let pathAndFileNames = path.split("/"); + return pathAndFileNames[pathAndFileNames.length - 2]; + } + + getPHPPath(directoryName) { + if(directoryName === "test") // mouse_typing/test/ + return "../src/web/"; + else // mousetyping/src/web/client/ + return "../"; + } + requestCheckUserLogin(userName, enterCode, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); - xhr.open("POST", "../../web/server/user/login.php", true); + xhr.open("POST", this.phpPath + "server/user/login.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { @@ -32,7 +61,7 @@ class DBConnectManager { onFailedListener(jsonData); } }; - xhr.send("name=" + sessionStorageManager.playerName + "&enter_code=" + enterCode); + xhr.send("name=" + userName + "&enter_code=" + enterCode); } requestPlayerHistory(listener) { @@ -52,7 +81,7 @@ class DBConnectManager { let self = this; let xhr = new XMLHttpRequest(); - xhr.open("POST", "../../web/server/record/history_record.php", true); + xhr.open("POST", this.phpPath + "server/record/history_record.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { @@ -128,7 +157,7 @@ class DBConnectManager { let self = this; let xhr = new XMLHttpRequest(); - xhr.open("POST", this.getPHPUrl(type), true); + xhr.open("POST", this.getRankingRecordUrl(type), true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { @@ -146,22 +175,27 @@ class DBConnectManager { xhr.send(params); } - getPHPUrl(type) { + getRankingRecordUrl(type) { + let rankingRecordURL = this.phpPath; + switch(type) { case DBConnectManager.TYPE_MY_RANKING_HOUR: case DBConnectManager.TYPE_ALL_RANKING_HOUR: - return "../../web/server/record/ranking_hour_record.php"; + rankingRecordURL += "server/record/ranking_record_hour.php"; + break; case DBConnectManager.TYPE_MY_RANKING_DAY: case DBConnectManager.TYPE_ALL_RANKING_DAY: - return "../../web/server/record/ranking_day_record.php"; + rankingRecordURL += "server/record/ranking_record_day.php"; + break; case DBConnectManager.TYPE_MY_RANKING_MONTH: case DBConnectManager.TYPE_ALL_RANKING_MONTH: - return "../../web/server/record/ranking_month_record.php"; + rankingRecordURL += "server/record/ranking_record_month.php"; + break; } - return ""; + return rankingRecordURL; } parseJSONtoRankingRecord(type, json) { diff --git a/src/game/result/history_board.js b/src/game/result/history_board.js index b34633b..a9a2321 100644 --- a/src/game/result/history_board.js +++ b/src/game/result/history_board.js @@ -14,7 +14,7 @@ class HistoryBoard { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); this.dbConnectManager.requestPlayerHistory( historyRecordManager => { - let maxIndex = historyRecordManager.count; + let maxIndex = historyRecordManager.count - 1; if(maxIndex > 6) maxIndex = 6; diff --git a/src/web/server/record/ranking_month_record.php b/src/web/server/record/ranking_record 복사본.php similarity index 100% rename from src/web/server/record/ranking_month_record.php rename to src/web/server/record/ranking_record 복사본.php diff --git a/src/web/server/record/ranking_day_record.php b/src/web/server/record/ranking_record_day.php similarity index 100% rename from src/web/server/record/ranking_day_record.php rename to src/web/server/record/ranking_record_day.php diff --git a/src/web/server/record/ranking_hour_record.php b/src/web/server/record/ranking_record_hour.php similarity index 100% rename from src/web/server/record/ranking_hour_record.php rename to src/web/server/record/ranking_record_hour.php diff --git a/src/web/server/record/ranking_record_month.php b/src/web/server/record/ranking_record_month.php new file mode 100644 index 0000000..9fccb50 --- /dev/null +++ b/src/web/server/record/ranking_record_month.php @@ -0,0 +1,49 @@ +prepare($query); +$stmt->bind_param('s', $app_name); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $high_score); + +$score_record_array = array(); +while($stmt->fetch()) { + $score_record['UserID'] = $userID; + $score_record['Name'] = $name; + $score_record['HighScore'] = $high_score; + array_push($score_record_array, $score_record); +} +$return_array['rankingMonth'] = $score_record_array; + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/test/db_connect_manager.html b/test/db_connect_manager.html new file mode 100644 index 0000000..6095284 --- /dev/null +++ b/test/db_connect_manager.html @@ -0,0 +1,23 @@ + + +
+ + +