diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 0e1aea6..0fbb623 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -30,6 +30,7 @@ let sessionStorageManager = new SessionStorageManager(); // sessionStorageManager.highScore = 2000; // } + console.log("maestroID : " + sessionStorageManager.maestroID); console.log("playerName : " + sessionStorageManager.playerName); console.log("playerUserID : " + sessionStorageManager.playerUserID); console.log("playingAppName : " + sessionStorageManager.playingAppName); diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 5498906..234b9ec 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -1,38 +1,76 @@ class DBConnectManager { constructor() { + this.maestroID = 0; + this.playerUserID = 0; + this.appName = ""; } - requestMyHistory(appName) { - + setMaestro(maestroID) { + this.maestroID = maestroID; } - requestRankingHour(appName) { - + setPlayer(userID) { + this.playerUserID = userID; } - requestRankingDay(appName) { - + setAppName(appName) { + this.appName = appName; } - requestRankingMonth(appName) { - + requestMyHistory(listener) { + let historyRecordManager = new HistoryRecordManager(); + + listener(historyRecordManager); + } + + requestRankingHour(listener) { + this.requestRanking(type, listener); + } + + requestRankingDay(listener) { + this.requestRanking(type, listener); + } + + requestRankingMonth(listener) { + this.requestRanking(type, listener); + } + + requestAllRankingHour(listener) { + this.requestRanking(type, listener); + } + + requestAllRankingDay(listener) { + this.requestRanking(type, listener); + } + + requestAllRankingMonth(listener) { + this.requestRanking(type, listener); + } + + requestRanking(type, listener) { + let rankingRecordManager = new RankingRecordManager(); + + listener(rankingRecordManager); } - requestTempMyHistory() { - this.historyRecordManager.clear(); + requestTempMyHistory(listener) { + let historyRecordManager = new HistoryRecordManager(); - this.historyRecordManager.push(new HistoryRecordData("05/10", 15460)); - this.historyRecordManager.push(new HistoryRecordData("05/11", 3040)); - this.historyRecordManager.push(new HistoryRecordData("05/12", 460)); - this.historyRecordManager.push(new HistoryRecordData("05/13", 60)); - this.historyRecordManager.push(new HistoryRecordData("05/14", 8)); + historyRecordManager.push(new HistoryRecord("05/10", "space_invaders", 15460)); + historyRecordManager.push(new HistoryRecord("05/11", "typing_korean_basic", 3040)); + historyRecordManager.push(new HistoryRecord("05/12", "typing_english_basic", 460)); + historyRecordManager.push(new HistoryRecord("05/13", "space_invaders", 60)); + historyRecordManager.push(new HistoryRecord("05/14", "space_invaders", 8)); - this.printHistoryRecords(); + if(listener === null) + return; + + listener(historyRecordManager); } - requestTempRanking() { + requestTempRanking(userID, appName, rankingRecordManager, listener) { let jsonRankingList = [ { "UserID":"17", "Name":"강경모", "BestRecord":"4400" }, { "UserID":"2", "Name":"강성태", "BestRecord":"3400" }, @@ -52,7 +90,10 @@ class DBConnectManager { { "UserID":"16", "Name":"하하하", "BestRecord":"4" }, ]; - return jsonRankingList; + if(listener === null) + return; + + listener(); } } \ No newline at end of file diff --git a/src/game/lib/history_record_manager.js b/src/game/lib/history_record_manager.js index 19125cf..3226ef2 100644 --- a/src/game/lib/history_record_manager.js +++ b/src/game/lib/history_record_manager.js @@ -1,7 +1,8 @@ class HistoryRecord { - constructor(date, score) { + constructor(date, appName, score) { this.date = date; + this.appName = appName; this.score = score; } } @@ -40,6 +41,10 @@ class HistoryRecordManager { return this.historyRecords[index].date; } + getAppNameAt(index) { + return this.historyRecords[index].appName; + } + getScoreAt(index) { return this.historyRecords[index].score; } diff --git a/src/game/lib/ranking_record_manager.js b/src/game/lib/ranking_record_manager.js new file mode 100644 index 0000000..a421f58 --- /dev/null +++ b/src/game/lib/ranking_record_manager.js @@ -0,0 +1,49 @@ +class RankingRecord { + + constructor(rank, userName, score) { + this.rank = rank; + this.userName = userName; + this.score = score; + } +} + + + +class RankingRecordManager { + + constructor() { + this.clear(); + } + + push(RankingRecord) { + this.rankingRecords.push(RankingRecord); + } + + clear() { + this.rankingRecords = []; + + this.minValueOfRecord = 0; + this.maxValueOfRecord = 0; + } + + get count() { + return this.rankingRecords.length; + } + + getAt(index) { + return this.rankingRecords[index]; + } + + getRankAt(index) { + return this.rankingRecords[index].rank; + } + + getUserNameAt(index) { + return this.rankingRecords[index].userName; + } + + getScoreAt(index) { + return this.rankingRecords[index].score; + } + +} \ 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 1dc4ee7..ddda845 100644 --- a/src/game/lib/session_storage_manager.js +++ b/src/game/lib/session_storage_manager.js @@ -11,6 +11,14 @@ class SessionStorageManager { return sessionStorage.removeItem(key); } + // maestro user ID + set maestroID(value) { + sessionStorage.setItem("maestroID", value); + } + get maestroID() { + return sessionStorage.getItem("maestroID"); + } + // player name set playerName(value) { sessionStorage.setItem("playerName", value); diff --git a/src/game/result/history_board.js b/src/game/result/history_board.js index ff80e1a..c80dd77 100644 --- a/src/game/result/history_board.js +++ b/src/game/result/history_board.js @@ -4,7 +4,7 @@ class HistoryBoard { constructor() { - this.historyRecordManager = new HistoryRecordManager(); + this.dbConnectManager = new DBConnectManager(); let arrayTabStyle = { font: "20px Arial", fill: "#fff", align: "left", tabs: [ 40, 80, 120 ] }; @@ -13,60 +13,22 @@ class HistoryBoard { this.textMyRanking = game.add.text(posX, posY + 100, '', arrayTabStyle) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - this.loadHistoryRecords(); + this.dbConnectManager.requestTempMyHistory( historyRecordManager => { + let self = this; + + for(let i = 0; i < historyRecordManager.count; i++) { + let data = historyRecordManager.getAt(i); + self.printRecord(i, data.date, data.score); + } + }); } - loadHistoryRecords() { - this.historyRecordManager.clear(); - - this.historyRecordManager.push(new HistoryRecord("05/10", 15460)); - this.historyRecordManager.push(new HistoryRecord("05/11", 3040)); - this.historyRecordManager.push(new HistoryRecord("05/12", 460)); - this.historyRecordManager.push(new HistoryRecord("05/13", 60)); - this.historyRecordManager.push(new HistoryRecord("05/14", 8)); - - this.printHistoryRecords(); - } - - printHistoryRecords(historyRecords) { - for(let i = 0; i < this.historyRecordManager.count; i++) { - let data = this.historyRecordManager.getAt(i); - this.printRecord(i, data.date, data.score); - } - - // this.chartGraphics.lineStyle(3, 0xffd900, 1); - // this.chartGraphics.moveTo(0, 0); - // this.chartGraphics.lineTo(game.world.width - 200, 0); - } - printRecord(index, date, score) { - if(sessionStorageManager.playingAppName.indexOf("typing") > -1) + if(sessionStorageManager.playingAppName.indexOf("typing") < 0) this.printMouseAppHistory(index, date, score); else - this.printMouseAppHistory(index, date, score); - } - - printTypingAppHistory(index, date, score) { - let posX = 60; - let posY = game.world.height / 2 + 90 + 30 * index; - - var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" }; - - style.boundsAlignH = "center"; - game.add.text(posX, posY, date, style) - .setTextBounds(0, 0, 40, 40) - .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - - game.add.text(posX + 60, posY, "(한)단어", style) - .setTextBounds(0, 0, 60, 60) - .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); - - let numberWithCommas = NumberUtil.numberWithCommas(score); - style.boundsAlignH = "right"; - game.add.text(posX + 120, posY, numberWithCommas, style) - .setTextBounds(0, 0, 80, 60) - .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + this.printTypingAppHistory(index, date, appName, score); } printMouseAppHistory(index, date, score) { @@ -86,4 +48,27 @@ class HistoryBoard { .setTextBounds(0, 0, 100, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); } + + printTypingAppHistory(index, date, appName, score) { + let posX = 60; + let posY = game.world.height / 2 + 90 + 30 * index; + + var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" }; + + style.boundsAlignH = "center"; + game.add.text(posX, posY, date, style) + .setTextBounds(0, 0, 40, 40) + .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + + let typingAppName = appName; + game.add.text(posX + 60, posY, typingAppName, style) + .setTextBounds(0, 0, 60, 60) + .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + + let numberWithCommas = NumberUtil.numberWithCommas(score); + style.boundsAlignH = "right"; + game.add.text(posX + 120, posY, numberWithCommas, style) + .setTextBounds(0, 0, 80, 60) + .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + } } \ No newline at end of file diff --git a/src/game/result/record_board.js b/src/game/result/record_board.js index dfb2e64..05501ec 100644 --- a/src/game/result/record_board.js +++ b/src/game/result/record_board.js @@ -7,6 +7,7 @@ class RecordBoard { this.chartGraphics = game.add.graphics(0, 0); this.printRecordBoardHeader(); + this.printSeperator(); let historyBoard = new HistoryBoard(); let rankingBoard = new RankingBoard(); @@ -33,12 +34,6 @@ class RecordBoard { posX = 780; this.printHeader(posX, posY, "이달의 순위", style); - - posX = 300; - posY = 480; - this.chartGraphics.lineStyle(3, 0x444444, 1); - this.chartGraphics.moveTo(posX, posY); - this.chartGraphics.lineTo(posX, posY + 200); } printHeader(x, y, title, style) { @@ -47,6 +42,15 @@ class RecordBoard { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); } + printSeperator() { + const posX = 300; + const posY = 480; + + this.chartGraphics.lineStyle(3, 0x444444, 1); + this.chartGraphics.moveTo(posX, posY); + this.chartGraphics.lineTo(posX, posY + 200); + } + } RecordBoard.HEADER_BAR_HEIGHT_PX = 60; \ No newline at end of file diff --git a/src/web/client/result.html b/src/web/client/result.html index fe07b06..889c498 100644 --- a/src/web/client/result.html +++ b/src/web/client/result.html @@ -17,6 +17,8 @@ + + diff --git a/test/ranking_record_manager.html b/test/ranking_record_manager.html new file mode 100644 index 0000000..97e4614 --- /dev/null +++ b/test/ranking_record_manager.html @@ -0,0 +1,16 @@ + + + + + + QUnit Example + + + +
+
+ + + + + \ No newline at end of file diff --git a/test/test_history_record_manager.js b/test/test_history_record_manager.js index b38c06d..f27a9c5 100644 --- a/test/test_history_record_manager.js +++ b/test/test_history_record_manager.js @@ -1,10 +1,10 @@ let historyRecordManager = new HistoryRecordManager(); -historyRecordManager.push(new HistoryRecordData("05/10", 1000)); -historyRecordManager.push(new HistoryRecordData("05/11", 100)); -historyRecordManager.push(new HistoryRecordData("05/12", 200)); -historyRecordManager.push(new HistoryRecordData("05/13", 2000)); -historyRecordManager.push(new HistoryRecordData("05/14", 10000)); +historyRecordManager.push(new HistoryRecord("05/10", "space_invaders", 1000)); +historyRecordManager.push(new HistoryRecord("05/11", "typing_korean_basic", 100)); +historyRecordManager.push(new HistoryRecord("05/12", "cooking_meats", 200)); +historyRecordManager.push(new HistoryRecord("05/13", "typing_english_basic", 2000)); +historyRecordManager.push(new HistoryRecord("05/14", "test", 10000)); QUnit.test( "push", function( assert ) { assert.equal(historyRecordManager.count, 5); @@ -13,11 +13,14 @@ QUnit.test( "push", function( assert ) { QUnit.test( "getAt", function( assert ) { assert.equal(historyRecordManager.getDateAt(0), "05/10"); assert.equal(historyRecordManager.getDateAt(4), "05/14"); + + assert.equal(historyRecordManager.getAppNameAt(0), "space_invaders"); + assert.equal(historyRecordManager.getAppNameAt(4), "test"); }); QUnit.test( "clear", function( assert ) { let historyRecordManagerForClear = new HistoryRecordManager(); - historyRecordManagerForClear.push(new HistoryRecordData("05/10", 1)); + historyRecordManagerForClear.push(new HistoryRecord("05/10", "space_invaders", 1)); historyRecordManagerForClear.clear(); assert.equal(historyRecordManagerForClear.count, 0); diff --git a/test/test_ranking_record_manager.js b/test/test_ranking_record_manager.js new file mode 100644 index 0000000..78a5446 --- /dev/null +++ b/test/test_ranking_record_manager.js @@ -0,0 +1,30 @@ +let rankingRecordManager = new RankingRecordManager(); + +rankingRecordManager.push(new RankingRecord(4, "김남희", 1400)); +rankingRecordManager.push(new RankingRecord(5, "고봉순", 900)); +rankingRecordManager.push(new RankingRecord(6, "파르마", 800)); +rankingRecordManager.push(new RankingRecord(7, "박지상", 700)); +rankingRecordManager.push(new RankingRecord(8, "신현주", 600)); + +QUnit.test( "push", function( assert ) { + assert.equal(rankingRecordManager.count, 5); +}); + +QUnit.test( "getAt", function( assert ) { + assert.equal(rankingRecordManager.getRankAt(0), 4); + assert.equal(rankingRecordManager.getRankAt(4), 8); + + assert.equal(rankingRecordManager.getUserNameAt(0), "김남희"); + assert.equal(rankingRecordManager.getUserNameAt(4), "신현주"); + + assert.equal(rankingRecordManager.getScoreAt(0), 1400); + assert.equal(rankingRecordManager.getScoreAt(4), 600); +}); + +QUnit.test( "clear", function( assert ) { + let rankingRecordManagerForClear = new RankingRecordManager(); + rankingRecordManagerForClear.push(new RankingRecord(8, "신현주", 600)); + rankingRecordManagerForClear.clear(); + + assert.equal(rankingRecordManagerForClear.count, 0); +}); \ No newline at end of file