Add: show animal icon in typing app button
This commit is contained in:
+19
-16
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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]);;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user