From 3f43f80c3d013620341b22eaf86682473f4f089e 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: Tue, 5 Jun 2018 18:29:19 +0900 Subject: [PATCH] Fix: show best record with DB --- src/game/lib/screen_bottom.js | 6 ++++++ src/game/lib/session_storage_manager.js | 8 ++++++++ src/game/mouse/space_invaders/game.js | 27 ++++++++++++++----------- src/game/result/result.js | 13 +++++++++++- src/game/start/start.js | 17 +++++++++++++--- src/web/client/space_invaders.html | 1 + 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/game/lib/screen_bottom.js b/src/game/lib/screen_bottom.js index c7fef02..fcdc6d7 100644 --- a/src/game/lib/screen_bottom.js +++ b/src/game/lib/screen_bottom.js @@ -8,6 +8,8 @@ class ScreenBottom { this.BOTTOM_BAR_NAME_WIDTH = 200; this.BOTTOM_BAR_TEXT_OFFSET = 10; + this.dbConnectManager = new DBConnectManager(); + this.bottomAreaPositionY = game.world.height - this.BOTTOM_BAR_HEIGHT; let style = { font: "32px Arial", fill: "#fff", align: "left", boundsAlignH: "left", boundsAlignV: "bottom" }; @@ -61,4 +63,8 @@ class ScreenBottom { this.rightText.text = text; } + printBottomLeftTextWithBestRecord(bestRecord) { + this.printBottomLeftText("오늘의 최고 기록 : " + bestRecord); + } + } \ No newline at end of file diff --git a/src/game/lib/session_storage_manager.js b/src/game/lib/session_storage_manager.js index 0c13916..630e32e 100644 --- a/src/game/lib/session_storage_manager.js +++ b/src/game/lib/session_storage_manager.js @@ -75,4 +75,12 @@ class SessionStorageManager { return sessionStorage.getItem("bestRecord"); } + // best record + set isNewBestRecord(value) { + sessionStorage.setItem("isNewBestRecord", value); + } + get isNewBestRecord() { + return sessionStorage.getItem("isNewBestRecord"); + } + } \ 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 43ac04c..3077e54 100644 --- a/src/game/mouse/space_invaders/game.js +++ b/src/game/mouse/space_invaders/game.js @@ -6,21 +6,13 @@ class Game { create() { this.game.stage.backgroundColor = '#4d4d4d'; + sessionStorageManager.isNewBestRecrd = false; + // top let backButton = new BackButton( () => { location.href = '../../web/client/menu_app.html'; }); - let scoreBoard = new ScoreBoard(); - scoreManager.addOnChangeScoreListener( score => { - sessionStorageManager.record = score; - scoreBoard.printScore(NumberUtil.numberWithCommas(score)); - }); - scoreManager.addOnChangeHighScoreListener( highScore => { - sessionStorageManager.bestRecord = highScore; - screenBottom.printBottomLeftText("최고 기록 : " + NumberUtil.numberWithCommas(highScore)); - }); - let heartGauge = new HeartGauge(heartManager); heartManager.addOnChangeGameOverListener( () => { this.gameOver(); } @@ -30,6 +22,18 @@ class Game { let fullscreenButton = new FullscreenButton(this.game); + let scoreBoard = new ScoreBoard(); + scoreManager.addOnChangeScoreListener( score => { + sessionStorageManager.record = score; + scoreBoard.printScore(NumberUtil.numberWithCommas(score)); + }); + scoreManager.addOnChangeHighScoreListener( highScore => { + sessionStorageManager.bestRecord = highScore; + sessionStorageManager.isNewBestRecrd = true; + screenBottom.printBottomLeftTextWithBestRecord(); + }); + + // waiting room this.game.add.graphics() .beginFill(0xffffff, 0.1) @@ -58,8 +62,7 @@ class Game { // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); - let highScore = NumberUtil.numberWithCommas(scoreManager.getHighScore()); - screenBottom.printBottomLeftText("최고 기록 : " + highScore); + screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName); screenBottom.printBottomRightText(sessionStorageManager.playerName); diff --git a/src/game/result/result.js b/src/game/result/result.js index b230e0c..169172f 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -34,7 +34,7 @@ class Result { // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); - screenBottom.printBottomLeftText("게임 진행 정보"); + screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName); screenBottom.printBottomRightText(sessionStorageManager.playerName); } @@ -54,6 +54,16 @@ class Result { .setTextBounds(0, posY, game.world.width, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + + if(sessionStorageManager.isNewBestRecrd === true) { + style.font = "32px Arial"; + let bestRecordText = game.add.text(0, 0, "!!! 새로운 최고 기록 !!!", style) + .setTextBounds(0, posY + 80, game.world.width, 40); + // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + bestRecordText.stroke = "#333"; + bestRecordText.strokeThickness = 5; + } + /* if(sessionStorageManager.bestRecord === null) sessionStorageManager.bestRecord = 0; let bestRecord = NumberUtil.numberWithCommas(sessionStorageManager.bestRecord); @@ -63,6 +73,7 @@ class Result { // .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); bestRecordText.stroke = "#333"; bestRecordText.strokeThickness = 5; + */ } uploadRecord() { diff --git a/src/game/start/start.js b/src/game/start/start.js index 2655c09..d2f9af1 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -58,10 +58,21 @@ class Start { // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); - screenBottom.printBottomLeftText("게임 진행 정보"); - let playingAppKoreanName = sessionStorageManager.playingAppKoreanName; - screenBottom.printBottomCenterText(playingAppKoreanName); + screenBottom.printBottomLeftText("오늘의 최고 기록 : "); + screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName); screenBottom.printBottomRightText(sessionStorageManager.playerName); + + + this.dbConnectManager.requestTodayBestRecord( + sessionStorageManager.maestroID, + sessionStorageManager.playerUserID, + sessionStorageManager.playingAppID, + replyJSON => { + sessionStorageManager.BestRecord = Number(replyJSON["BestRecord"]); + let highScoreWithCommas = NumberUtil.numberWithCommas(sessionStorageManager.BestRecord); + screenBottom.printBottomLeftText("오늘의 최고 기록 : " + highScoreWithCommas); + } + ); } loadHowToPlay(appID) { diff --git a/src/web/client/space_invaders.html b/src/web/client/space_invaders.html index b2f31cc..188b509 100644 --- a/src/web/client/space_invaders.html +++ b/src/web/client/space_invaders.html @@ -25,6 +25,7 @@ +