diff --git a/src/game/lib/realtime_stage_timer.js b/src/game/lib/realtime_stage_timer.js index 685ccd1..76d1990 100644 --- a/src/game/lib/realtime_stage_timer.js +++ b/src/game/lib/realtime_stage_timer.js @@ -85,6 +85,10 @@ RealtimeStageTimer.prototype.sendElapsedTime = function() { this.onTimeUpdate(timeLeft); } +RealtimeStageTimer.prototype.getElapsedTime = function() { + return this.elapsedTime; +} + RealtimeStageTimer.prototype.removeTimer = function() { game.time.events.remove(this.timerEvent); if(this.timerEvent) diff --git a/src/game/lib/util/string_util.js b/src/game/lib/util/string_util.js index ab4bfb7..8088250 100644 --- a/src/game/lib/util/string_util.js +++ b/src/game/lib/util/string_util.js @@ -51,7 +51,7 @@ StringUtil.toKoreanAlphabets = function(text) { return chars; }; -StringUtil.getUnicodeAlphabetCount = function(text) { +StringUtil.getUnicodeKoreanAlphabetCount = function(text) { var chars = StringUtil.toKoreanAlphabets(text); // console.log('char : ' + chars); @@ -194,9 +194,9 @@ StringUtil.getUnicodeAlphabetCount = function(text) { var textLen = text.length for(var i = 0; i < textLen; i++) { if(StringUtil.isKoreanAlphabet(text[i])) - count += 2; + count += StringUtil.getUnicodeKoreanAlphabetCount(text[i]); else - count++ + count++; } return count; diff --git a/src/game/typing/examination/game.js b/src/game/typing/examination/game.js index 1522161..ff9b890 100644 --- a/src/game/typing/examination/game.js +++ b/src/game/typing/examination/game.js @@ -338,6 +338,9 @@ TypingExamination.prototype.initTypingData = function() { this.typingLetterCountTotal = 0; this.typingRecordTotal = 0; + + this.correctLetterCountInLine = 0; + this.correctLetterCountInAllLines = 0; } @@ -502,6 +505,26 @@ TypingExamination.prototype.onKeyUp = function(event) { this.highlightTypingContent(notTrimmedInputContent, notTrimmedTypingContent); + // get correct letter count + // if the count > this.correctLetterCountInLine + 1 (2 more at onece), it's abusing (reset input text) + // if the count = this.correctLetterCountInLine + 1 + // this.correctLetterCountInLine++ + // this.correctLetterCountForAllLines++ + // update this.textTypingRecord.text with this.correctLetterCountForAllLines + var correctLetterCount = this.getCorrectLetterCount(trimmedInputContent, trimmedTypingContent); + if(correctLetterCount > this.correctLetterCountInLine + 1) { + var abusingAmount = correctLetterCount - this.correctLetterCountInLine; + console.log("abusing!!! " + abusingAmount); + } else { + if(correctLetterCount === this.correctLetterCountInLine + 1) { + this.correctLetterCountInLine++; + var correctLetter = trimmedTypingContent[correctLetterCount - 1]; + var unicodeLetterCount = StringUtil.getUnicodeAlphabetCount(correctLetter); + this.correctLetterCountInAllLines += unicodeLetterCount; + } + } + this.updateTypingRecord(); + if(event.keyCode == Phaser.Keyboard.ENTER) this.onKeyEnter(trimmedInputContent, trimmedTypingContent, notTrimmedTypingContent); @@ -517,7 +540,12 @@ TypingExamination.prototype.onKeyEnter = function(trimmedInputContent, trimmedTy if(trimmedInputContent === trimmedTypingContent) { // console.log("input completed"); - this.calculateTypingRecord(notTrimmedTypingContent); + // this.calculateTypingRecord(notTrimmedTypingContent); + + this.correctLetterCountInAllLines++; + this.correctLetterCountInLine = 0; + // update this.textTypingRecord.text with this.correctLetterCountForAllLines + this.updateTypingRecord(); // console.log("this.typingIndex : " + this.typingIndex); // console.log("this.trimmedTypingContentLength : " + this.trimmedTypingContentLength); @@ -564,6 +592,44 @@ TypingExamination.prototype.highlightTypingContent = function(notTrimmedInputCon } } +TypingExamination.prototype.updateTypingRecord = function() { + + this.typingRecordTotal = this.correctLetterCountInAllLines * TimeUtil.MINUTE_SEC / this.realtimeStageTimer.getElapsedTime(); + // console.log("---"); + // console.log(this.correctLetterCountInAllLines); + // console.log(this.realtimeStageTimer.getElapsedTime()); + // console.log(typingRecord); + var typingRecordInteger = Math.floor(this.typingRecordTotal); + this.averageTypingSpeedText.print(typingRecordInteger); + + var animalLevelID = Animal.animalLevelIDByRecord(typingRecordInteger, Animal.TYPE_EXAM); + this.animalRecordList.activate(animalLevelID); + this.animalRecordList.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); +} + +TypingExamination.prototype.getCorrectLetterCount = function(trimmedInputContent, trimmedTypingContent) { + var typingContentLength = trimmedTypingContent.length; + for(var i = 0; i < typingContentLength; i++) { + var typingChar = trimmedTypingContent.charAt(i); + var inputChar = trimmedInputContent.charAt(i); + // console.log("typingChar : " + typingChar); + // console.log("inputChar : " + inputChar); + + // when typingChar is the last letter + // if(isNaN(inputChar)) + // return 0; + + if(typingChar !== inputChar) { + // console.log("trimmedInputContent.charAt(" + i + ") : " + trimmedInputContent.charCodeAt(i).toString(16) + ", " + inputChar); + // console.log("trimmedTypingContent.charAt(" + i + ") : " + trimmedTypingContent.charCodeAt(i).toString(16) + ", " + typingChar); + + return i; + } + } + + return typingContentLength; +} + TypingExamination.prototype.calculateTypingRecord = function(typingContent) { // console.log('입력 단어 : ' + this.typingExaminationContents[this.typingIndex]); var ONE_MINUTE_MS = Phaser.Timer.SECOND * 60;