diff --git a/src/game/lib/animal.js b/src/game/lib/animal.js index 6c800df..5e2a6e0 100644 --- a/src/game/lib/animal.js +++ b/src/game/lib/animal.js @@ -8,22 +8,6 @@ class Animal { this.posY = y; } - animalLevelIDByRecord(record) { - for(let i = Animal.SPECIES_DATA.length - 1; i > 0; i--) { - if(record >= this.typingCount(Animal.SPECIES_DATA[i])) - return i; - } - - return 0; - } - - typingCount(speciesData) { - if(sessionStorageManager.playingAppID <= 20) - return speciesData.practiceTypingCount; - else - return speciesData.testTypingCount; - } - loadSpriteNames() { let spriteNames = {}; @@ -102,6 +86,22 @@ class Animal { } + static animalLevelIDByRecord(record, gameType) { + for(let i = Animal.SPECIES_DATA.length - 1; i > 0; i--) { + if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType)) + return i; + } + + return 0; + } + + static typingCount(speciesData, gameType) { + if(gameType === Animal.TYPE_PRACTICE) + return speciesData.practiceTypingCount; + else + return speciesData.testTypingCount; + } + static loadResources() { game.load.image('snail_shadow', '../../../resources/image/character/animal/snail/shadow.png'); @@ -151,6 +151,9 @@ class Animal { Animal.TYPE_ANIMATION = 0; Animal.TYPE_ICON = 1; +Animal.TYPE_PRACTICE = 0; +Animal.TYPE_TEST = 1; + Animal.ANIMATION_TYPE_CHANGE = 0; Animal.ANIMATION_TYPE_DAMAGE = 1; diff --git a/src/game/lib/button/typing_app_button.js b/src/game/lib/button/typing_app_button.js index 2f19346..0a5566e 100644 --- a/src/game/lib/button/typing_app_button.js +++ b/src/game/lib/button/typing_app_button.js @@ -84,7 +84,6 @@ class TypingAppButton extends RoundRectButton { this.text.x = 30; if(iconName.length > 0) { - console.log(this.icon); this.icon.x = 40; this.icon.width = 100; this.icon.height = 100; diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index c496dba..989623b 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -117,7 +117,7 @@ class DBConnectManager { xhr.send("maestro_id=" + maestroID); } - requestTypingPracticeAppList(maestroID, onSucceededListener, onFailedListener) { + requestTypingPracticeAppList(maestroID, playerID, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/app/menu_active_typing_practice_app_list.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -131,10 +131,10 @@ class DBConnectManager { onFailedListener(replyJSON); } }; - xhr.send("maestro_id=" + maestroID); + xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID); } - requestTypingTestAppList(maestroID, onSucceededListener, onFailedListener) { + requestTypingTestAppList(maestroID, playerID, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/app/menu_active_typing_test_app_list.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -148,7 +148,7 @@ class DBConnectManager { onFailedListener(replyJSON); } }; - xhr.send("maestro_id=" + maestroID); + xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID); } requestPlayerHistory(maestroID, date, listener) { diff --git a/src/game/menu/menu_typing_practice.js b/src/game/menu/menu_typing_practice.js index 315f42d..b6b5f72 100644 --- a/src/game/menu/menu_typing_practice.js +++ b/src/game/menu/menu_typing_practice.js @@ -84,6 +84,7 @@ class MenuTypingPractice { let dbConnectManager = new DBConnectManager(); dbConnectManager.requestTypingPracticeAppList( sessionStorageManager.maestroID, + sessionStorageManager.playerID, self.downloadListSucceeded, self.downloadListFailed ); @@ -99,6 +100,27 @@ class MenuTypingPractice { return false; } + getBestRecord(jsonList, appID) { + let count = Object.keys(jsonList).length; + + for(let i = 0; i < count; i++) { + if(jsonList[i].AppID === appID) + return jsonList[i].BestRecord; + } + + return 0; + } + + getIconImage(jsonList, appID) { + let bestRecord = this.getBestRecord(jsonList, appID); + + if(bestRecord === 0) + return "snail_shadow"; + + let animalLevel = Animal.animalLevelIDByRecord(bestRecord, Animal.TYPE_PRACTICE); + return Animal.SPECIES_DATA[animalLevel].species + Animal.SPRITE_NAMES.icon; + } + downloadListSucceeded(replyJSON) { // console.log(replyJSON); @@ -115,11 +137,10 @@ class MenuTypingPractice { TypingAppButton.BUTTON_UPPER_POS_Y ); - let iconImage = "snail_shadow"; let typingPracticeButton = new TypingAppButton( TypingAppButton.TYPE_PRACTICE_KOREAN, posX, posY, - iconImage, + self.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; @@ -141,11 +162,10 @@ class MenuTypingPractice { TypingAppButton.BUTTON_LOWER_POS_Y ); - let iconImage = "snail_shadow"; let typingPracticeButton = new TypingAppButton( TypingAppButton.TYPE_PRACTICE_ENGLISH, posX, posY, - iconImage, + self.getIconImage(activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; diff --git a/src/game/menu/menu_typing_test.js b/src/game/menu/menu_typing_test.js index 767e161..7d9fda0 100644 --- a/src/game/menu/menu_typing_test.js +++ b/src/game/menu/menu_typing_test.js @@ -32,22 +32,22 @@ class MenuTypingTest { 0, 60 + AppAreaBG.GAP_Y, GAME_SCREEN_SIZE.x, 270 ); - koreanBG.printText( - "한 글 타 자", - game.world.centerX, 320, - 36, "#000", 0.05 - ); + // koreanBG.printText( + // "한 글 타 자", + // game.world.centerX, 320, + // 36, "#000", 0.05 + // ); // english app area let englishBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_ENGLISH, 1, 0, 340, GAME_SCREEN_SIZE.x, 270 ); - englishBG.printText( - "영 문 타 자", - game.world.centerX, 370, - 36, "#000", 0.05 - ); + // englishBG.printText( + // "영 문 타 자", + // game.world.centerX, 370, + // 36, "#000", 0.05 + // ); @@ -84,6 +84,7 @@ class MenuTypingTest { let dbConnectManager = new DBConnectManager(); dbConnectManager.requestTypingTestAppList( sessionStorageManager.maestroID, + sessionStorageManager.playerID, self.downloadListSucceeded, self.downloadListFailed ); @@ -99,6 +100,27 @@ class MenuTypingTest { return false; } + getBestRecord(jsonList, appID) { + let count = Object.keys(jsonList).length; + + for(let i = 0; i < count; i++) { + if(jsonList[i].AppID === appID) + return jsonList[i].BestRecord; + } + + return 0; + } + + getIconImage(jsonList, appID) { + let bestRecord = this.getBestRecord(jsonList, appID); + + if(bestRecord === 0) + return "snail_shadow"; + + let animalLevel = Animal.animalLevelIDByRecord(bestRecord, Animal.TYPE_PRACTICE); + return Animal.SPECIES_DATA[animalLevel].species + Animal.SPRITE_NAMES.icon; + } + downloadListSucceeded(replyJSON) { // console.log(replyJSON); @@ -115,11 +137,10 @@ class MenuTypingTest { TypingAppButton.BUTTON_UPPER_POS_Y ); - let iconImage = "snail_shadow"; let typingTestButton = new TypingAppButton( TypingAppButton.TYPE_TEST_KOREAN, posX, posY, - iconImage, + self.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; @@ -141,11 +162,10 @@ class MenuTypingTest { TypingAppButton.BUTTON_LOWER_POS_Y ); - let iconImage = "snail_shadow"; let typingTestButton = new TypingAppButton( TypingAppButton.TYPE_TEST_ENGLISH, posX, posY, - iconImage, + self.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; diff --git a/src/game/result/result.js b/src/game/result/result.js index 639acc4..b32db1b 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -68,7 +68,11 @@ class Result { if(sessionStorageManager.playingAppID < 100) { let leftAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX - 200, 150); - let animalLevelID = leftAnimal.animalLevelIDByRecord(sessionStorageManager.record); + let animalLevelID = 0; + if(sessionStorageManager.playingAppID < 20) + animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.record, Animal.TYPE_PRACTICE); + else + animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.record, Animal.TYPE_TEST); leftAnimal.setSpecies(Animal.SPECIES_DATA[animalLevelID]);; // leftAnimal.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); leftAnimal.startAnimation(); diff --git a/src/game/typing/practice/game.js b/src/game/typing/practice/game.js index d50e0aa..bcd7415 100644 --- a/src/game/typing/practice/game.js +++ b/src/game/typing/practice/game.js @@ -360,7 +360,7 @@ class TypingPractice { if(this.isKeyPressed(inputContent, typingContent)) { this.typingScore.increase(); - let animalLevelID = this.animalOnTitle.animalLevelIDByRecord(this.typingScore.score()); + let animalLevelID = Animal.animalLevelIDByRecord(this.typingScore.score(), Animal.TYPE_PRACTICE); if(animalLevelID > this.playingAnimalIndex) { this.playingAnimalIndex = animalLevelID; this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);; diff --git a/src/game/typing/test/game.js b/src/game/typing/test/game.js index 95d2727..9ad6b22 100644 --- a/src/game/typing/test/game.js +++ b/src/game/typing/test/game.js @@ -399,7 +399,7 @@ class TypingTest { // console.log('typingRecordTotal : ' + typingRecordTotal); // console.log('-----------------------------------'); - let animalLevelID = this.animalOnTitle.animalLevelIDByRecord(typingRecordTotalInteger); + let animalLevelID = Animal.animalLevelIDByRecord(typingRecordTotalInteger, Animal.TYPE_TEST); this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[animalLevelID]);; this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); this.animalOnTitle.startAnimation(); diff --git a/src/web/server/app/menu_active_typing_practice_app_list.php b/src/web/server/app/menu_active_typing_practice_app_list.php index 45e541d..6442f94 100644 --- a/src/web/server/app/menu_active_typing_practice_app_list.php +++ b/src/web/server/app/menu_active_typing_practice_app_list.php @@ -2,6 +2,7 @@ header("Content-Type: application/json"); $maestro_id = $_POST["maestro_id"]; +$player_id = $_POST["player_id"]; include "./../lib/send_reply_json.php"; include "./../setup/connect_db.php"; @@ -21,13 +22,19 @@ if($englishAppList === null) { send_result_fail(); exit; } + $koreanActiveAppList = get_active_typing_practice_app_list($maestro_id, 1); $englishActiveAppList = get_active_typing_practice_app_list($maestro_id, 2); +$koreanHighScoreList = get_high_score_list($maestro_id, $player_id, $koreanAppList); +$englishHighScoreList = get_high_score_list($maestro_id, $player_id, $englishAppList); + set_data("KoreanAppList", $koreanAppList); set_data("EnglishAppList", $englishAppList); set_data("KoreanActiveAppList", $koreanActiveAppList); set_data("EnglishActiveAppList", $englishActiveAppList); +set_data("KoreanHighScoreList", $koreanHighScoreList); +set_data("EnglishHighScoreList", $englishHighScoreList); send_result_success(); exit; @@ -84,4 +91,44 @@ function get_active_typing_practice_app_list($maestro_id, $appType) { return $return_array; } +function get_high_score_list($maestro_id, $player_id, $appList) { + global $db_conn; + + $return_array = array(); + $count = count($appList); + + for($i = 0; $i < $count; $i++) { + $app_id_list = $appList[$i]['AppID']; + + $query = " + SELECT MAX(BR.BestRecord) + FROM app AS A + INNER JOIN best_record AS BR + ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ? + ORDER BY A.AppID ASC"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id); + $stmt->execute(); + $stmt->bind_result($best_record); + + $returnValue = $stmt->fetch(); + $stmt->close(); + + if($returnValue === NULL || $returnValue === FALSE) + continue; + + // $row_array['maestro_id'] = $maestro_id; + // $row_array['player_id'] = $player_id; + $row_array['AppID'] = $app_id_list; + if($best_record === NULL) + $row_array['BestRecord'] = 0; + else + $row_array['BestRecord'] = $best_record; + + array_push($return_array, $row_array); + } + + return $return_array; +} + ?> \ No newline at end of file diff --git a/src/web/server/app/menu_active_typing_test_app_list.php b/src/web/server/app/menu_active_typing_test_app_list.php index b32323c..905c061 100644 --- a/src/web/server/app/menu_active_typing_test_app_list.php +++ b/src/web/server/app/menu_active_typing_test_app_list.php @@ -2,6 +2,7 @@ header('Content-Type: application/json'); $maestro_id = $_POST["maestro_id"]; +$player_id = $_POST["player_id"]; include "./../lib/send_reply_json.php"; include "./../setup/connect_db.php"; @@ -21,13 +22,19 @@ if($englishAppList === null) { send_result_fail(); exit; } + $koreanActiveAppList = get_active_typing_practice_app_list($maestro_id, 11); $englishActiveAppList = get_active_typing_practice_app_list($maestro_id, 12); +$koreanHighScoreList = get_high_score_list($maestro_id, $player_id, $koreanAppList); +$englishHighScoreList = get_high_score_list($maestro_id, $player_id, $englishAppList); + set_data("KoreanAppList", $koreanAppList); set_data("EnglishAppList", $englishAppList); set_data("KoreanActiveAppList", $koreanActiveAppList); set_data("EnglishActiveAppList", $englishActiveAppList); +set_data("KoreanHighScoreList", $koreanHighScoreList); +set_data("EnglishHighScoreList", $englishHighScoreList); send_result_success(); exit; @@ -84,4 +91,44 @@ function get_active_typing_practice_app_list($maestro_id, $appType) { return $return_array; } +function get_high_score_list($maestro_id, $player_id, $appList) { + global $db_conn; + + $return_array = array(); + $count = count($appList); + + for($i = 0; $i < $count; $i++) { + $app_id_list = $appList[$i]['AppID']; + + $query = " + SELECT MAX(BR.BestRecord) + FROM app AS A + INNER JOIN best_record AS BR + ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ? + ORDER BY A.AppID ASC"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id); + $stmt->execute(); + $stmt->bind_result($best_record); + + $returnValue = $stmt->fetch(); + $stmt->close(); + + if($returnValue === NULL || $returnValue === FALSE) + continue; + + // $row_array['maestro_id'] = $maestro_id; + // $row_array['player_id'] = $player_id; + $row_array['AppID'] = $app_id_list; + if($best_record === NULL) + $row_array['BestRecord'] = 0; + else + $row_array['BestRecord'] = $best_record; + + array_push($return_array, $row_array); + } + + return $return_array; +} + ?> \ No newline at end of file