|
|
|
@@ -0,0 +1,413 @@
|
|
|
|
|
/////////////////////////////
|
|
|
|
|
// TypingPractice
|
|
|
|
|
|
|
|
|
|
class TypingPractice {
|
|
|
|
|
|
|
|
|
|
create() {
|
|
|
|
|
self = this;
|
|
|
|
|
|
|
|
|
|
this.initTypingData();
|
|
|
|
|
sessionStorageManager.isNewBestRecrd = false;
|
|
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#4d4d4d';
|
|
|
|
|
|
|
|
|
|
// top
|
|
|
|
|
let backButton = new BackButton( () => {
|
|
|
|
|
sessionStorageManager.resetPlayingAppData();
|
|
|
|
|
|
|
|
|
|
location.href = '../../web/client/menu_typing_practice.html';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.contentProgressText = new ContentProgress();
|
|
|
|
|
|
|
|
|
|
let fullscreenButton = new FullscreenButton(game);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// typing content
|
|
|
|
|
var typingAreaPositionY = 260;
|
|
|
|
|
var bar = game.add.graphics();
|
|
|
|
|
bar.beginFill(0x000000, 0.2);
|
|
|
|
|
bar.drawRect(0, typingAreaPositionY, GAME_SCREEN_SIZE.x, 120);
|
|
|
|
|
|
|
|
|
|
if(isTypingWordStage())
|
|
|
|
|
textStyleBasic.font = "bold 84px Arial";
|
|
|
|
|
else // Sentence stage
|
|
|
|
|
textStyleBasic.font = "bold 48px Arial";
|
|
|
|
|
|
|
|
|
|
this.textTypingContent = game.add.text(0, 2, "test", textStyleBasic)
|
|
|
|
|
.setTextBounds(0, typingAreaPositionY, GAME_SCREEN_SIZE.x, 120)
|
|
|
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
|
|
|
|
.addColor(TypingPractice.COLOR_CONTENT_WRONG, 0);
|
|
|
|
|
|
|
|
|
|
textStyleBasic.font = "32px Arial";
|
|
|
|
|
|
|
|
|
|
var textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
|
|
|
|
|
this.textTypingContentsDone = [];
|
|
|
|
|
this.textTypingRecordsDone = [];
|
|
|
|
|
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
|
|
|
|
this.textTypingContentsDone[i] = game.add.text(0, 2, "test", textStyleBasic)
|
|
|
|
|
.setTextBounds(0, typingAreaPositionY - 50 - i * 50, GAME_SCREEN_SIZE.x, 40)
|
|
|
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
|
|
|
|
.addColor(textDoneColor[i], 0);
|
|
|
|
|
|
|
|
|
|
var scorePositionX = 780;
|
|
|
|
|
if(isTypingWordStage())
|
|
|
|
|
scorePositionX = 600;
|
|
|
|
|
|
|
|
|
|
this.textTypingRecordsDone[i] = game.add.text(0, 2, "", textStyleBasic)
|
|
|
|
|
.setTextBounds(scorePositionX, typingAreaPositionY - 50 - i * 50, 200, 40)
|
|
|
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
|
|
|
|
.addColor(textDoneColor[i], 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var textPreviewColor = [ '#999999', '#888888', '#777777' ];
|
|
|
|
|
this.textTypingContentPreview = [];
|
|
|
|
|
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
|
|
|
|
this.textTypingContentPreview[i] = game.add.text(0, 2, "test", textStyleBasic)
|
|
|
|
|
.setTextBounds(0, typingAreaPositionY + 130 + i * 50, GAME_SCREEN_SIZE.x, 40)
|
|
|
|
|
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
|
|
|
|
.addColor(textPreviewColor[i], 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// input text
|
|
|
|
|
this.inputTextContent = new InputTypeText(game.world.centerX, typingAreaPositionY + 360);
|
|
|
|
|
this.inputTextContent.anchor.set(0.5);
|
|
|
|
|
this.inputTextContent.canvasInput.value('');
|
|
|
|
|
this.inputTextContent.canvasInput.focus();
|
|
|
|
|
// inputTextContent.canvasInput._onkeydown = this.checkInputText;
|
|
|
|
|
// inputTextContent.canvasInput._onkeyup = function() {
|
|
|
|
|
this.inputTextContent.canvasInput._onkeyup = function() {
|
|
|
|
|
self.checkTypingContents(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bottom
|
|
|
|
|
let screenBottom = new ScreenBottom();
|
|
|
|
|
screenBottom.makeBottomLine();
|
|
|
|
|
// screenBottom.printBottomLeftText("");
|
|
|
|
|
screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName);
|
|
|
|
|
screenBottom.printBottomRightText(sessionStorageManager.playerName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.startGame();
|
|
|
|
|
// this.countDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
countDown() {
|
|
|
|
|
const style = { font: "bold 200px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" };
|
|
|
|
|
this.countDownText = game.add.text(0, 0, "", style);
|
|
|
|
|
this.countDownText.setTextBounds(0, 0, game.world.width, game.world.height);
|
|
|
|
|
this.countDownText.stroke = "#333";
|
|
|
|
|
this.countDownText.strokeThickness = 50;
|
|
|
|
|
|
|
|
|
|
this.countDownNumber = 3;
|
|
|
|
|
if(isDebugMode())
|
|
|
|
|
this.countDownNumber = 1;
|
|
|
|
|
this.tweenCountDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tweenCountDown() {
|
|
|
|
|
if(this.countDownNumber === 0) {
|
|
|
|
|
this.startGame();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.countDownText.text = this.countDownNumber.toString();
|
|
|
|
|
this.countDownText.alpha = 1;
|
|
|
|
|
|
|
|
|
|
let countDownTween = game.add.tween(this.countDownText);
|
|
|
|
|
countDownTween.to( { alpha: 0 }, GAME_SCREEN_SIZE.x, Phaser.Easing.Linear.None, true);
|
|
|
|
|
countDownTween.onComplete.add(this.tweenCountDown, this);
|
|
|
|
|
|
|
|
|
|
this.countDownNumber--;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
startGame() {
|
|
|
|
|
this.showTypingPracticeContents();
|
|
|
|
|
this.showPlayingWordNumber();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameOver() {
|
|
|
|
|
let gameOverText = new GameOverText();
|
|
|
|
|
|
|
|
|
|
game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goResult() {
|
|
|
|
|
sessionStorageManager.record = this.typingRecordTotal;
|
|
|
|
|
if(sessionStorageManager.record > sessionStorageManager.bestRecord)
|
|
|
|
|
sessionStorageManager.bestRecord = sessionStorageManager.record;
|
|
|
|
|
|
|
|
|
|
location.href = '../../web/client/result.html';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initTypingData() {
|
|
|
|
|
this.typingContents = this.getTypingPracticeContents();
|
|
|
|
|
var randomContents = Phaser.ArrayUtils.shuffle(this.typingContents);
|
|
|
|
|
this.wordCountForStage = TypingPractice.WORD_COUNT_FOR_STAGE;
|
|
|
|
|
if(isDebugMode())
|
|
|
|
|
this.wordCountForStage = 3;
|
|
|
|
|
this.typingRandomContents = randomContents.slice(1, this.wordCountForStage + 1); // start Num, end Num (not index)
|
|
|
|
|
this.typingContentLength = this.typingContents.length;
|
|
|
|
|
this.typingIndex = 0;
|
|
|
|
|
|
|
|
|
|
this.isTyping = false;
|
|
|
|
|
this.timeTypingStart = 0;
|
|
|
|
|
this.timeTypingEnd = 0;
|
|
|
|
|
|
|
|
|
|
this.typingLetterCountTotal = 0;
|
|
|
|
|
this.typingRecordTotal = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTypingPracticeContents() {
|
|
|
|
|
var TypingPracticeContents = this.loadTestContent();
|
|
|
|
|
// console.log('playingStageData.language : ' + playingStageData.language);
|
|
|
|
|
// console.log('playingStageData.level : ' + playingStageData.level);
|
|
|
|
|
// console.log('TypingPracticeContents : ' + TypingPracticeContents);
|
|
|
|
|
|
|
|
|
|
this.typingRecordForLines = [];
|
|
|
|
|
this.typingElapsedTime = [];
|
|
|
|
|
for(var i = 0; i < TypingPracticeContents.length; i++) {
|
|
|
|
|
this.typingRecordForLines[i] = 0;
|
|
|
|
|
this.typingElapsedTime[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TypingPracticeContents;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadTestContent() {
|
|
|
|
|
let appName = "";
|
|
|
|
|
if(isTypingTestStage())
|
|
|
|
|
appName = sessionStorageManager.playingAppName.substring(5);
|
|
|
|
|
else if(isTypingPracticeStage())
|
|
|
|
|
appName = sessionStorageManager.playingAppName.substring(9);
|
|
|
|
|
|
|
|
|
|
var testContent = [];
|
|
|
|
|
switch(appName) {
|
|
|
|
|
case "korean_basic":
|
|
|
|
|
testContent = koreanBasicWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_left_upper":
|
|
|
|
|
testContent = koreanLeftUpperWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_second_finger":
|
|
|
|
|
testContent = koreanSecondFingerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_right_upper":
|
|
|
|
|
testContent = koreanRightUpperWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_left_lower":
|
|
|
|
|
testContent = koreanLeftLowerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_right_lower":
|
|
|
|
|
testContent = koreanRightLowerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_left_upper_double":
|
|
|
|
|
testContent = koreanLeftUpperDoubleWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_right_upper_double":
|
|
|
|
|
testContent = koreanRightUpperDoubleWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_word":
|
|
|
|
|
testContent = koreanWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "korean_sentence":
|
|
|
|
|
testContent = koreanSentenceList;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "english_basic":
|
|
|
|
|
testContent = englishBasicWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_left_upper":
|
|
|
|
|
testContent = englishLeftUpperWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_second_finger":
|
|
|
|
|
testContent = englishSecondFingerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_right_upper":
|
|
|
|
|
testContent = englishRightUpperWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_left_lower":
|
|
|
|
|
testContent = englishLeftLowerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_right_lower":
|
|
|
|
|
testContent = englishRightLowerWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_word":
|
|
|
|
|
testContent = englishWordList;
|
|
|
|
|
break;
|
|
|
|
|
case "english_sentence":
|
|
|
|
|
testContent = englishSentenceList;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return testContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showTypingPracticeContents() {
|
|
|
|
|
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
|
|
|
|
|
var doneIndex = this.typingIndex - i - 1;
|
|
|
|
|
if(doneIndex < 0) {
|
|
|
|
|
this.textTypingContentsDone[i].text = "";
|
|
|
|
|
this.textTypingRecordsDone[i].text = "";
|
|
|
|
|
} else {
|
|
|
|
|
this.textTypingContentsDone[i].text = this.typingRandomContents[doneIndex];
|
|
|
|
|
this.textTypingRecordsDone[i].text = Math.floor(this.typingRecordForLines[doneIndex]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.typingIndex == this.wordCountForStage) {
|
|
|
|
|
this.textTypingContent.text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.textTypingContent.text = this.typingRandomContents[this.typingIndex];
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
|
|
|
|
|
var previewIndex = this.typingIndex + i + 1;
|
|
|
|
|
if(previewIndex < this.typingRandomContents.length)
|
|
|
|
|
this.textTypingContentPreview[i].text = this.typingRandomContents[previewIndex];
|
|
|
|
|
else
|
|
|
|
|
this.textTypingContentPreview[i].text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetTypingContent() {
|
|
|
|
|
this.textTypingContent.clearColors();
|
|
|
|
|
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_WRONG, 0);
|
|
|
|
|
this.inputTextContent.canvasInput.value('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkTypingContents(evnet) {
|
|
|
|
|
if(event.keyCode == Phaser.Keyboard.ENTER) {
|
|
|
|
|
// console.log("### enter ###");
|
|
|
|
|
var inputContent = this.inputTextContent.canvasInput.value();
|
|
|
|
|
var typingContent = this.typingRandomContents[this.typingIndex];
|
|
|
|
|
|
|
|
|
|
if(inputContent == typingContent) {
|
|
|
|
|
this.calculateTypingRecord(typingContent);
|
|
|
|
|
this.playNextContent();
|
|
|
|
|
|
|
|
|
|
if(this.typingIndex == this.wordCountForStage)
|
|
|
|
|
this.goResult();
|
|
|
|
|
// this.state.start('TypingPracticeResult');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// console.log(this.inputTextContent.canvasInput.value());
|
|
|
|
|
if(this.isTyping == false) {
|
|
|
|
|
// console.log(event);
|
|
|
|
|
this.setTimeTypingStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.showTypingContentHighlight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showTypingContentHighlight() {
|
|
|
|
|
var typingContent = this.typingRandomContents[this.typingIndex];
|
|
|
|
|
var inputContent = this.inputTextContent.canvasInput.value();
|
|
|
|
|
|
|
|
|
|
this.textTypingContent.clearColors();
|
|
|
|
|
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
|
|
|
|
|
|
|
|
|
|
if(typingContent == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var typingContentLength = typingContent.length;
|
|
|
|
|
for(var i = 0; i < typingContentLength; i++) {
|
|
|
|
|
// console.log("typingContent.charAt(i) : " + typingContent.charAt(i));
|
|
|
|
|
// console.log("inputContent.charAt(i) : " + inputContent.charAt(i));
|
|
|
|
|
|
|
|
|
|
if(typingContent.charAt(i) != inputContent.charAt(i)) {
|
|
|
|
|
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_WRONG, i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateTypingRecord(typingContent) {
|
|
|
|
|
// console.log('입력 단어 : ' + this.typingRandomContents[this.typingIndex]);
|
|
|
|
|
|
|
|
|
|
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 typingContentPlusEnterCount = typingContentLength + TypingPractice.TYPING_COUNT_PLUS_ENTER;
|
|
|
|
|
|
|
|
|
|
var typingRecord = (typingContentPlusEnterCount + TypingPractice.TYPING_COUNT_PLUS_ENTER) * 60000 / elapsedTimeMS;
|
|
|
|
|
|
|
|
|
|
this.typingElapsedTime[this.typingIndex] = elapsedTimeMS;
|
|
|
|
|
this.typingLetterCountTotal += typingContentPlusEnterCount;
|
|
|
|
|
this.typingRecordForLines[this.typingIndex] = typingRecord;
|
|
|
|
|
// console.log(this.typingRecordForLines[this.typingIndex]);
|
|
|
|
|
|
|
|
|
|
var typingElapsedTimeTotal = 0;
|
|
|
|
|
for(let i = 0; i <= this.typingIndex; i++) {
|
|
|
|
|
// console.log('i : ' + i + ' - time : ' + this.typingElapsedTime[i]);
|
|
|
|
|
typingElapsedTimeTotal += this.typingElapsedTime[i];
|
|
|
|
|
}
|
|
|
|
|
this.typingRecordTotal = this.typingLetterCountTotal * 60000 / typingElapsedTimeTotal;
|
|
|
|
|
// console.log(this.typingLetterCountTotal);
|
|
|
|
|
// console.log(typingElapsedTimeTotal);
|
|
|
|
|
// console.log(typingRecordTotal);
|
|
|
|
|
|
|
|
|
|
// console.log('-------------- total --------------');
|
|
|
|
|
// console.log('typingLetterCountTotal : ' + this.typingLetterCountTotal);
|
|
|
|
|
// console.log('typingElapsedTimeTotal : ' + typingElapsedTimeTotal);
|
|
|
|
|
// console.log('typingRecordTotal : ' + typingRecordTotal);
|
|
|
|
|
// console.log('-----------------------------------');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playNextContent() {
|
|
|
|
|
this.typingIndex++;
|
|
|
|
|
this.showTypingPracticeContents();
|
|
|
|
|
this.showPlayingWordNumber();
|
|
|
|
|
this.resetTypingContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showPlayingWordNumber() {
|
|
|
|
|
this.contentProgressText.print(this.typingIndex + 1, this.wordCountForStage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeTypingStart() {
|
|
|
|
|
this.timeTypingStart = game.time.elapsedSince(0);
|
|
|
|
|
var timeGap = this.timeTypingStart - this.timeTypingEnd;
|
|
|
|
|
|
|
|
|
|
if(timeGap < 50)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.isTyping = true;
|
|
|
|
|
// console.log('last End : ' + this.timeTypingEnd);
|
|
|
|
|
// console.log('this.timeTypingStart : ' + this.timeTypingStart);
|
|
|
|
|
|
|
|
|
|
// console.log('time gap : ' + (this.timeTypingStart - this.timeTypingEnd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TypingPractice.TYPING_CONTENT_PREVIEW_COUNT = 3;
|
|
|
|
|
TypingPractice.TYPING_CONTENT_DONE_COUNT = 3;
|
|
|
|
|
TypingPractice.TYPING_COUNT_PLUS_ENTER = 1;
|
|
|
|
|
|
|
|
|
|
TypingPractice.OFFSET_RIGHT_ALIGN = 10;
|
|
|
|
|
|
|
|
|
|
TypingPractice.WORD_COUNT_FOR_STAGE = 10;
|
|
|
|
|
// if(isDebugMode())
|
|
|
|
|
// WORD_COUNT_FOR_STAGE = 3;
|
|
|
|
|
|
|
|
|
|
TypingPractice.COLOR_CONTENT_WRONG = "#aaaaaa";
|
|
|
|
|
TypingPractice.COLOR_CONTENT_RIGHT = "#ffff4d";
|
|
|
|
|
|
|
|
|
|
|