Fix: stop playing after time over

This commit is contained in:
2019-08-28 23:50:52 +09:00
parent cf119e4bf1
commit 2bc00ed186
2 changed files with 56 additions and 95 deletions
+16 -1
View File
@@ -189,7 +189,7 @@ StringUtil.isKoreanAlphabet = function(char) {
return false;
};
StringUtil.getUnicodeAlphabetCount = function(text) {
StringUtil.getSyllableCount = function(text) {
var count = 0;
var textLen = text.length
for(var i = 0; i < textLen; i++) {
@@ -204,6 +204,21 @@ StringUtil.getUnicodeAlphabetCount = function(text) {
return count;
};
StringUtil.getUnicodeAlphabetCount = function(text) {
var count = 0;
var textLen = text.length
for(var i = 0; i < textLen; i++) {
var unicodeLetter = text[i];
if(StringUtil.isKoreanAlphabet(unicodeLetter))
count += 2;
else
count++;
}
// console.log(unicodeLetter + " count : " + count);
return count;
};
StringUtil.getMultibyteIndex = function(multibyteText, unicodeCharIndex) {
var multibyteTextIndex = 0;
var index = 0;
+40 -94
View File
@@ -19,7 +19,7 @@ TypingExamination.prototype.create = function() {
sessionStorageManager.setRecord(0);
this.initTypingData();
this.initialize();
sessionStorageManager.setIsNewAppHighestRecord(false);
var experienceAppTimer = new ExperienceAppTimer();
@@ -64,13 +64,15 @@ TypingExamination.prototype.create = function() {
);
this.realtimeStageTimer.setTimeOverEvent(
(function() {
this.isGameOver = true;
this.textTimer.text = "타임 오버";
console.log("Time over");
this.updateCorrectUnicodeLetterCount();
this.updateTypingRecord();
// this.inputTextContent.inputEnabled = false;
this.timeOver();
}).bind(this)
);
@@ -84,6 +86,20 @@ TypingExamination.prototype.create = function() {
// this.countDown();
}
TypingExamination.prototype.initialize = function() {
this.typingIndex = 0;
this.isGameOver = false;
this.isTyping = false;
this.correctLetterCountInLine = 0;
this.correctSyllableLetterCountInAllLines = 0;
this.typingRecordTotal = 0;
this.animalLevelID = -1;
}
TypingExamination.prototype.fontLoaded = function() {
this.makeAnimalRecordList();
// this.animalRecordList.hide();
@@ -237,6 +253,9 @@ TypingExamination.prototype.makeTextContents = function() {
this.inputTextContent.canvasInput.placeHolder("");
// inputTextContent.canvasInput._onkeydown = this.checkInputText;
this.inputTextContent.canvasInput._onkeyup = (function() {
if(this.isGameOver)
return;
this.onKeyUp(event);
// warning
// : onKeyUp is called onkeyup and onkeydown
@@ -293,12 +312,12 @@ TypingExamination.prototype.startGame = function() {
this.showTypingExaminationContents();
this.showPlayingWordNumber();
this.realtimeStageTimer.start();
// this.realtimeStageTimer.start();
}
TypingExamination.prototype.timeOver = function() {
var timeOverText = new TimeOverText();
// this.stopAndGoResult();
this.stopAndGoResult();
}
TypingExamination.prototype.gameOver = function() {
@@ -338,25 +357,6 @@ TypingExamination.prototype.goResult = function() {
}
TypingExamination.prototype.initTypingData = function() {
this.typingIndex = 0;
this.isGameOver = false;
this.isTyping = false;
this.timeTypingStart = 0;
this.timeTypingEnd = 0;
this.typingLetterCountTotal = 0;
this.typingRecordTotal = 0;
this.correctLetterCountInLine = 0;
this.correctUnicodeLetterCountInAllLines = 0;
this.animalLevelID = -1;
}
TypingExamination.prototype.loadExaminationContent = function() {
this.dbService.requestWritingInfo(
sessionStorageManager.getWritingID(),
@@ -497,12 +497,9 @@ TypingExamination.prototype.resetTypingContent = function() {
}
TypingExamination.prototype.onKeyUp = function(event) {
if(this.isGameOver)
return;
if(this.isTyping == false) {
if(this.isTyping === false) {
// console.log(event);
this.setTimeTypingStart();
this.startTyping();
}
//not trimmed contents
@@ -537,9 +534,9 @@ TypingExamination.prototype.updateCorrectUnicodeLetterCount = function() {
this.correctLetterCountInLine++;
var correctLetter = notTrimmedInputContent[this.correctLetterCountInLine - 1];
var unicodeLetterCount = StringUtil.getUnicodeAlphabetCount(correctLetter);
this.correctUnicodeLetterCountInAllLines += unicodeLetterCount;
// console.log(this.correctUnicodeLetterCountInAllLines + " : '" + correctLetter + "'");
var syllableLetterCount = StringUtil.getSyllableCount(correctLetter);
this.correctSyllableLetterCountInAllLines += syllableLetterCount;
// console.log(this.correctSyllableLetterCountInAllLines + " : '" + correctLetter + "'");
} else if(correctLetterCount > this.correctLetterCountInLine) {
var count = correctLetterCount - this.correctLetterCountInLine;
// console.log("*** missed onKeyUp event - begin : " + count);
@@ -547,9 +544,9 @@ TypingExamination.prototype.updateCorrectUnicodeLetterCount = function() {
this.correctLetterCountInLine++;
var correctLetter = notTrimmedInputContent[this.correctLetterCountInLine - 1];
var unicodeLetterCount = StringUtil.getUnicodeAlphabetCount(correctLetter);
this.correctUnicodeLetterCountInAllLines += unicodeLetterCount;
// console.log(this.correctUnicodeLetterCountInAllLines + " : '" + correctLetter + "'");
var syllableLetterCount = StringUtil.getSyllableCount(correctLetter);
this.correctSyllableLetterCountInAllLines += syllableLetterCount;
// console.log(this.correctSyllableLetterCountInAllLines + " : '" + correctLetter + "'");
}
// console.log("*** missed onKeyUp event - end");
} else {
@@ -567,8 +564,8 @@ TypingExamination.prototype.onKeyEnter = function(trimmedInputContent, trimmedTy
// console.log("input completed");
// this.calculateTypingRecord(notTrimmedTypingContent);
this.correctUnicodeLetterCountInAllLines++;
// console.log(this.correctUnicodeLetterCountInAllLines + " : Enter");
this.correctSyllableLetterCountInAllLines++;
// console.log(this.correctSyllableLetterCountInAllLines + " : Enter");
this.correctLetterCountInLine = 0;
// update this.textTypingRecord.text with this.correctLetterCountForAllLines
this.updateTypingRecord();
@@ -621,10 +618,12 @@ TypingExamination.prototype.highlightTypingContent = function(notTrimmedInputCon
}
TypingExamination.prototype.updateTypingRecord = function() {
if(this.isGameOver)
return;
this.typingRecordTotal = this.correctUnicodeLetterCountInAllLines * TimeUtil.MINUTE_SEC / this.realtimeStageTimer.getElapsedTime();
this.typingRecordTotal = this.correctSyllableLetterCountInAllLines * TimeUtil.MINUTE_SEC / this.realtimeStageTimer.getElapsedTime();
// console.log("---");
// console.log(this.correctUnicodeLetterCountInAllLines);
// console.log(this.correctSyllableLetterCountInAllLines);
// console.log(this.realtimeStageTimer.getElapsedTime());
// console.log(typingRecord);
var typingRecordInteger = Math.floor(this.typingRecordTotal);
@@ -661,50 +660,6 @@ TypingExamination.prototype.getCorrectLetterCount = function(inputContent, typin
return typingContentLength;
}
TypingExamination.prototype.calculateTypingRecord = function(typingContent) {
// console.log('입력 단어 : ' + this.typingExaminationContents[this.typingIndex]);
var ONE_MINUTE_MS = Phaser.Timer.SECOND * 60;
this.isTyping = false;
this.timeTypingEnd = game.time.elapsedSince(0);
// console.log('this.timeTypingEnd : ' + this.timeTypingEnd);
var elapsedTimeMS = this.timeTypingEnd - this.timeTypingStart;
// console.log('elapsedTimeMS : ' + elapsedTimeMS);
var typingContentLength = StringUtil.getUnicodeAlphabetCount(typingContent);
// console.log('typingContentLength : ' + typingContentLength);
var typingRecord = typingContentLength * (ONE_MINUTE_MS / elapsedTimeMS);
this.typingElapsedTime[this.typingIndex] = elapsedTimeMS;
this.typingLetterCountTotal += typingContentLength;
this.typingRecordForLines[this.typingIndex] = typingRecord;
// console.log(this.typingRecordForLines[this.typingIndex]);
var typingElapsedTimeTotal = 0;
for(var i = 0; i <= this.typingIndex; i++) {
// console.log('i : ' + i + ' - time : ' + this.typingElapsedTime[i]);
typingElapsedTimeTotal += this.typingElapsedTime[i];
}
// this.typingRecordTotal = this.typingLetterCountTotal * 60000 / typingElapsedTimeTotal;
this.typingRecordTotal = this.typingLetterCountTotal * (ONE_MINUTE_MS / typingElapsedTimeTotal);
// console.log(this.typingElapsedTime);
// console.log(this.typingLetterCountTotal);
// console.log(typingElapsedTimeTotal);
// console.log(typingRecordTotal);
var typingRecordTotalInteger = Math.floor(this.typingRecordTotal);
this.averageTypingSpeedText.print(typingRecordTotalInteger);
// console.log('-------------- total --------------');
// console.log('typingLetterCountTotal : ' + this.typingLetterCountTotal);
// console.log('typingElapsedTimeTotal : ' + typingElapsedTimeTotal);
// console.log('typingRecordTotal : ' + this.typingRecordTotal);
// console.log('-----------------------------------');
var animalLevelID = Animal.animalLevelIDByRecord(typingRecordTotalInteger, Animal.TYPE_EXAM);
this.animalRecordList.activate(animalLevelID);
this.animalRecordList.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE);
}
TypingExamination.prototype.playNextContent = function() {
this.typingIndex++;
@@ -719,25 +674,16 @@ TypingExamination.prototype.showPlayingWordNumber = function() {
this.textTypingLine.text = this.typingContentLength - this.typingIndex + " ";
}
TypingExamination.prototype.setTimeTypingStart = function() {
TypingExamination.prototype.startTyping = function() {
if(this.inputTextContent.canvasInput.value() == "")
return;
this.timeTypingStart = game.time.elapsedSince(0);
var timeGap = this.timeTypingStart - this.timeTypingEnd;
if(timeGap < 50)
return;
this.realtimeStageTimer.start();
this.isTyping = true;
// console.log('last End : ' + this.timeTypingEnd);
// console.log('this.timeTypingStart : ' + this.timeTypingStart);
// console.log('time gap : ' + (this.timeTypingStart - this.timeTypingEnd));
}
TypingExamination.GAME_TIME_SEC = 3; //TimeUtil.MINUTE_SEC * 5; // 5 minutes
TypingExamination.GAME_TIME_SEC = TimeUtil.MINUTE_SEC * 5; // 5 minutes
TypingExamination.SPACE_INDICATOR = "␣"; // "ˇ"; // "ᵔ"; // "ᵕ"; // "ˣ"; // "ᵛ"; // " · ";
TypingExamination.ENTER_INDICATOR = "⏎"; // "↵"; // "↵";