Add: ranking hour, day, month record php
This commit is contained in:
@@ -37,6 +37,17 @@ let sessionStorageManager = new SessionStorageManager();
|
||||
console.log("score : " + sessionStorageManager.score);
|
||||
console.log("highscore : " + sessionStorageManager.highScore);
|
||||
}
|
||||
|
||||
function isTypingGame() {
|
||||
if(sessionStorageManager.playingAppName === null)
|
||||
return false;
|
||||
|
||||
if(sessionStorageManager.playingAppName.indexOf("typing") < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let appInfoManager = new AppInfoManager();
|
||||
|
||||
let textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
|
||||
@@ -71,6 +71,12 @@ class DBConnectManager {
|
||||
parseJSONtoHistoryRecord(json) {
|
||||
let historyRecordManager = new HistoryRecordManager();
|
||||
|
||||
if(typeof json === "undefined")
|
||||
return historyRecordManager;
|
||||
|
||||
if(typeof json.history === "undefined")
|
||||
return historyRecordManager;
|
||||
|
||||
let count = json.history.length;
|
||||
for(let i = 0; i < count; i++) {
|
||||
let record = new HistoryRecord(
|
||||
@@ -108,16 +114,98 @@ class DBConnectManager {
|
||||
requestRanking(type, listener) {
|
||||
let rankingRecordManager = new RankingRecordManager();
|
||||
|
||||
/*
|
||||
if(isDebugMode()) {
|
||||
this.loadTempPlayerHistory(historyRecordManager);
|
||||
this.loadTempRanking(rankingRecordManager);
|
||||
|
||||
if(listener !== null)
|
||||
listener(historyRecordManager);
|
||||
listener(rankingRecordManager);
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
let self = this;
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", this.getPHPUrl(type), true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState == 4 && xhr.status == 200) {
|
||||
let jsonData = JSON.parse(xhr.responseText);
|
||||
|
||||
if(jsonData != null) {
|
||||
listener(type, self.parseJSONtoRankingRecord(type, jsonData));
|
||||
}
|
||||
else
|
||||
onFailedListener(jsonData);
|
||||
}
|
||||
};
|
||||
let params = "UserID=" + sessionStorageManager.playerUserID
|
||||
+ "&AppName=" + sessionStorageManager.playingAppName;
|
||||
console.log(params);
|
||||
xhr.send(params);
|
||||
}
|
||||
|
||||
getPHPUrl(type) {
|
||||
switch(type) {
|
||||
case DBConnectManager.TYPE_MY_RANKING_HOUR:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
|
||||
return "../../web/server/record/ranking_hour_record.php";
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_DAY:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_DAY:
|
||||
return "../../web/server/record/ranking_day_record.php";
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_MONTH:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
|
||||
return "../../web/server/record/ranking_month_record.php";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
parseJSONtoRankingRecord(type, json) {
|
||||
let rankingRecordManager = new RankingRecordManager();
|
||||
|
||||
if(typeof json === "undefined")
|
||||
return rankingRecordManager;
|
||||
|
||||
let jsonData = null;
|
||||
switch(type) {
|
||||
case DBConnectManager.TYPE_MY_RANKING_HOUR:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
|
||||
jsonData = json.rankingHour;
|
||||
break;
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_DAY:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_DAY:
|
||||
jsonData = json.rankingDay;
|
||||
break;
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_MONTH:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
|
||||
jsonData = json.rankingMonth;
|
||||
break;
|
||||
}
|
||||
|
||||
if(jsonData === null)
|
||||
return rankingRecordManager;
|
||||
|
||||
let count = jsonData.length;
|
||||
for(let i = 0; i < count; i++) {
|
||||
let record = new RankingRecord(
|
||||
i + 1,
|
||||
jsonData[i]["Name"],
|
||||
jsonData[i]["HighScore"]
|
||||
);
|
||||
rankingRecordManager.push(record);
|
||||
}
|
||||
|
||||
return rankingRecordManager;
|
||||
}
|
||||
|
||||
|
||||
onFailed(errorMessage) {
|
||||
console.log("failed : " + errorMessage);
|
||||
}
|
||||
|
||||
@@ -8,4 +8,14 @@ class NumberUtil {
|
||||
return Math.floor(Math.log(number) / Math.LN10 + 1); // bug : 1000 -> expected 4 but 3
|
||||
}
|
||||
|
||||
static getScoreText(value) {
|
||||
let number = Math.floor(value);
|
||||
let numberWithCommas = NumberUtil.numberWithCommas(number);
|
||||
|
||||
if(isTypingGame())
|
||||
return numberWithCommas + " 타";
|
||||
else
|
||||
return numberWithCommas + " 점";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
class StringUtil {
|
||||
|
||||
static printMonthDay(date) {
|
||||
let dateTime = new Date(date);
|
||||
return (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일";
|
||||
}
|
||||
|
||||
static getScoreTextWithoutUnit(value) {
|
||||
let number = Math.floor(value);
|
||||
return NumberUtil.numberWithCommas(number);
|
||||
}
|
||||
|
||||
static getScoreTextWithUnit(value) {
|
||||
let number = Math.floor(value);
|
||||
let numberWithCommas = NumberUtil.numberWithCommas(number);
|
||||
|
||||
if(isTypingGame())
|
||||
return numberWithCommas + " 타";
|
||||
else
|
||||
return numberWithCommas + " 점";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,12 +14,17 @@ class HistoryBoard {
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
this.dbConnectManager.requestPlayerHistory( historyRecordManager => {
|
||||
let maxIndex = historyRecordManager.count;
|
||||
if(maxIndex > 6)
|
||||
maxIndex = 6;
|
||||
|
||||
for(let i = 0; i < historyRecordManager.count; i++) {
|
||||
if(i > 6)
|
||||
break;
|
||||
|
||||
let data = historyRecordManager.getAt(i);
|
||||
let data = historyRecordManager.getAt(maxIndex);
|
||||
this.printRecord(i, data.date, data.score);
|
||||
maxIndex--;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -39,13 +44,12 @@ class HistoryBoard {
|
||||
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
|
||||
style.boundsAlignH = "center";
|
||||
game.add.text(posX, posY, date, style)
|
||||
game.add.text(posX, posY, StringUtil.printMonthDay(date), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
let numberWithCommas = NumberUtil.numberWithCommas(score);
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(posX + 80, posY, numberWithCommas, style)
|
||||
game.add.text(posX + 80, posY, StringUtil.getScoreTextWithoutUnit(score), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
@@ -61,14 +65,12 @@ class HistoryBoard {
|
||||
.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)
|
||||
game.add.text(posX + 60, posY, appName, 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)
|
||||
game.add.text(posX + 120, posY, StringUtil.getScoreTextWithoutUnit(score), style)
|
||||
.setTextBounds(0, 0, 80, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@ class RankingBoard {
|
||||
this.dbConnectManager = new DBConnectManager();
|
||||
|
||||
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR);
|
||||
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
|
||||
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
|
||||
// this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
|
||||
// this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
|
||||
}
|
||||
|
||||
|
||||
requestRanking(type, rankingRecordManager) {
|
||||
this.dbConnectManager.requestRanking(type, rankingRecordManager => {
|
||||
this.dbConnectManager.requestRanking(type, (type, rankingRecordManager) => {
|
||||
console.log(type);
|
||||
console.log(rankingRecordManager);
|
||||
for(let i = 0; i < rankingRecordManager.count; i++) {
|
||||
if(i > 6)
|
||||
break;
|
||||
@@ -40,9 +42,9 @@ class RankingBoard {
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
// score
|
||||
let numberWithCommas = NumberUtil.numberWithCommas(data.score);
|
||||
let score = StringUtil.getScoreTextWithoutUnit(data.score);
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(this.getPosX(type) + 120, this.getPosY(index), numberWithCommas, style)
|
||||
game.add.text(this.getPosX(type) + 120, this.getPosY(index), score, style)
|
||||
.setTextBounds(0, 0, 80, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
@@ -53,17 +55,17 @@ class RankingBoard {
|
||||
switch(type) {
|
||||
case DBConnectManager.TYPE_MY_RANKING_HOUR:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
|
||||
posX = 340;
|
||||
posX = 320;
|
||||
break;
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_DAY:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_DAY:
|
||||
posX = 560;
|
||||
posX = 540;
|
||||
break;
|
||||
|
||||
case DBConnectManager.TYPE_MY_RANKING_MONTH:
|
||||
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
|
||||
posX = 780;
|
||||
posX = 760;
|
||||
}
|
||||
|
||||
return posX;
|
||||
|
||||
@@ -15,7 +15,7 @@ class RecordBoard {
|
||||
|
||||
|
||||
printRecordBoardHeader() {
|
||||
let posX = 40;
|
||||
let posX = 60;
|
||||
let posY = game.world.height / 2 + 20;
|
||||
|
||||
var bar = game.add.graphics();
|
||||
@@ -25,14 +25,14 @@ class RecordBoard {
|
||||
const style = { font: "32px Arial", fill: "#ffc", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
this.printHeader(posX, posY, "최근의 내 기록", style);
|
||||
|
||||
posX = 340;
|
||||
posX = 320;
|
||||
style.fill = "#fff";
|
||||
this.printHeader(posX, posY, "수업시간 순위", style);
|
||||
|
||||
posX = 560;
|
||||
posX = 550;
|
||||
this.printHeader(posX, posY, "오늘의 순위", style);
|
||||
|
||||
posX = 780;
|
||||
posX = 770;
|
||||
this.printHeader(posX, posY, "이달의 순위", style);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class RecordBoard {
|
||||
}
|
||||
|
||||
printSeperator() {
|
||||
const posX = 300;
|
||||
const posX = 290;
|
||||
const posY = 480;
|
||||
|
||||
this.chartGraphics.lineStyle(3, 0x444444, 1);
|
||||
|
||||
@@ -80,18 +80,18 @@ class Start {
|
||||
const CHART_HEIGHT = 120;
|
||||
const style = { font: "24px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
|
||||
let dateTime = new Date(date);
|
||||
console.log(dateTime);
|
||||
console.log((dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일");
|
||||
let monthDay = (dateTime.getMonth() + 1) + "월 " + dateTime.getDate() + "일";
|
||||
|
||||
let dateText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 140, monthDay, style);
|
||||
let dateText = game.add.text(
|
||||
100 + index * CHART_GAP_PX, game.world.height - 140,
|
||||
StringUtil.printMonthDay(date), style
|
||||
);
|
||||
dateText.setTextBounds(0, 0, 100, 100);
|
||||
dateText.stroke = "#333";
|
||||
dateText.strokeThickness = 1;
|
||||
|
||||
let numberWithCommas = NumberUtil.numberWithCommas(Math.floor(score));
|
||||
let scoreText = game.add.text(100 + index * CHART_GAP_PX, game.world.height - 300, numberWithCommas, style);
|
||||
let scoreText = game.add.text(
|
||||
100 + index * CHART_GAP_PX, game.world.height - 300,
|
||||
StringUtil.getScoreTextWithUnit(score), style
|
||||
);
|
||||
scoreText.setTextBounds(0, 0, 100, 100);
|
||||
scoreText.stroke = "#333";
|
||||
scoreText.strokeThickness = 1;
|
||||
|
||||
Reference in New Issue
Block a user