From c6e3411212f2c419485b578dd9210d2dc0b67064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 7 Jun 2018 14:49:16 +0900 Subject: [PATCH] Add: show result after typing test --- src/game/result/result.js | 4 ++-- src/game/typing/test/game.js | 41 +++++++++++++++++------------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/game/result/result.js b/src/game/result/result.js index 14b32a1..4541ee2 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -35,7 +35,7 @@ class Result { // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); - screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); + screenBottom.printBottomLeftTextWithBestRecord(Math.floor(sessionStorageManager.bestRecord)); screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName); screenBottom.printBottomRightText(sessionStorageManager.playerName); } @@ -49,7 +49,7 @@ class Result { let posY = 120; if(sessionStorageManager.record === null) sessionStorageManager.record = 0; - let record = NumberUtil.numberWithCommas(sessionStorageManager.record); + let record = NumberUtil.numberWithCommas(Math.floor(sessionStorageManager.record)); style.font = "bold 80px Arial"; game.add.text(0, 0, record, style) .setTextBounds(0, posY, game.world.width, 60) diff --git a/src/game/typing/test/game.js b/src/game/typing/test/game.js index 9b64571..6f15a2f 100644 --- a/src/game/typing/test/game.js +++ b/src/game/typing/test/game.js @@ -9,7 +9,7 @@ class Test { this.initTypingData(); sessionStorageManager.isNewBestRecrd = false; - this.game.stage.backgroundColor = '#4d4d4d'; + game.stage.backgroundColor = '#4d4d4d'; // top let backButton = new BackButton( () => { @@ -20,12 +20,7 @@ class Test { this.averageTypingSpeedText = new AverageTypingSpeed(); this.contentProgressText = new ContentProgress(); - // var scoreboardAreaPositionY = 2; - // this.textPlayingWordNumber = game.add.text(900, scoreboardAreaPositionY, "0", textStyleBasic) - // .setTextBounds(0, 0, 300, 80) - // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - - let fullscreenButton = new FullscreenButton(this.game); + let fullscreenButton = new FullscreenButton(game); // typing content @@ -77,7 +72,7 @@ class Test { // input text - this.inputTextContent = new InputTypeText(this.game.world.centerX, typingAreaPositionY + 360); + this.inputTextContent = new InputTypeText(game.world.centerX, typingAreaPositionY + 360); this.inputTextContent.anchor.set(0.5); this.inputTextContent.canvasInput.value(''); this.inputTextContent.canvasInput.focus(); @@ -132,7 +127,7 @@ class Test { */ startGame() { - this.initStage(); + this.averageTypingSpeedText.print(0); this.showTypingTestContents(); this.showPlayingWordNumber(); @@ -145,6 +140,10 @@ class Test { } goResult() { + sessionStorageManager.record = this.typingRecordTotal; + if(sessionStorageManager.record > sessionStorageManager.bestRecord) + sessionStorageManager.bestRecord = sessionStorageManager.record; + location.href = '../../web/client/result.html'; } @@ -163,12 +162,9 @@ class Test { this.timeTypingEnd = 0; this.typingLetterCountTotal = 0; + this.typingRecordTotal = 0; } - initStage() { - // this.textBestRecord.text = Math.floor(sessionStorageManager.bestRecord); - this.averageTypingSpeedText.print(0); - } getTypingTestContents() { var typingTestContents = this.loadTestContent(); @@ -255,7 +251,8 @@ class Test { this.playNextContent(); if(this.typingIndex == this.wordCountForStage) - this.state.start('TypingTestResult'); + this.goResult(); + // this.state.start('TypingTestResult'); } } else { @@ -295,7 +292,7 @@ class Test { // console.log('입력 단어 : ' + this.typingRandomContents[this.typingIndex]); this.isTyping = false; - this.timeTypingEnd = this.game.time.elapsedSince(0); + this.timeTypingEnd = game.time.elapsedSince(0); // console.log('this.timeTypingEnd : ' + this.timeTypingEnd); var elapsedTimeMS = this.timeTypingEnd - this.timeTypingStart; @@ -317,12 +314,13 @@ class Test { // console.log('i : ' + i + ' - time : ' + this.typingElapsedTime[i]); typingElapsedTimeTotal += this.typingElapsedTime[i]; } - let typingRecordTotal = this.typingLetterCountTotal * 60000 / typingElapsedTimeTotal; - console.log(this.typingLetterCountTotal); - console.log(typingElapsedTimeTotal); - console.log(typingRecordTotal); + this.typingRecordTotal = this.typingLetterCountTotal * 60000 / typingElapsedTimeTotal; + // console.log(this.typingLetterCountTotal); + // console.log(typingElapsedTimeTotal); + // console.log(typingRecordTotal); + // this.textTypingRecordTotal.text = Math.floor(typingRecordTotal); - this.averageTypingSpeedText.print(Math.floor(typingRecordTotal)); + this.averageTypingSpeedText.print(Math.floor(this.typingRecordTotal)); // console.log('-------------- total --------------'); // console.log('typingLetterCountTotal : ' + this.typingLetterCountTotal); // console.log('typingElapsedTimeTotal : ' + typingElapsedTimeTotal); @@ -338,12 +336,11 @@ class Test { } showPlayingWordNumber() { - // this.textPlayingWordNumber.text = (this.typingIndex + 1) + " / " + this.wordCountForStage; this.contentProgressText.print(this.typingIndex + 1, this.wordCountForStage); } setTimeTypingStart() { - this.timeTypingStart = this.game.time.elapsedSince(0); + this.timeTypingStart = game.time.elapsedSince(0); var timeGap = this.timeTypingStart - this.timeTypingEnd; if(timeGap < 50)