From b4f0531db076f1ee23962bb40f43f48084a795a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Wed, 6 Jun 2018 00:06:40 +0900 Subject: [PATCH] Fix: update best record for every hour --- src/game/global/global_variables.js | 2 +- src/game/mouse/space_invaders/game.js | 2 +- src/game/start/start.js | 11 +++++++++++ src/web/server/record/request_best_record.php | 2 +- src/web/server/record/update_best_record.php | 6 +++--- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 7bb0d04..4724ab4 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -38,7 +38,7 @@ let sessionStorageManager = new SessionStorageManager(); console.log("playingAppName : " + sessionStorageManager.playingAppName); console.log("playingAppKoreanName : " + sessionStorageManager.playingAppKoreanName); console.log("record : " + sessionStorageManager.record); - console.log("BestRecord : " + sessionStorageManager.bestRecord); + console.log("bestRecord : " + sessionStorageManager.bestRecord); } function isTypingGame() { diff --git a/src/game/mouse/space_invaders/game.js b/src/game/mouse/space_invaders/game.js index 3077e54..7fc64e4 100644 --- a/src/game/mouse/space_invaders/game.js +++ b/src/game/mouse/space_invaders/game.js @@ -30,7 +30,7 @@ class Game { scoreManager.addOnChangeHighScoreListener( highScore => { sessionStorageManager.bestRecord = highScore; sessionStorageManager.isNewBestRecrd = true; - screenBottom.printBottomLeftTextWithBestRecord(); + screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); }); diff --git a/src/game/start/start.js b/src/game/start/start.js index d2f9af1..916ac19 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -16,6 +16,11 @@ class Start { // top let backButton = new BackButton( () => { + sessionStorageManager.playingAppName = null; + sessionStorageManager.playingAppKoreanName = null; + sessionStorageManager.record = null; + sessionStorageManager.bestRecord = null; + location.href = '../../web/client/menu_app.html'; }); @@ -26,6 +31,7 @@ class Start { // this.printHowToPlay(appInfoManager.getHowToPlayText(sessionStorageManager.playingAppName)); this.loadHowToPlay(sessionStorageManager.playingAppID); this.makeStartButton(); + let today = new Date(); let date = DateUtil.getYYYYMMDD(today); this.dbConnectManager.requestPlayerHistory( @@ -71,6 +77,11 @@ class Start { sessionStorageManager.BestRecord = Number(replyJSON["BestRecord"]); let highScoreWithCommas = NumberUtil.numberWithCommas(sessionStorageManager.BestRecord); screenBottom.printBottomLeftText("오늘의 최고 기록 : " + highScoreWithCommas); + }, + replyJSON => { // no data + sessionStorageManager.BestRecord = 0; + let highScoreWithCommas = NumberUtil.numberWithCommas(sessionStorageManager.BestRecord); + screenBottom.printBottomLeftText("오늘의 최고 기록 : " + highScoreWithCommas); } ); } diff --git a/src/web/server/record/request_best_record.php b/src/web/server/record/request_best_record.php index fa2ac40..610624a 100644 --- a/src/web/server/record/request_best_record.php +++ b/src/web/server/record/request_best_record.php @@ -28,7 +28,7 @@ function get_best_record($maestro_id, $app_id, $user_id) { $query = " SELECT BestRecord FROM moty_best_record - WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = Date(NOW()) + WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = DATE(NOW()) "; $stmt = $db_conn->prepare($query); $stmt->bind_param("iii", $maestro_id, $app_id, $user_id); diff --git a/src/web/server/record/update_best_record.php b/src/web/server/record/update_best_record.php index d313fd1..bd86733 100644 --- a/src/web/server/record/update_best_record.php +++ b/src/web/server/record/update_best_record.php @@ -38,7 +38,7 @@ function get_best_record($maestro_id, $app_id, $user_id) { $query = " SELECT BestRecordID, BestRecord FROM moty_best_record - WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = DATE(NOW()) + WHERE MaestroID = ? AND AppID = ? AND UserID = ? AND DATE(RecordDateTime) = DATE(NOW()) AND HOUR(RecordDateTime) = HOUR(NOW()) "; $stmt = $db_conn->prepare($query); $stmt->bind_param("iii", $maestro_id, $app_id, $user_id); @@ -71,8 +71,8 @@ function update_best_record($prev_best_record_id, $best_record) { $query = " UPDATE moty_best_record - SET BestRecord = ?, RecordDateTime = now() - WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW()) + SET BestRecord = ?, RecordDateTime = NOW() + WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW()) AND HOUR(RecordDateTime) = HOUR(NOW()) "; $stmt = $db_conn->prepare($query); $stmt->bind_param('ii', $best_record, $prev_best_record_id);