diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 4400653..fcd0c96 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -37,6 +37,17 @@ let sessionStorageManager = new SessionStorageManager(); console.log("score : " + sessionStorageManager.score); console.log("highscore : " + sessionStorageManager.highScore); } + +function isTypingGame() { + if(sessionStorageManager.playingAppName === null) + return false; + + if(sessionStorageManager.playingAppName.indexOf("typing") < 0) + return false; + + return true; +} + let appInfoManager = new AppInfoManager(); let textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" }; diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 3668120..d576ac3 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -71,6 +71,12 @@ class DBConnectManager { parseJSONtoHistoryRecord(json) { let historyRecordManager = new HistoryRecordManager(); + if(typeof json === "undefined") + return historyRecordManager; + + if(typeof json.history === "undefined") + return historyRecordManager; + let count = json.history.length; for(let i = 0; i < count; i++) { let record = new HistoryRecord( @@ -108,16 +114,98 @@ class DBConnectManager { requestRanking(type, listener) { let rankingRecordManager = new RankingRecordManager(); + /* if(isDebugMode()) { - this.loadTempPlayerHistory(historyRecordManager); + this.loadTempRanking(rankingRecordManager); if(listener !== null) - listener(historyRecordManager); + listener(rankingRecordManager); return; } + */ + + let self = this; + + let xhr = new XMLHttpRequest(); + xhr.open("POST", this.getPHPUrl(type), true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null) { + listener(type, self.parseJSONtoRankingRecord(type, jsonData)); + } + else + onFailedListener(jsonData); + } + }; + let params = "UserID=" + sessionStorageManager.playerUserID + + "&AppName=" + sessionStorageManager.playingAppName; + console.log(params); + xhr.send(params); } + getPHPUrl(type) { + switch(type) { + case DBConnectManager.TYPE_MY_RANKING_HOUR: + case DBConnectManager.TYPE_ALL_RANKING_HOUR: + return "../../web/server/record/ranking_hour_record.php"; + + case DBConnectManager.TYPE_MY_RANKING_DAY: + case DBConnectManager.TYPE_ALL_RANKING_DAY: + return "../../web/server/record/ranking_day_record.php"; + + case DBConnectManager.TYPE_MY_RANKING_MONTH: + case DBConnectManager.TYPE_ALL_RANKING_MONTH: + return "../../web/server/record/ranking_month_record.php"; + } + + return ""; + } + + parseJSONtoRankingRecord(type, json) { + let rankingRecordManager = new RankingRecordManager(); + + if(typeof json === "undefined") + return rankingRecordManager; + + let jsonData = null; + switch(type) { + case DBConnectManager.TYPE_MY_RANKING_HOUR: + case DBConnectManager.TYPE_ALL_RANKING_HOUR: + jsonData = json.rankingHour; + break; + + case DBConnectManager.TYPE_MY_RANKING_DAY: + case DBConnectManager.TYPE_ALL_RANKING_DAY: + jsonData = json.rankingDay; + break; + + case DBConnectManager.TYPE_MY_RANKING_MONTH: + case DBConnectManager.TYPE_ALL_RANKING_MONTH: + jsonData = json.rankingMonth; + break; + } + + if(jsonData === null) + return rankingRecordManager; + + let count = jsonData.length; + for(let i = 0; i < count; i++) { + let record = new RankingRecord( + i + 1, + jsonData[i]["Name"], + jsonData[i]["HighScore"] + ); + rankingRecordManager.push(record); + } + + return rankingRecordManager; + } + + onFailed(errorMessage) { console.log("failed : " + errorMessage); } diff --git a/src/game/lib/number_util.js b/src/game/lib/number_util.js index 361e16c..f002b2a 100644 --- a/src/game/lib/number_util.js +++ b/src/game/lib/number_util.js @@ -8,4 +8,14 @@ class NumberUtil { return Math.floor(Math.log(number) / Math.LN10 + 1); // bug : 1000 -> expected 4 but 3 } + static getScoreText(value) { + let number = Math.floor(value); + let numberWithCommas = NumberUtil.numberWithCommas(number); + + if(isTypingGame()) + return numberWithCommas + " 타"; + else + return numberWithCommas + " 점"; + } + } \ No newline at end of file diff --git a/src/game/lib/string_util.js b/src/game/lib/string_util.js new file mode 100644 index 0000000..8c57a54 --- /dev/null +++ b/src/game/lib/string_util.js @@ -0,0 +1,23 @@ +class StringUtil { + + static printMonthDay(date) { + let dateTime = new Date(date); + return (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일"; + } + + static getScoreTextWithoutUnit(value) { + let number = Math.floor(value); + return NumberUtil.numberWithCommas(number); + } + + static getScoreTextWithUnit(value) { + let number = Math.floor(value); + let numberWithCommas = NumberUtil.numberWithCommas(number); + + if(isTypingGame()) + return numberWithCommas + " 타"; + else + return numberWithCommas + " 점"; + } + +} \ No newline at end of file diff --git a/src/game/result/history_board.js b/src/game/result/history_board.js index f4730af..b34633b 100644 --- a/src/game/result/history_board.js +++ b/src/game/result/history_board.js @@ -14,12 +14,17 @@ class HistoryBoard { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); this.dbConnectManager.requestPlayerHistory( historyRecordManager => { + let maxIndex = historyRecordManager.count; + if(maxIndex > 6) + maxIndex = 6; + for(let i = 0; i < historyRecordManager.count; i++) { if(i > 6) break; - let data = historyRecordManager.getAt(i); + let data = historyRecordManager.getAt(maxIndex); this.printRecord(i, data.date, data.score); + maxIndex--; } }); } @@ -39,13 +44,12 @@ class HistoryBoard { var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" }; style.boundsAlignH = "center"; - game.add.text(posX, posY, date, style) + game.add.text(posX, posY, StringUtil.printMonthDay(date), style) .setTextBounds(0, 0, 100, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - let numberWithCommas = NumberUtil.numberWithCommas(score); style.boundsAlignH = "right"; - game.add.text(posX + 80, posY, numberWithCommas, style) + game.add.text(posX + 80, posY, StringUtil.getScoreTextWithoutUnit(score), style) .setTextBounds(0, 0, 100, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); } @@ -61,14 +65,12 @@ class HistoryBoard { .setTextBounds(0, 0, 40, 40) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - let typingAppName = appName; - game.add.text(posX + 60, posY, typingAppName, style) + game.add.text(posX + 60, posY, appName, style) .setTextBounds(0, 0, 60, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - let numberWithCommas = NumberUtil.numberWithCommas(score); style.boundsAlignH = "right"; - game.add.text(posX + 120, posY, numberWithCommas, style) + game.add.text(posX + 120, posY, StringUtil.getScoreTextWithoutUnit(score), style) .setTextBounds(0, 0, 80, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); } diff --git a/src/game/result/ranking_board.js b/src/game/result/ranking_board.js index 22d1989..08ec60e 100644 --- a/src/game/result/ranking_board.js +++ b/src/game/result/ranking_board.js @@ -7,13 +7,15 @@ class RankingBoard { this.dbConnectManager = new DBConnectManager(); this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR); - this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY); - this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH); + // this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY); + // this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH); } requestRanking(type, rankingRecordManager) { - this.dbConnectManager.requestRanking(type, rankingRecordManager => { + this.dbConnectManager.requestRanking(type, (type, rankingRecordManager) => { + console.log(type); + console.log(rankingRecordManager); for(let i = 0; i < rankingRecordManager.count; i++) { if(i > 6) break; @@ -40,9 +42,9 @@ class RankingBoard { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); // score - let numberWithCommas = NumberUtil.numberWithCommas(data.score); + let score = StringUtil.getScoreTextWithoutUnit(data.score); style.boundsAlignH = "right"; - game.add.text(this.getPosX(type) + 120, this.getPosY(index), numberWithCommas, style) + game.add.text(this.getPosX(type) + 120, this.getPosY(index), score, style) .setTextBounds(0, 0, 80, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); } @@ -53,17 +55,17 @@ class RankingBoard { switch(type) { case DBConnectManager.TYPE_MY_RANKING_HOUR: case DBConnectManager.TYPE_ALL_RANKING_HOUR: - posX = 340; + posX = 320; break; case DBConnectManager.TYPE_MY_RANKING_DAY: case DBConnectManager.TYPE_ALL_RANKING_DAY: - posX = 560; + posX = 540; break; case DBConnectManager.TYPE_MY_RANKING_MONTH: case DBConnectManager.TYPE_ALL_RANKING_MONTH: - posX = 780; + posX = 760; } return posX; diff --git a/src/game/result/record_board.js b/src/game/result/record_board.js index 05501ec..c47341f 100644 --- a/src/game/result/record_board.js +++ b/src/game/result/record_board.js @@ -15,7 +15,7 @@ class RecordBoard { printRecordBoardHeader() { - let posX = 40; + let posX = 60; let posY = game.world.height / 2 + 20; var bar = game.add.graphics(); @@ -25,14 +25,14 @@ class RecordBoard { const style = { font: "32px Arial", fill: "#ffc", align: "left", boundsAlignH: "center", boundsAlignV: "middle" }; this.printHeader(posX, posY, "최근의 내 기록", style); - posX = 340; + posX = 320; style.fill = "#fff"; this.printHeader(posX, posY, "수업시간 순위", style); - posX = 560; + posX = 550; this.printHeader(posX, posY, "오늘의 순위", style); - posX = 780; + posX = 770; this.printHeader(posX, posY, "이달의 순위", style); } @@ -43,7 +43,7 @@ class RecordBoard { } printSeperator() { - const posX = 300; + const posX = 290; const posY = 480; this.chartGraphics.lineStyle(3, 0x444444, 1); diff --git a/src/game/start/start.js b/src/game/start/start.js index 8eb9b4c..11a8f28 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -80,18 +80,18 @@ class Start { const CHART_HEIGHT = 120; const style = { font: "24px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" }; - let dateTime = new Date(date); - console.log(dateTime); - console.log((dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일"); - let monthDay = (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일"; - - let dateText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 140, monthDay, style); + let dateText = game.add.text( + 100 + index * CHART_GAP_PX, game.world.height - 140, + StringUtil.printMonthDay(date), style + ); dateText.setTextBounds(0, 0, 100, 100); dateText.stroke = "#333"; dateText.strokeThickness = 1; - let numberWithCommas = NumberUtil.numberWithCommas(Math.floor(score)); - let scoreText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 300, numberWithCommas, style); + let scoreText = game.add.text( + 100 + index * CHART_GAP_PX, game.world.height - 300, + StringUtil.getScoreTextWithUnit(score), style + ); scoreText.setTextBounds(0, 0, 100, 100); scoreText.stroke = "#333"; scoreText.strokeThickness = 1; diff --git a/src/web/client/result.html b/src/web/client/result.html index 889c498..5d245ae 100644 --- a/src/web/client/result.html +++ b/src/web/client/result.html @@ -16,6 +16,7 @@ + diff --git a/src/web/client/start.html b/src/web/client/start.html index 21f8d6c..6685d7f 100644 --- a/src/web/client/start.html +++ b/src/web/client/start.html @@ -16,6 +16,7 @@ + diff --git a/src/web/server/record/history_record.php b/src/web/server/record/history_record.php index 54f5985..cacdb1d 100644 --- a/src/web/server/record/history_record.php +++ b/src/web/server/record/history_record.php @@ -1,12 +1,12 @@ execute(); $stmt->bind_result($date, $score, $app_name); -$bestRecordArray = array(); +$history_record_array = array(); while($stmt->fetch()) { - $best_record['Date'] = $date; - $best_record['HighScore'] = $score; - $best_record['AppName'] = $app_name; - array_push($bestRecordArray, $best_record); - array_push($return_array, $best_record); + $history_record['Date'] = $date; + $history_record['HighScore'] = $score; + $history_record['AppName'] = $app_name; + array_push($history_record_array, $history_record); + array_push($return_array, $history_record); } -$return_array['history'] = $bestRecordArray; +$return_array['history'] = $history_record_array; echo json_encode($return_array, JSON_UNESCAPED_UNICODE); diff --git a/src/web/server/record/ranking_day_record.php b/src/web/server/record/ranking_day_record.php new file mode 100644 index 0000000..bf2614e --- /dev/null +++ b/src/web/server/record/ranking_day_record.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['rankingDay'] = $score_record_array; + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/server/record/ranking_hour_record.php b/src/web/server/record/ranking_hour_record.php new file mode 100644 index 0000000..e820a3b --- /dev/null +++ b/src/web/server/record/ranking_hour_record.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['rankingHour'] = $score_record_array; + +echo json_encode($return_array, JSON_UNESCAPED_UNICODE); + + +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/server/record/ranking_month_record.php b/src/web/server/record/ranking_month_record.php new file mode 100644 index 0000000..effaa26 --- /dev/null +++ b/src/web/server/record/ranking_month_record.php @@ -0,0 +1,40 @@ +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/src/web/server/record/ranking_record.php b/src/web/server/record/ranking_record.php new file mode 100644 index 0000000..c011f74 --- /dev/null +++ b/src/web/server/record/ranking_record.php @@ -0,0 +1,88 @@ +prepare($query); +$stmt->bind_param('s', $app_name); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$score_record_array = array(); +while($stmt->fetch()) { + $score_record['UserID'] = $userID; + $score_record['Name'] = $name; + $score_record['HighScore'] = $record; + array_push($score_record_array, $score_record); +} +$return_array['rankingHour'] = $score_record_array; + + +// ranking day +$query = " + SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore + FROM afterschool_record D, afterschool_user U + WHERE D.userID = U.userID AND DATE(D.DateTime) = DATE(NOW()) AND AppName = ? + GROUP BY D.userID + ORDER BY max(D.Record) DESC; +"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('s', $app_name); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$score_record_array = array(); +while($stmt->fetch()) { + $score_record['UserID'] = $userID; + $score_record['Name'] = $name; + $score_record['HighScore'] = $record; + array_push($score_record_array, $score_record); +} +$return_array['rankingDay'] = $score_record_array; + + +// ranking month +$query = " + SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS HighScore + FROM afterschool_record D, afterschool_user U + WHERE D.userID = U.userID AND MONTH(D.DateTime) = MONTH(NOW()) AND AppName = ? + GROUP BY D.userID + ORDER BY max(D.Record) DESC; +"; +$stmt = $db_conn->prepare($query); +$stmt->bind_param('s', $app_name); +$stmt->execute(); + +$stmt->bind_result($userID, $name, $record); + +$score_record_array = array(); +while($stmt->fetch()) { + $score_record['UserID'] = $userID; + $score_record['Name'] = $name; + $score_record['HighScore'] = $record; + 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/src/web/server/record/stage_ranking.php b/src/web/server/record/stage_ranking.php deleted file mode 100644 index 950a8ce..0000000 --- a/src/web/server/record/stage_ranking.php +++ /dev/null @@ -1,118 +0,0 @@ -prepare($query); -$stmt->bind_param('s', $user_id); -$stmt->execute(); - -$stmt->bind_result($date, $record, $stage_name); - -$bestRecordArray = array(); -while($stmt->fetch()) { - $best_record['Date'] = $date; - $best_record['BestRecord'] = $record; - $best_record['StageName'] = $stage_name; - array_push($bestRecordArray, $best_record); - array_push($return_array, $best_record); -} -$return_array['myRanking'] = $bestRecordArray; - - -// ranking hour -$query = " - SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord - FROM afterschool_record D, afterschool_user U - WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ? - GROUP BY D.userID - ORDER BY max(D.Record) DESC; -"; -$stmt = $db_conn->prepare($query); -$stmt->bind_param('s', $stageName); -$stmt->execute(); - -$stmt->bind_result($userID, $name, $record); - -$bestRecordArray = array(); -while($stmt->fetch()) { - $best_record['UserID'] = $userID; - $best_record['Name'] = $name; - $best_record['BestRecord'] = $record; - array_push($bestRecordArray, $best_record); - // array_push($return_array, $best_record); -} -$return_array['rankingHour'] = $bestRecordArray; - - -// ranking day -$query = " - SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord - FROM afterschool_record D, afterschool_user U - WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ? - GROUP BY D.userID - ORDER BY max(D.Record) DESC; -"; -$stmt = $db_conn->prepare($query); -$stmt->bind_param('s', $stageName); -$stmt->execute(); - -$stmt->bind_result($userID, $name, $record); - -$bestRecordArray = array(); -while($stmt->fetch()) { - $best_record['UserID'] = $userID; - $best_record['Name'] = $name; - $best_record['BestRecord'] = $record; - array_push($bestRecordArray, $best_record); - // array_push($return_array, $best_record); -} -$return_array['rankingDay'] = $bestRecordArray; - - -// ranking month -$query = " - SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord - FROM afterschool_record D, afterschool_user U - WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ? - GROUP BY D.userID - ORDER BY max(D.Record) DESC; -"; -$stmt = $db_conn->prepare($query); -$stmt->bind_param('s', $stageName); -$stmt->execute(); - -$stmt->bind_result($userID, $name, $record); - -$bestRecordArray = array(); -while($stmt->fetch()) { - $best_record['UserID'] = $userID; - $best_record['Name'] = $name; - $best_record['BestRecord'] = $record; - array_push($bestRecordArray, $best_record); - // array_push($return_array, $best_record); -} -$return_array['rankingMonth'] = $bestRecordArray; - -echo json_encode($return_array, JSON_UNESCAPED_UNICODE); - - -$db_conn->close(); - -?> \ No newline at end of file diff --git a/src/web/server/NA_service_db_setting.php b/src/web/server/setup/NA_service_db_setting.php similarity index 100% rename from src/web/server/NA_service_db_setting.php rename to src/web/server/setup/NA_service_db_setting.php diff --git a/src/web/server/connect_db.php b/src/web/server/setup/connect_db.php similarity index 100% rename from src/web/server/connect_db.php rename to src/web/server/setup/connect_db.php