From 988d289a7041d1925db56b49846b1a29785b47b6 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, 27 Sep 2018 12:43:28 +0900 Subject: [PATCH] Add: experience app timer --- src/game/lib/experience_app_timer.js | 77 ++++++++++++++++++++++++ src/game/mouse/space_invaders/game.js | 5 ++ src/game/typing/practice/game.js | 6 ++ src/game/typing/test/game.js | 7 ++- src/web/client/space_invaders.html | 1 + src/web/client/typing_practice.html | 1 + src/web/client/typing_test.html | 1 + src/web/module/maestro_section_main.html | 2 +- 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/game/lib/experience_app_timer.js diff --git a/src/game/lib/experience_app_timer.js b/src/game/lib/experience_app_timer.js new file mode 100644 index 0000000..bbffbcf --- /dev/null +++ b/src/game/lib/experience_app_timer.js @@ -0,0 +1,77 @@ +function ExperienceAppTimer() { + if(!isExperienceMaestroAccount()) { + return; + } + + this.leftTime = ExperienceAppTimer.DEFAULT_LEFT_TIME_SEC; + this.onTimeOver = null; + + var timeLeftText = game.add.text( + game.world.centerX + ExperienceAppTimer.OFFSET_POS_X, + game.world.height - ExperienceAppTimer.OFFSET_POS_Y, + "앱 체험 종료까지 ", + this.getFontStyle() + ); + timeLeftText.anchor.set(1, 0.5); + timeLeftText.alpha = 0.5; + // timeLeftText.stroke = '#000'; + // timeLeftText.strokeThickness = 3; + + this.timerText = game.add.text( + game.world.centerX + ExperienceAppTimer.OFFSET_POS_X, + game.world.height - ExperienceAppTimer.OFFSET_POS_Y, + this.getLeftTimeText(), + this.getFontStyle() + ); + this.timerText.anchor.set(0, 0.5); + // this.timerText.stroke = '#000'; + // this.timerText.strokeThickness = 3; + + // this.setTimeLimit(4); + + this.loopTimer = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this); +}; + + +ExperienceAppTimer.prototype.getFontStyle = function() { + return { font: "24px Arial", fill: "#f86", align: "left", boundsAlignH: "left", boundsAlignV: "bottom" }; +} + +ExperienceAppTimer.prototype.getLeftTimeText = function() { + return this.leftTime + " 초"; +} + +ExperienceAppTimer.prototype.setTimeOverListener = function(onTimeOver) { + this.onTimeOver = onTimeOver; +} + +ExperienceAppTimer.prototype.setTimeLimit = function(leftTime) { + this.leftTime = leftTime; + this.timerText.text = this.getLeftTimeText(); +} + +ExperienceAppTimer.prototype.updateTimer = function() { + this.leftTime--; + + if(this.leftTime == 5) { + this.timerText.fill = "#f42"; + } else if(this.leftTime == 0) { + this.timerText.fill = "#f00"; + } + + if(this.leftTime > 0) { + this.timerText.text = this.getLeftTimeText(); + } else { + this.timerText.text = this.getLeftTimeText(); + + if(this.loopTimer != null) + game.time.events.remove(this.loopTimer); + + if(this.onTimeOver != null) + this.onTimeOver(); + } +} + +ExperienceAppTimer.DEFAULT_LEFT_TIME_SEC = 20; +ExperienceAppTimer.OFFSET_POS_X = 60; +ExperienceAppTimer.OFFSET_POS_Y = 60; \ No newline at end of file diff --git a/src/game/mouse/space_invaders/game.js b/src/game/mouse/space_invaders/game.js index af1401d..faf16bc 100644 --- a/src/game/mouse/space_invaders/game.js +++ b/src/game/mouse/space_invaders/game.js @@ -5,6 +5,11 @@ var Game = { sessionStorageManager.setIsNewBestRecord(false); + var experienceAppTimer = new ExperienceAppTimer(); + experienceAppTimer.setTimeOverListener( + (function() { this.gameOver(); }).bind(this) + ); + // top ui var screenTopUI = new ScreenTopUI(); screenTopUI.makeBackButton( function() { diff --git a/src/game/typing/practice/game.js b/src/game/typing/practice/game.js index 5597930..18416e6 100644 --- a/src/game/typing/practice/game.js +++ b/src/game/typing/practice/game.js @@ -1,4 +1,5 @@ var TypingPractice = { + create: function() { var self = this; @@ -7,6 +8,11 @@ var TypingPractice = { this.initTypingData(); sessionStorageManager.setIsNewBestRecord(false); + var experienceAppTimer = new ExperienceAppTimer(); + experienceAppTimer.setTimeOverListener( + (function() { this.gameOver(); }).bind(this) + ); + game.stage.backgroundColor = '#4d4d4d'; // top ui diff --git a/src/game/typing/test/game.js b/src/game/typing/test/game.js index 06dbd8a..7f7041b 100644 --- a/src/game/typing/test/game.js +++ b/src/game/typing/test/game.js @@ -1,11 +1,16 @@ var TypingTest = { create: function() { - self = this; + var self = this; this.initTypingData(); sessionStorageManager.setIsNewBestRecord(false); + var experienceAppTimer = new ExperienceAppTimer(); + experienceAppTimer.setTimeOverListener( + (function() { this.gameOver(); }).bind(this) + ); + game.stage.backgroundColor = '#4d4d4d'; // top ui diff --git a/src/web/client/space_invaders.html b/src/web/client/space_invaders.html index 2c739ff..4903ac9 100644 --- a/src/web/client/space_invaders.html +++ b/src/web/client/space_invaders.html @@ -28,6 +28,7 @@ + diff --git a/src/web/client/typing_practice.html b/src/web/client/typing_practice.html index 456e6a1..be908a5 100644 --- a/src/web/client/typing_practice.html +++ b/src/web/client/typing_practice.html @@ -26,6 +26,7 @@ + diff --git a/src/web/client/typing_test.html b/src/web/client/typing_test.html index 75aaee3..ce1abe9 100644 --- a/src/web/client/typing_test.html +++ b/src/web/client/typing_test.html @@ -26,6 +26,7 @@ + diff --git a/src/web/module/maestro_section_main.html b/src/web/module/maestro_section_main.html index 78c5ec3..319cc25 100644 --- a/src/web/module/maestro_section_main.html +++ b/src/web/module/maestro_section_main.html @@ -104,7 +104,7 @@ function deactivateApp(appID) {
▶ 체험판 [마에스트로 앱] 기능 제한 안내
- 타자, 마우스 앱 연습 결과가 서버에 저장되지 않습니다.
- - 모든 컨텐츠는 30초만 플레이하실 수 있습니다.
+ - 모든 컨텐츠는 20초만 플레이하실 수 있습니다.