Add: php server files for timer

This commit is contained in:
2018-12-13 00:36:48 +09:00
parent edbd4743af
commit 537b0c1db1
10 changed files with 374 additions and 88 deletions
+43
View File
@@ -420,6 +420,49 @@ DBConnectManager.prototype.requestLicenseTimeData = function(maestroID, playerID
);
}
DBConnectManager.prototype.updateLicenseStartTime = function(maestroID, playerID, startTime, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/license_timer/update_license_start_time.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
if(replyJSON != null)
onSucceededListener(replyJSON);
else
onFailedListener(replyJSON);
}
};
xhr.send(
"MaestroID=" + maestroID
+ "&PlayerID=" + playerID
+ "&StartTime=" + startTime
);
}
DBConnectManager.prototype.updateLicenseLeftTime = function(maestroID, playerID, leftTime, onSucceededListener, onFailedListener) {
var xhr = new XMLHttpRequest();
xhr.open("POST", this.phpPath + "server/license_timer/update_license_left_time.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
if(replyJSON != null)
onSucceededListener(replyJSON);
else
onFailedListener(replyJSON);
}
};
xhr.send(
"MaestroID=" + maestroID
+ "&PlayerID=" + playerID
+ "&LeftTime=" + leftTime
);
}
DBConnectManager.prototype.loadTempPlayerHistory = function(historyRecordManager) {
historyRecordManager.push(new HistoryRecord("05/14", "space_invaders", 14460));
+2
View File
@@ -1,4 +1,6 @@
function Chart() {
this.dbConnectManager = new DBConnectManager();
this.chartGraphics = game.add.graphics(0, 0);
this.printChartTitle();
this.printChartBaseLine();
+1 -1
View File
@@ -27,7 +27,7 @@ var LicenseTimer = {
this.chart = new Chart();
this.chart.printContents();
this.inputScore = new InputScore(this.chart);
this.inputScore = new InputScore(this.timer, this.chart);
},
back: function() {
+8 -16
View File
@@ -1,4 +1,5 @@
function InputScore(chart) {
function InputScore(timer, chart) {
this.timer = timer;
this.chart = chart;
this.licenseDataManager = new LicenseDataManager();
@@ -64,7 +65,6 @@ function InputScore(chart) {
(function() { this.onClickSendToServerButton(); }).bind(this)
);
// this.loadLicenseCompanySubjectData();
this.makeCompanyPanel();
this.makeSubjectPanel();
this.setVisibleCompanyPanel(false);
@@ -195,8 +195,8 @@ InputScore.prototype.makeSubjectPanel = function() {
setting.width = InputScore.SUBJECT_BUTTON_WIDTH;
var subjectData = this.licenseDataManager.getSubjectDataByIndex(i);
var subjectData = subjectData.companyName + " " + subjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, subjectData, null);
var subjectName = subjectData.companyName + " " + subjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, subjectName, null);
}
}
@@ -265,6 +265,9 @@ InputScore.prototype.setVisibleSubjectPanel = function(flag, companyName) {
InputScore.prototype.onClickCompanySubjectButton = function(subjectFullname) {
this.setSubjectFullname(subjectFullname);
this.selectedSubjectData = this.licenseDataManager.getSubjectDataByName(subjectFullname);
// console.log(this.selectedSubjectData);
this.timer.setStartTime(this.selectedSubjectData.timeLimit * Timer.TIME_SECONDS_FOR_MINUTE);
}
@@ -300,15 +303,4 @@ InputScore.SUBJECT_BUTTON_WIDTH = 260;
InputScore.BUTTON_GAP_WIDTH = 10;
InputScore.BUTTON_GAP_HEIGHT = 64;
InputScore.SUBJECT_BUTTON_MAX_COUNT = 6;
/*
function LicenseCompanySubjectData(companyName, subjectName, timeLimit, maxScore, gradeList) {
this.companyName = companyName;
this.subjectName = subjectName;
this.timeLimit = timeLimit;
this.maxScore = maxScore;
this.gradeList = gradeList;
}
*/
InputScore.SUBJECT_BUTTON_MAX_COUNT = 6;
+2 -2
View File
@@ -80,7 +80,7 @@ var Loading = {
// return;
// }
// this.state.start('Login');
this.state.start('LicenseTimer');
this.state.start('Login');
// this.state.start('LicenseTimer');
},
}
+135 -69
View File
@@ -1,6 +1,8 @@
function Timer() {
this.initVariables();
this.dbConnectManager = new DBConnectManager();
// bar
var bar = game.add.graphics();
bar.beginFill(0x202020);
@@ -24,8 +26,8 @@ Timer.prototype.initVariables = function() {
this.isTimerGoingOn = false;
this.isTimeOver = false;
this.timeStart = 0
this.timeLeft = 0;
this.startTime = 0
this.leftTime = 0;
this.timerEvent = null;
this.prevTime = null;
@@ -44,16 +46,36 @@ Timer.prototype.initVariables = function() {
}
Timer.prototype.loadDataFromServer = function() {
this.timeStart = Timer.TIME_DEFAULT_SEC;
this.timeLeft = Timer.TIME_DEFAULT_SEC;
this.updateTimeText();
this.dbConnectManager.requestLicenseTimeData(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
Timer.TIME_DEFAULT_SEC,
(function(replyJson) {
console.log(replyJson);
// if( there is saved time record) {
// this.isTimerGoingOn = false;
// this.setTimerTextColor(0xffffff);
// }
// else
this.setTimerTextColor(Timer.TEXT_COLOR_CYAN);
if(replyJson.leftTime == null || replyJson.leftTime == 0) {
this.startTime = replyJson.startTime;
this.leftTime = replyJson.timeStart;
this.resetTimer();
return;
}
// this.setTimerTextColor(Timer.TEXT_COLOR_CYAN);
// this.updateTimeText();
this.startTime = replyJson.startTime;
this.leftTime = replyJson.leftTime;
this.pauseTimer();
}).bind(this),
(function(replyJson) {
console.log(replyJson);
this.startTime = Timer.TIME_DEFAULT_SEC;
this.leftTime = this.startTime;
this.updateTimeText();
})
);
}
Timer.prototype.makeTimer = function() {
@@ -129,7 +151,10 @@ Timer.prototype.makeResetButton = function() {
return new RoundRectButton(
setting,
null, "C",
(function() { this.resetTimer(); }).bind(this)
(function() {
this.resetTimer();
this.resetLeftTimeToServer();
}).bind(this)
);
}
@@ -205,7 +230,10 @@ Timer.prototype.makePauseButton = function() {
return new RoundRectButton(
setting,
null, "∥",
(function() { this.pauseTimer(); }).bind(this)
(function() {
this.updateLeftTimeToServer();
this.pauseTimer();
}).bind(this)
);
}
@@ -252,16 +280,16 @@ Timer.prototype.setTimerTextColor = function(color) {
Timer.prototype.startTimer = function() {
this.isTimerGoingOn = true;
if(this.timeLeft < 0)
if(this.leftTime < 0)
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
else
this.setTimerTextColor(Timer.TEXT_COLOR_YELLOW);
this.updateTimeText();
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
ShowNotifyTimeOver(this.leftTime * Timer.TIME_MILLISECONDS);
this.prevTime = this.getNowTime();
this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this);
this.timerEvent = game.time.events.loop(1000, this.tickLeftTime, this);
this.showButton(this.playButton, false);
this.showButton(this.pauseButton, true);
@@ -281,12 +309,14 @@ Timer.prototype.pauseTimer = function() {
this.showButton(this.playButton, true);
this.showButton(this.pauseButton, false);
this.showTimerButtons();
// this.updateLeftTimeToServer();
}
Timer.prototype.resetTimer = function() {
this.isTimeOver = false;
this.timeLeft = this.timeStart;
this.leftTime = this.startTime;
this.pauseTimer();
this.isTimerGoingOn = false;
@@ -295,37 +325,32 @@ Timer.prototype.resetTimer = function() {
// this.loadDataFromServer();
}
Timer.prototype.tickTimeLeft = function() {
this.timeLeft--;
Timer.prototype.tickLeftTime = function() {
this.leftTime--;
var outFocusedTime = this.getOutFocusedTime();
if(outFocusedTime > 2) {
this.timeLeft -= outFocusedTime - 1;
this.leftTime -= outFocusedTime - 1;
if(this.timeLeft > 0) {
if(this.leftTime > 0) {
CancelNotifyTimeOver();
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
ShowNotifyTimeOver(this.leftTime * Timer.TIME_MILLISECONDS);
}
}
this.updateTimeText();
if(!this.isTimeOver && this.timeLeft < 0)
if(!this.isTimeOver && this.leftTime < 0)
this.timeOver();
}
Timer.prototype.timeOver = function() {
this.isTimeOver = true;
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
console.log("time over");
// xhr = new XMLHttpRequest();
// xhr.open('POST', 'delete_last_timestamp.php', true);
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// var param = 'UserID=' + playerUserID;
// xhr.send(param);
this.isTimeOver = true;
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
this.resetLeftTimeToServer();
}
Timer.prototype.getNowTime = function() {
@@ -443,15 +468,18 @@ Timer.prototype.timePlus = function(timePlusSecond, type) {
}
// console.log(timeAmount);
this.timeLeft += timeAmount;
this.leftTime += timeAmount;
var maxTime = 99 * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE * Timer.TIME_SECONDS_FOR_MINUTE;
if(this.timeLeft > maxTime)
this.timeLeft = maxTime;
if(this.leftTime > maxTime)
this.leftTime = maxTime;
this.updateTimeText();
if(!this.isTimerGoingOn)
this.sendStartTimeToServer(this.timeLeft);
this.sendTimeLeftToServer();
if(!this.isTimerGoingOn) {
this.startTime = this.leftTime;
this.updateStartTimeToServer();
} else {
this.updateLeftTimeToServer();
}
}
Timer.prototype.timeMinus = function(timeMinusSecond, type) {
@@ -467,37 +495,45 @@ Timer.prototype.timeMinus = function(timeMinusSecond, type) {
}
// console.log(timeAmount);
this.timeLeft -= timeAmount;
if(this.timeLeft < 0)
this.timeLeft = 0;
this.leftTime -= timeAmount;
if(this.leftTime < 0)
this.leftTime = 0;
this.updateTimeText();
if(!this.isTimerGoingOn)
this.sendStartTimeToServer(this.timeLeft);
this.sendTimeLeftToServer();
if(!this.isTimerGoingOn) {
this.startTime = this.leftTime;
this.updateStartTimeToServer();
} else {
this.updateLeftTimeToServer();
}
}
Timer.prototype.setTime =function(sec) {
// console.log("time up : " + min);
this.timeLeft += sec;
Timer.prototype.setTime =function(timeSecond) {
this.leftTime = timeSecond;
this.updateTimeText();
if(!this.isTimerGoingOn) {
this.startTime = this.leftTime;
this.updateStartTimeToServer();
} else {
this.updateLeftTimeToServer();
}
}
Timer.prototype.updateTimeText = function() {
var secondsForHour = Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE;
var timeLeftHour = parseInt(this.timeLeft / secondsForHour);
var timeLeftMinute = parseInt((this.timeLeft % secondsForHour) / Timer.TIME_SECONDS_FOR_MINUTE);
var timeLeftSecond = this.timeLeft % Timer.TIME_SECONDS_FOR_MINUTE;
var leftTimeHour = parseInt(this.leftTime / secondsForHour);
var leftTimeMinute = parseInt((this.leftTime % secondsForHour) / Timer.TIME_SECONDS_FOR_MINUTE);
var leftTimeSecond = this.leftTime % Timer.TIME_SECONDS_FOR_MINUTE;
this.timeHourText.text = this.getTimeWithTimeFormat(timeLeftHour, Timer.TYPE_HOUR);
// console.log(this.timeLeft);
this.timeHourText.text = this.getTimeWithTimeFormat(leftTimeHour, Timer.TYPE_HOUR);
// console.log(this.leftTime);
// console.log(this.timeHourText.text);
this.timeMinuteText.text = this.getTimeWithTimeFormat(timeLeftMinute, Timer.TYPE_MINUTE);
this.timeSecondText.text = this.getTimeWithTimeFormat(timeLeftSecond, Timer.TYPE_SECOND);
this.timeMinuteText.text = this.getTimeWithTimeFormat(leftTimeMinute, Timer.TYPE_MINUTE);
this.timeSecondText.text = this.getTimeWithTimeFormat(leftTimeSecond, Timer.TYPE_SECOND);
// this.updateTimeVariables();
// this.timerText.text = this.getTimeWithTimeFormat();
}
@@ -518,7 +554,7 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) {
return this.getTwoDigitNumber(timeValue);
}
if(this.timeLeft < 0) {
if(this.leftTime < 0) {
return "-" + this.getTwoDigitNumber(timeValue);
} else {
return this.getTwoDigitNumber(timeValue);
@@ -526,25 +562,55 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) {
}
Timer.prototype.setStartTime = function(time) {
this.startTime = time;
Timer.prototype.sendStartTimeToServer = function(time) {
this.timeStart = time;
if(!this.isTimerGoingOn) {
this.leftTime = this.startTime;
this.updateTimeText();
}
// send to server
console.log("send to server : " + this.timeStart);
this.updateStartTimeToServer();
}
Timer.prototype.sendTimeLeftToServer = function() {
return;
// console.log(this.timeLeft);
// console.log(playerUserID);
xhr = new XMLHttpRequest();
xhr.open('POST', 'make_last_timestamp.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var param = 'UserID=' + playerUserID + '&Time=' + this.timeLeft;
xhr.send(param);
Timer.prototype.updateStartTimeToServer = function() {
// send to server
console.log("send start time to server : " + this.startTime);
this.dbConnectManager.updateLicenseStartTime(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
this.startTime,
(function(replyJson) { console.log(replyJson); }).bind(this),
(function(replyJson) { console.log(replyJson); })
);
}
Timer.prototype.resetLeftTimeToServer = function() {
console.log("send left time to server : " + this.leftTime);
this.dbConnectManager.updateLicenseLeftTime(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
0,
(function(replyJson) { console.log(replyJson); }).bind(this),
(function(replyJson) { console.log(replyJson); })
);
},
Timer.prototype.updateLeftTimeToServer = function() {
console.log("send left time to server : " + this.leftTime);
this.dbConnectManager.updateLicenseLeftTime(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
this.leftTime,
(function(replyJson) { console.log(replyJson); }).bind(this),
(function(replyJson) { console.log(replyJson); })
);
},