Add: RankingRecordManager

This commit is contained in:
2018-05-17 12:05:21 +09:00
parent 0f623e954c
commit 2c1b928554
11 changed files with 224 additions and 80 deletions
+1
View File
@@ -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);
+58 -17
View File
@@ -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();
}
}
+6 -1
View File
@@ -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;
}
+49
View File
@@ -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;
}
}
+8
View File
@@ -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);
+34 -49
View File
@@ -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);
}
}
+10 -6
View File
@@ -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;
+2
View File
@@ -17,6 +17,8 @@
<!-- library source files -->
<script src="../../game/lib/number_util.js"></script>
<script src="../../game/lib/history_record_manager.js"></script>
<script src="../../game/lib/ranking_record_manager.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
<script src="../../game/lib/input_type_text.js"></script>
<script src="../../game/lib/round_rect_button.js"></script>
<script src="../../game/lib/back_button.js"></script>
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.6.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.6.0.js"></script>
<script src="../src/game/lib/ranking_record_manager.js"></script>
<script src="test_ranking_record_manager.js"></script>
</body>
</html>
+9 -6
View File
@@ -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);
+30
View File
@@ -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);
});