diff --git a/src/game/typing/examination/average_typing_speed.js b/src/game/typing/examination/average_typing_speed.js new file mode 100644 index 0000000..7a5ee95 --- /dev/null +++ b/src/game/typing/examination/average_typing_speed.js @@ -0,0 +1,38 @@ +function AverageTypingSpeed() { + var fontStyle = AverageTypingSpeed.DEFAULT_TEXT_FONT; + + fontStyle.align = "right"; + fontStyle.boundsAlignH = "right"; + this.tytleSpeedText = game.add.text(game.world.width / 2 + 20, AverageTypingSpeed.FONT_HEIGHT_PX, "현재 타수 : ", fontStyle); + this.tytleSpeedText.anchor.set(1, 0.5); + + fontStyle.align = "left"; + fontStyle.boundsAlignH = "left"; + this.typingSpeedText = game.add.text(game.world.width / 2 + 20, AverageTypingSpeed.FONT_HEIGHT_PX, "0", fontStyle); + this.typingSpeedText.anchor.set(0, 0.5); + + // var grd = this.label.context.createLinearGradient(0, 0, 0, AverageTypingSpeed.FONT_HEIGHT_PX); + // grd.addColorStop(0, '#8ED6FF'); + // grd.addColorStop(1, '#004CB3'); + // this.label.fill = grd; + // this.scoreText.fill = grd; + + // this.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + // this.label.stroke = '#000'; + // this.label.strokeThickness = 3; +}; + +AverageTypingSpeed.prototype.print = function(typingSpeed) { + this.typingSpeedText.text = typingSpeed; +} + + +AverageTypingSpeed.FONT_HEIGHT_PX = 30; + +AverageTypingSpeed.DEFAULT_TEXT_FONT = { + font: "38px Arial", + align: "center", + boundsAlignH: "center", // left, center. right + boundsAlignV: "middle", // top, middle, bottom + fill: "#fff" +}; \ No newline at end of file diff --git a/src/game/typing/examination/define_variables.js b/src/game/typing/examination/define_variables.js new file mode 100644 index 0000000..e69de29 diff --git a/src/game/typing/examination/game.js b/src/game/typing/examination/game.js new file mode 100644 index 0000000..11d63b9 --- /dev/null +++ b/src/game/typing/examination/game.js @@ -0,0 +1,821 @@ +var TypingExamination = { + + create: function() { + + // for developing + sessionStorageManager.setMaestroName("삼화초"); + sessionStorageManager.setMaestroID(3); + sessionStorageManager.setMaestroAccountType(4); + sessionStorageManager.setPlayerName("박지상"); + sessionStorageManager.setPlayerID(35); + sessionStorageManager.setPlayerAccountType(0); + sessionStorageManager.setPlayingAppID(100); + sessionStorageManager.setPlayingAppName("examination_korean"); + sessionStorageManager.setPlayingAppKoreanName("타자 검정"); + sessionStorageManager.setRecord(0); + sessionStorageManager.setAppHighestRecord(100.123); + + + + this.dbConnectManager = new DBConnectManager(); + sessionStorageManager.setRecord(0); + + var self = this; + + this.initTypingData(); + sessionStorageManager.setIsNewAppHighestRecord(false); + + var experienceAppTimer = new ExperienceAppTimer(); + experienceAppTimer.setTimeOverListener( + (function() { this.timeOver(); }).bind(this) + ); + + game.stage.backgroundColor = '#4d4d4d'; + + /* + // keyboard shortcut - useless. this.keyboard is chargning for ESC event + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "keyboard_test" // callerClassName + ); + */ + + // top ui + var screenTopUI = new ScreenTopUI(); + screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) ); + screenTopUI.makeFullScreenButton(); + + + this.averageTypingSpeedText = new AverageTypingSpeed(); + this.contentProgressText = new ContentProgress(); + + + // typing content + var typingContentBG = new TypingContentBG(); + typingContentBG.makeExaminationContentBG(); + + this.animalList = new AnimalList(670); + + + var TYPING_CONTENT_X = 100; + var TYPING_CONTENT_Y = 340; + + textStyleBasic.font = "bold 52px Arial"; + + this.textTypingContent = game.add.text( + TYPING_CONTENT_X, TYPING_CONTENT_Y, + "", textStyleBasic + ) + .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) + .addColor(TypingExamination.COLOR_CONTENT_INPUT, 0); + this.textTypingContent.anchor.set(0, 0.5); + + var TYPING_OFFSET_Y = 100; + var TYPING_PREVIEW_OFFSET_Y = 40; + var TYPING_TEXT_OFFSET_HEIGHT = 70; + textStyleBasic.font = "52px Arial"; + + var textDoneColor = [ '#99994d', '#77774d', '#66664d' ]; + this.textTypingContentsDone = []; + this.textTypingRecordsDone = []; + for(var i = 0; i < TypingExamination.TYPING_CONTENT_DONE_COUNT; i++) { + this.textTypingContentsDone[i] = game.add.text( + TYPING_CONTENT_X, TYPING_CONTENT_Y - TYPING_OFFSET_Y - i * TYPING_TEXT_OFFSET_HEIGHT, + "", textStyleBasic + ) + // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) + .addColor(textDoneColor[i], 0); + this.textTypingContentsDone[i].anchor.set(0, 0.5); + + var SCORE_POSITION_X = 900; + + this.textTypingRecordsDone[i] = game.add.text( + SCORE_POSITION_X, TYPING_CONTENT_Y - TYPING_OFFSET_Y - i * TYPING_TEXT_OFFSET_HEIGHT, + "", textStyleBasic + ) + // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) + .addColor(textDoneColor[i], 0); + this.textTypingRecordsDone[i].anchor.set(0.5); + } + + var textPreviewColor = [ '#999999', '#888888', '#777777' ]; + this.textTypingContentPreview = []; + for(var i = 0; i < TypingExamination.TYPING_CONTENT_PREVIEW_COUNT; i++) { + this.textTypingContentPreview[i] = game.add.text( + TYPING_CONTENT_X, + TYPING_CONTENT_Y + TYPING_OFFSET_Y + TYPING_PREVIEW_OFFSET_Y + i * TYPING_TEXT_OFFSET_HEIGHT, + "", textStyleBasic + ) + // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) + .addColor(textPreviewColor[i], 0); + this.textTypingContentPreview[i].anchor.set(0, 0.5); + } + + + // input text + this.inputTextContent = new InputTypeText(TYPING_CONTENT_X, TYPING_CONTENT_Y + 70); + this.inputTextContent.anchor.set(0, 0.5); + this.inputTextContent.canvasInput.value(''); + this.inputTextContent.canvasInput.focus(); + this.inputTextContent.canvasInput.fontSize(52); + this.inputTextContent.canvasInput.placeHolder("입력 후 Space, Enter키를 누르세요"); + // inputTextContent.canvasInput._onkeydown = this.checkInputText; + // inputTextContent.canvasInput._onkeyup = function() { + this.inputTextContent.canvasInput._onkeyup = function() { + self.checkTypingContents(event); + // warning + // : checkTypingContents is called onkeyup and onkeydown + } + + + /* + // keyboard + this.keyMapper = new KeyMapper(); + this.keyboard = null; + if(sessionStorageManager.getPlayingAppName().indexOf("korean") > 0) + this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN, Keyboard.NO_OFFSET_POS_Y); + else + this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH, Keyboard.NO_OFFSET_POS_Y); + this.keyboard.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "keyboard_test" // callerClassName + ); + + // hands + this.leftHand = new LeftHand(this.keyMapper); + this.rightHand = new RightHand(this.keyMapper); + */ + + + + // bottom ui + var screenBottomUI = new ScreenBottomUI(); + screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord()); + screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); + screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); + + + this.startGame(); + // this.countDown(); + }, + + /* + countDown() { + var 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; + + var 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--; + } + */ + + + back: function() { + sessionStorageManager.resetPlayingAppData(); + location.href = '../../web/client/menu_typing_test.html'; + }, + + startGame: function() { + this.averageTypingSpeedText.print(0); + + this.showTypingExaminationContents(); + this.showPlayingWordNumber(); + // this.updateKeyboard(); + }, + + timeOver: function() { + var timeOverText = new TimeOverText(); + this.stopAndGoResult(); + }, + + gameOver: function() { + var missionClearText = new MissionClearText(); + this.stopAndGoResult(); + }, + + stopAndGoResult: function() { + this.animalList.stopAnimation(); + + sessionStorageManager.setRecord(this.typingRecordTotal); + if(!isExperienceMaestroAccount()) + this.updateResultRecord(); + + game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this); + }, + + updateResultRecord: function() { + if(sessionStorageManager.getMaestroAccountType() < 100) { // experience account + this.dbConnectManager.updateResultRecord( + sessionStorageManager.getMaestroID(), + sessionStorageManager.getPlayerID(), + sessionStorageManager.getPlayingAppID(), + sessionStorageManager.getRecord() + ); + } + }, + + goResult: function() { + location.href = '../../web/client/result.html'; + }, + + + initTypingData: function() { + var typingTextMan = new TypingTextManager(); + + var typingPracticeContents = this.getTypingExaminationContents(); + // var typingPracticeContents = [ "십년이면 강산도 변한다." , "십년이면 강산도 변한다.", "십년이면 강산도 변한다." ]; // for debug + // var typingPracticeContents = [ "꿰뚫다" , "워머신", "홧김에" ]; // for debug + console.log(typingPracticeContents); + typingTextMan.makeExaminationContents(typingPracticeContents); + // var wordCountForStage = TypingExamination.WORD_COUNT_FOR_STAGE; + // if(isDebugMode()) + // wordCountForStage = 3; + // typingTextMan.slice(0, wordCountForStage); + this.typingRandomContents = typingTextMan.getContents(); + // console.log(this.typingRandomContents); + this.typingContentLength = this.typingRandomContents.length; + this.typingIndex = 0; + + + this.isGameOver = false; + this.isTyping = false; + this.timeTypingStart = 0; + this.timeTypingEnd = 0; + + this.typingLetterCountTotal = 0; + this.typingRecordTotal = 0; + }, + + + getTypingExaminationContents: function() { + var TypingExaminationContents = this.loadTestContent(); + // console.log('playingStageData.language : ' + playingStageData.language); + // console.log('playingStageData.level : ' + playingStageData.level); + // console.log('TypingExaminationContents : ' + TypingExaminationContents); + + this.typingRecordForLines = []; + this.typingElapsedTime = []; + for(var i = 0; i < TypingExaminationContents.length; i++) { + this.typingRecordForLines[i] = 0; + this.typingElapsedTime[i] = 0; + } + + return TypingExaminationContents; + }, + + loadTestContent: function() { + // game.load.text("literature", "./../literature_list/korean_national_anthem.txt"); + + var literature = game.cache.getText("literature"); + var testContent = literature.split("\n"); + + for(var i = 0; i < testContent.length; i++) { + testContent[i] = testContent[i].replace(/\r/g, ""); + console.log("typingContent : [" + testContent[i] + "], length : " + testContent[i].length); + testContent[i] = testContent[i].replace("\n", ""); + // var char = testContent[i]; + // for(var j = 0; j < char.length; j++) { + // console.log("[" + j + "] : " + char[j].charCodeAt(0).toString(16)); + // } + } + + return testContent; + }, + + showTypingExaminationContents: function() { + for(var i = 0; i < TypingExamination.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.typingContentLength) { + this.textTypingContent.text = ""; + return; + } + + this.textTypingContent.text = this.typingRandomContents[this.typingIndex]; + + for(var i = 0; i < TypingExamination.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: function() { + this.textTypingContent.clearColors(); + this.textTypingContent.addColor(TypingExamination.COLOR_CONTENT_INPUT, 0); + this.inputTextContent.canvasInput.value(''); + }, + + checkTypingContents: function(event) { + if(this.isGameOver) + return; + + var inputContent = this.inputTextContent.canvasInput.value().trim(); + var typingContent = this.typingRandomContents[this.typingIndex]; + + if(event.keyCode == Phaser.Keyboard.ENTER || + event.keyCode == Phaser.Keyboard.SPACEBAR) { + console.log("### enter ###"); + console.log("this.typingIndex : " + this.typingIndex); + console.log("inputContent : [" + inputContent + "], length : " + inputContent.length); + console.log("typingContent : [" + typingContent + "], length : " + typingContent.length); + + if(inputContent === typingContent) { + console.log("input completed"); + this.calculateTypingRecord(typingContent); + + console.log("this.typingIndex : " + this.typingIndex); + console.log("this.typingContentLength : " + this.typingContentLength); + if(this.typingIndex == this.typingContentLength - 1) { + this.isGameOver = true; + this.gameOver(); + return; + } + + this.playNextContent(); + return; + } + } + + if(this.isTyping == false) { + // console.log(event); + this.setTimeTypingStart(); + } + + this.showTypingContentHighlight(inputContent, typingContent); + // this.updateKeyboard(); + }, + + showTypingContentHighlight: function(inputContent, typingContent) { + this.textTypingContent.clearColors(); + this.textTypingContent.addColor(TypingExamination.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(TypingExamination.COLOR_CONTENT_INPUT, i); + return; + } + } + }, + + /* + updateKeyboard: function() { + var inputContent = this.inputTextContent.canvasInput.value(); + var typingContent = this.typingRandomContents[this.typingIndex]; + + this.hideHighlightKey(this.highlightKey); + this.highlightKey = this.getHighlioghtKey(inputContent, typingContent); + // console.log(this.highlightKey); + this.showHighlightKey(this.highlightKey); + this.moveHands(this.highlightKey); + }, + */ + + getHighlioghtKey: function(inputContent, typingContent) { + if(typingContent == undefined) + return undefined; + + var highlightKey = ""; + var inputIndex = inputContent.length - 1; + var inputLength = inputContent.length; + var typingLength = typingContent.length; + // console.log("inputLength : " + inputLength + " / " + inputContent); + // console.log("typingLength : " + typingLength + " / " + typingContent); + var misspelledIndex = -1; + for(var i = 0; i < typingLength; i++) { + // console.log("inputContent[i] : " + inputContent[i] + ", typingContent[i] : " + typingContent[i]); + if(inputContent[i] != typingContent[i]) { + misspelledIndex = i; + break; + } + } + + // over typing + if(inputLength > typingLength) { + highlightKey = "Backspace"; + } + + // complete typing + else if(inputContent == typingContent) { + highlightKey = "Enter"; + } + + // english typing test + else if(isEnglishTypingApp()) { + // console.log("===== english"); + // console.log("misspelledIndex : " + misspelledIndex); + // console.log("inputIndex : " + inputIndex); + if(misspelledIndex > inputIndex) + highlightKey = typingContent[misspelledIndex]; + else + highlightKey = "Backspace"; + } + // korean typing test + else { + // console.log(misspelledIndex + " / " + typingContent[misspelledIndex]); + if(typingContent[misspelledIndex] == " ") + highlightKey = " "; + else { + var inputLetter = ""; + var typingLetter = ""; + var typingNextLetter = ""; + + // console.log("-----"); + // console.log("inputConent : '" + inputContent + "'"); + // console.log("inputIndex : " + inputIndex); + // console.log("typingLength : " + typingLength); + // console.log("misspelledIndex : " + misspelledIndex); + + if(inputIndex < 0) + inputLetter = ""; + else if(misspelledIndex > inputIndex) + inputLetter = ""; + else + inputLetter = inputContent[misspelledIndex]; + typingLetter = typingContent[misspelledIndex]; + if(misspelledIndex <= typingContent.length) + typingNextLetter = typingContent[misspelledIndex + 1]; + + // console.log("inputLetter : '" + inputLetter + "'"); + // console.log("typingLetter : '" + typingLetter + "'"); + // console.log("typingNextLetter : '" + typingNextLetter + "'"); + + // var typingAlphabet = ""; + var inputLetterAlphabets = StringUtil.toKoreanAlphabets(inputLetter); + // var typingLetterAlphabets = StringUtil.toKoreanAlphabets(typingLetter); + // var typingNextLetterAlphabets = StringUtil.toKoreanAlphabets(typingNextLetter); + // console.log("inputLetterAlphabets : " + inputLetterAlphabets); + // console.log("typingLetterAlphabets : " + typingLetterAlphabets); + // console.log("typingNextLetterAlphabets : " + typingNextLetterAlphabets); + + if(misspelledIndex < inputIndex) { + highlightKey = "Backspace"; + } + + // typing nothing yet + else if(inputLetterAlphabets.length == 0) { + // highlightKey = typingLetterAlphabets[0]; + highlightKey = StringUtil.chosung(typingLetter); + } + + // after typing chosung + else if(inputLetterAlphabets.length == 1) { + if(StringUtil.chosung(inputLetter) != StringUtil.chosung(typingLetter)) + highlightKey = "Backspace"; + else { + if(StringUtil.isMultiAlphabetJungsung(StringUtil.jungsung(typingLetter))) { + // console.log("* multi jungsung"); + var jungsungLetter = StringUtil.jungsung(typingLetter); + // console.log("jungsungLetter : " + jungsungLetter); + jungsungAlphabets = StringUtil.getMultiAlphabetFromJungsung(jungsungLetter); + // console.log("jungsungAlphabets : " + jungsungAlphabets); + highlightKey = jungsungAlphabets[0]; + // console.log(highlightKey); + } else { + // console.log("* single jungsung"); + highlightKey = StringUtil.jungsung(typingLetter); + // console.log(highlightKey); + } + } + } + + // after typing jungsung + else if(inputLetterAlphabets.length == 2) { + var typingLetterJungsung = StringUtil.jungsung(typingLetter); + // console.log("* 222"); + // inputLetter jungsung == typingLetter jungsung + + // inputLetter chosung != typingLetter chosung + if(StringUtil.chosung(inputLetter) != StringUtil.chosung(typingLetter)) + highlightKey = "Backspace"; + + else if(StringUtil.jungsung(inputLetter) == StringUtil.jungsung(typingLetter)) { + if(StringUtil.hasJongsung(typingLetter)) { + // highlightKey = StringUtil.jongsung(typingLetter); + var typingLetterJongsung = StringUtil.jongsung(typingLetter); + // typingLetter jongsung is multi alphabet + if(StringUtil.isMultiAlphabetJongsung(typingLetterJongsung)) { + var typingJongsungAlphabets = StringUtil.getMultiAlphabetFromJongsung(StringUtil.jongsung(typingLetter)); + highlightKey = typingJongsungAlphabets[0]; + } + // typingLetter jongsung is single alphabet + else { + highlightKey = typingLetterJongsung; + } + } else + highlightKey = StringUtil.chosung(typingNextLetter); + } + // inputLetter jungsung != typingLetter jungsung + else { + if(StringUtil.isMultiAlphabetJungsung(typingLetterJungsung)) { + // console.log("* multi jungsung"); + var jungsungAlphabets = StringUtil.getMultiAlphabetFromJungsung(typingLetterJungsung); + // console.log(" * jungsungAlphabets : " + jungsungAlphabets); + if(StringUtil.jungsung(inputLetter) == jungsungAlphabets[0]) + highlightKey = jungsungAlphabets[1]; + else + highlightKey = "Backspace"; + } + // single letter jungsung + else { + // console.log("* single jungsung"); + if(StringUtil.jungsung(inputLetter) != typingLetterJungsung) + highlightKey = "Backspace"; + else { + if(StringUtil.hasJongsung(typingLetter)) { + // highlightKey = StringUtil.jongsung(typingLetter); + var typingLetterJongsung = StringUtil.jongsung(typingLetter); + if(StringUtil.isMultiAlphabetJongsung(typingLetterJongsung)) { + var jongsungAlphabets = StringUtil.getMultiAlphabetFromJongsung(StringUtil.jongsung(inputLetter)); + if(StringUtil.jongsung(typingLetter) == jongsungAlphabets[0] && StringUtil.chosung(typingNextLetter) == jongsungAlphabets[1]) + highlightKey = StringUtil.jungsung(typingNextLetter); + else if(StringUtil.jongsung(inputLetter) == jongsungAlphabets[0]) + highlightKey = jongsungAlphabets[1]; + else + highlightKey = "Backspace"; + } + } else + highlightKey = StringUtil.chosung(typingNextLetter); + } + } + } + } + + // after typing jongsung + else if(inputLetterAlphabets.length == 3) { + // inputLetter chosung != typingLetter chosung + if(StringUtil.chosung(inputLetter) != StringUtil.chosung(typingLetter)) + highlightKey = "Backspace"; + // inputLetter jungsung != typingLetter jungsung + else if(StringUtil.jungsung(inputLetter) != StringUtil.jungsung(typingLetter)) + highlightKey = "Backspace"; + + // 입력할 글자에 종성이 있을 경우 + else if(StringUtil.hasJongsung(typingLetter)) { + // console.log("has jongsung"); + var typingLetterJongsung = StringUtil.jongsung(typingLetter); + + // 입력한 글자의 종성과 입력할 글자의 종성이 같은 경우 + if(StringUtil.jongsung(inputLetter) == typingLetterJongsung) { + if(inputIndex == typingLength - 1) + highlightKey = "Enter"; + else + highlightKey = StringUtil.chosung(typingNextLetter); + } + // 입력한 글자의 종성이 입력할 글자와 다를 경우 + else { + if(inputIndex == typingLength - 1) + highlightKey = "Backspace"; + // 입력할 글자의 종성이 합성자음일 경우 + else if(StringUtil.isMultiAlphabetJongsung(typingLetterJongsung)) { + var inputJongsungAlphabets = StringUtil.getMultiAlphabetFromJongsung(StringUtil.jongsung(inputLetter)); + var typingJongsungAlphabets = StringUtil.getMultiAlphabetFromJongsung(StringUtil.jongsung(typingLetter)); + + // 입력할 글자의 종성과 입력한 글자의 종성이 같은 경우 + if(typingLetterJongsung == StringUtil.jongsung(inputLetter)) + highlightKey = StringUtil.chosung(typingNextLetter); + else if(StringUtil.jongsung(inputLetter) == typingJongsungAlphabets[0]) + highlightKey = typingJongsungAlphabets[1]; + else + highlightKey = "Backspace"; + } + // 입력할 글자의 종성이 단자음일 경우 : 알바 -> 앏 + else { + var inputLetterJongsung = StringUtil.jongsung(inputLetter); + // console.log("*** single jongsung"); + // console.log("inputLetter : " + inputLetter); + // console.log("StringUtil.jongsung(inputLetter) : " + StringUtil.jongsung(inputLetter)); + // console.log("inputLetterJongsung : " + inputLetterJongsung); + + if(StringUtil.isMultiAlphabetJongsung(inputLetterJongsung)) { + var inputJongsungAlphabets = StringUtil.getMultiAlphabetFromJongsung(StringUtil.jongsung(inputLetter)); + // console.log("inputJongsungAlphabets : " + inputJongsungAlphabets); + if(StringUtil.jongsung(typingLetter) == inputJongsungAlphabets[0] && StringUtil.chosung(typingNextLetter) == inputJongsungAlphabets[1]) + highlightKey = StringUtil.jungsung(typingNextLetter); + else + highlightKey = "Backspace"; + } + else { + highlightKey = StringUtil.chosung(typingNextLetter); + } + } + } + } + // 입력할 글자에 종성이 없을 경우 + else { + // console.log("inputLetter jongsung : " + StringUtil.jongsung(inputLetter)) + // console.log("typingNextLetter chosung : " + StringUtil.chosung(typingNextLetter)) + if(StringUtil.hasJongsung(inputLetter)) { + // console.log("### has jongsung"); + if(inputIndex == typingLength - 1) + highlightKey = "Backspace"; + else { + if(StringUtil.jongsung(inputLetter) == StringUtil.chosung(typingNextLetter)) { + // highlightKey = StringUtil.jungsung(typingNextLetter); + if(StringUtil.isMultiAlphabetJungsung(StringUtil.jungsung(typingNextLetter))) { + // console.log("* multi jungsung"); + jungsungAlphabets = StringUtil.getMultiAlphabetFromJungsung(StringUtil.jungsung(typingNextLetter)); + highlightKey = jungsungAlphabets[0]; + // console.log(highlightKey); + } else { + // console.log("* single jungsung"); + highlightKey = StringUtil.jungsung(typingNextLetter); + // console.log(highlightKey); + } + } + else { + highlightKey = "Backspace"; + } + } + } + else + highlightKey = "Backspace"; + } + } + } + } + + if(highlightKey == " ") + highlightKey = "Space"; + + return highlightKey; + }, + + /* + hideHighlightKey: function(highlightKey) { + // var prevText = this.typingRandomContents[this.typingIndex]; + if(highlightKey === undefined) + return; + + this.keyboard.hideHighlight(highlightKey); + }, + + showHighlightKey: function(highlightKey) { + // var typingText = this.typingRandomContents[this.typingIndex]; + if(highlightKey === undefined) + return; + + this.keyboard.showHighlight(highlightKey, this.leftHand, this.rightHand); + }, + + moveHands: function(highlightKey) { + // var typingText = this.typingRandomContents[this.typingIndex]; + if(highlightKey === undefined) + return; + + var key = this.keyboard.getKeyOfText(highlightKey); + var handSide = key.handSide; + if(handSide === KeyButton.LEFT_HAND) { + this.leftHand.moveTo(key); + + if(this.keyMapper.isShiftText(highlightKey)) { + var shiftRightKey = this.keyboard.getKey("ShiftRight"); + shiftRightKey.showHighlight(); + this.rightHand.moveTo(shiftRightKey); + } else { + this.rightHand.moveToDefaultPosition(); + } + } else { + this.rightHand.moveTo(key); + + if(this.keyMapper.isShiftText(highlightKey)) { + var shiftLeftKey = this.keyboard.getKey("ShiftLeft"); + shiftLeftKey.showHighlight(); + this.leftHand.moveTo(shiftLeftKey); + } else { + this.leftHand.moveToDefaultPosition(); + } + } + }, + */ + + calculateTypingRecord: function(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 + TypingExamination.TYPING_COUNT_PLUS_ENTER; + + var typingRecord = (typingContentPlusEnterCount + TypingExamination.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(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; + // 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_TEST); + this.animalList.activate(animalLevelID); + this.animalList.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); + }, + + playNextContent: function() { + this.typingIndex++; + this.showTypingExaminationContents(); + this.showPlayingWordNumber(); + this.resetTypingContent(); + // this.updateKeyboard(); + }, + + showPlayingWordNumber: function() { + this.contentProgressText.print(this.typingIndex + 1, this.typingContentLength); + }, + + setTimeTypingStart: function() { + if(this.inputTextContent.canvasInput.value() == "") + return; + + 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)); + } + +} + + +TypingExamination.TYPING_CONTENT_PREVIEW_COUNT = 3; // 3; +TypingExamination.TYPING_CONTENT_DONE_COUNT = 3; // 3; +TypingExamination.TYPING_COUNT_PLUS_ENTER = 1; + +TypingExamination.OFFSET_RIGHT_ALIGN = 10; + +TypingExamination.WORD_COUNT_FOR_STAGE = 10; + +TypingExamination.COLOR_CONTENT_INPUT = "#dddddd"; +TypingExamination.COLOR_CONTENT_RIGHT = "#ffff4d"; \ No newline at end of file diff --git a/src/game/typing/examination/loading.js b/src/game/typing/examination/loading.js new file mode 100644 index 0000000..1676dce --- /dev/null +++ b/src/game/typing/examination/loading.js @@ -0,0 +1,93 @@ +var Loading = { + + preload: function() { + // game.load.image('loadingbar', './image/phaser.png'); + }, + + create: function() { + // var userID = sessionStorage.getItem("UserID"); + // console.log("userID : " + userID); + + // game.stage.backgroundColor = '#4d4d4d'; + + // // Progress report + // this.textProgress = game.add.text(game.world.centerX, 100, '로딩중 . . .', textStyleBasic); + // this.textProgress.anchor.setTo(0.5, 0.4); + // this.textProgress.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + + // // Preload bar + // this.preloadBar = this.add.sprite(game.world.centerX, game.world.centerY, 'loadingbar'); + // this.preloadBar.anchor.setTo(0.5); + // this.preloadBar.alpha = 0; + + game.load.onFileComplete.add(this.fileComplete, this); + game.load.onLoadComplete.add(this.loadComplete, this); + + this.startLoading(); + }, + + startLoading: function() { + game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); + + // Hand.loadResources(); + Animal.loadResources(); + game.load.text("literature", "./../../game/typing/literature_list/korean_national_anthem.txt"); + + + // game.load.image('a', '../../../resources/image/icon/fullscreen_white.png'); + // game.load.image('b', '../../../resources/image/icon/fullscreen_white.png'); + // game.load.image('c', '../../../resources/image/icon/fullscreen_white.png'); + // game.load.image('d', '../../../resources/image/icon/fullscreen_white.png'); + // game.load.image('a', './image/phaser.png'); + // game.load.image('b', './image/phaser.png'); + // game.load.image('c', './image/phaser.png'); + // game.load.image('d', './image/phaser.png'); + // game.load.image('e', './image/phaser.png'); + // game.load.image('g', './image/phaser.png'); + // game.load.image('e', './image/phaser.png'); + // game.load.image('f', './image/phaser.png'); + // game.load.image('g', './image/phaser.png'); + // game.load.image('h', './image/phaser.png'); + + // game.load.image('phaser', './image/phaser.png'); + // game.load.spritesheet('button', './image/button_basic.png', 200, 100); + // game.load.image('star', './image/star_particle.png'); + // game.load.image('medal_gold', './image/medal_gold.png'); + // game.load.image('medal_silver', './image/medal_silver.png'); + // game.load.image('medal_bronze', './image/medal_bronze.png'); + + game.load.start(); + }, + + fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) { + // this.preloadBar.alpha = progress / 100; + + // console.log('progress : ' + progress); + + // text.setText("File Complete: " + progress + "% - " + totalLoaded + " out of " + totalFiles); + + // var newImage = game.add.image(x, y, cacheKey); + // newImage.scale.set(0.3); + + // x += newImage.width + 20; + // if (x > 700) + // { + // x = 32; + // y += 332; + // } + }, + + loadComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) { + // this.preloadBar.alpha = 1; + + if(isDebugMode()) { + this.state.start('TypingExamination'); + return; + } + + this.state.start('TypingExamination'); + // this.startMenu(); + // this.startTypingTestStage(); + // this.startTypingTestResult(); + }, +} diff --git a/src/game/typing/examination/main.js b/src/game/typing/examination/main.js new file mode 100644 index 0000000..ecd55aa --- /dev/null +++ b/src/game/typing/examination/main.js @@ -0,0 +1,16 @@ +///////////////////////////// +// Main game + +var CONTENT_ID = "Typing Examination"; + +var game = new Phaser.Game( + GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y, + Phaser.CANVAS, CONTENT_ID, + this, false, false +); + +game.state.add('Loading', Loading); +game.state.start('Loading'); + +game.state.add('TypingExamination', TypingExamination); +// game.state.add('Menu', Menu); diff --git a/src/game/typing/lib/typing_content_bg.js b/src/game/typing/lib/typing_content_bg.js index 71a8e49..21fae05 100644 --- a/src/game/typing/lib/typing_content_bg.js +++ b/src/game/typing/lib/typing_content_bg.js @@ -35,6 +35,23 @@ TypingContentBG.prototype.makeTestContentBG = function() { } } +TypingContentBG.prototype.makeExaminationContentBG = function() { + var contentY = TypingContentBG.POS_Y_CONTENT_BOX_TYPING_EXAMINATION; + + var bar = game.add.graphics(); + if(isKoreanTypingApp()) { + bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1); + bar.drawRect(0, contentY, GAME_SCREEN_SIZE.x, 70); + } else { + bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1); + bar.drawRect(0, contentY, GAME_SCREEN_SIZE.x, 20); + bar.beginFill(TypingContentBG.COLOR_CONTENT_ALPHABET_BG, 1); + bar.drawRect(0, contentY + 20, GAME_SCREEN_SIZE.x, 40); + bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1); + bar.drawRect(0, contentY + 55, GAME_SCREEN_SIZE.x, 10); + } +} + TypingContentBG.prototype.makeWhacAMoleContentBG = function() { var contentY = TypingContentBG.POS_Y_CONTENT_BOX_TYPING_WHACAMOLE; @@ -56,6 +73,7 @@ TypingContentBG.prototype.makeWhacAMoleContentBG = function() { TypingContentBG.COLOR_CONTENT_BG = 0x444444; TypingContentBG.COLOR_CONTENT_ALPHABET_BG = 0x3d3d3d; -TypingContentBG.POS_Y_CONTENT_BOX_TYPING_PRACTICE = 140; -TypingContentBG.POS_Y_CONTENT_BOX_TYPING_TEST = 195; // 260; -TypingContentBG.POS_Y_CONTENT_BOX_TYPING_WHACAMOLE = 200; +TypingContentBG.POS_Y_CONTENT_BOX_TYPING_PRACTICE = 140; +TypingContentBG.POS_Y_CONTENT_BOX_TYPING_TEST = 195; // 260; +TypingContentBG.POS_Y_CONTENT_BOX_TYPING_EXAMINATION = 300; +TypingContentBG.POS_Y_CONTENT_BOX_TYPING_WHACAMOLE = 200; diff --git a/src/game/typing/lib/typing_text_manager.js b/src/game/typing/lib/typing_text_manager.js index f97b789..7f2c1ed 100644 --- a/src/game/typing/lib/typing_text_manager.js +++ b/src/game/typing/lib/typing_text_manager.js @@ -98,6 +98,12 @@ TypingTextManager.prototype.makeTestContents = function(arr) { this.add(this.getShuffledArray(arr)); } +TypingTextManager.prototype.makeExaminationContents = function(arr) { + this.init(); + // getExaminationArray : slice too long sentence by proper words and last space + this.add(arr); +} + TypingTextManager.shuffledArray = function(arr) { diff --git a/src/game/typing/literature_list/korean_national_anthem.txt b/src/game/typing/literature_list/korean_national_anthem.txt new file mode 100644 index 0000000..57a5eea --- /dev/null +++ b/src/game/typing/literature_list/korean_national_anthem.txt @@ -0,0 +1,16 @@ +애국가 +1절 +동해 물과 백두산이 마르고 닳도록 +하느님이 보우하사 우리나라 만세 +2절 +남산 위에 저 소나무 철갑을 두른 듯 +바람서리 불변함은 우리 기상일세 +3절 +가을 하늘 공활한데 높고 구름 없이 +밝은 달은 우리 가슴 일편단심일세 +4절 +이 기상과 이 맘으로 충성을 다하여 +괴로우나 즐거우나 나라 사랑하세 +(후렴) +무궁화 삼천리 화려강산 +대한사람 대한으로 길이 보전하세 \ No newline at end of file diff --git a/src/web/client/typing_examination.html b/src/web/client/typing_examination.html new file mode 100644 index 0000000..ab87aa8 --- /dev/null +++ b/src/web/client/typing_examination.html @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + 타자 검정 | 초코마에 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + \ No newline at end of file