Fix: startTime, resetTime

This commit is contained in:
2018-12-10 23:05:51 +09:00
parent 6becc05aab
commit 5bd5f0809e
+115 -51
View File
@@ -6,9 +6,6 @@ function Timer() {
bar.beginFill(0x202020); bar.beginFill(0x202020);
bar.drawRect(0, 60, GAME_SCREEN_SIZE.x, 240); bar.drawRect(0, 60, GAME_SCREEN_SIZE.x, 240);
// Timer
this.timerCenterX = game.world.centerX + Timer.Timer_CENTER_OFFSET_X;
this.timerCenterY = 183;
this.makeTimer(); this.makeTimer();
this.makeTimerButtons(); this.makeTimerButtons();
@@ -16,20 +13,46 @@ function Timer() {
this.resetButton = this.makeResetButton(); this.resetButton = this.makeResetButton();
this.pauseButton = this.makePauseButton(); this.pauseButton = this.makePauseButton();
this.showButton(this.pauseButton, false); this.showButton(this.pauseButton, false);
// this.showButton(this.pauseButton, true);
this.playButton = this.makePlayButton(); this.playButton = this.makePlayButton();
this.loadDataFromServer();
this.startTimer();
} }
Timer.prototype.initVariables = function() { Timer.prototype.initVariables = function() {
this.isTimerGoingOn = false;
this.timeStart = 0
this.timeLeft = 0;
this.timerEvent = null;
this.prevTime = null; this.prevTime = null;
this.timerCenterX = game.world.centerX + Timer.Timer_CENTER_OFFSET_X;
this.timerCenterY = 183;
this.hour10ButtonPosX = this.timerCenterX - 285 - 90;
this.hour1ButtonPosX = this.timerCenterX - 195 - 90;
this.minute10ButtonPosX = this.timerCenterX - 45 - 90;
this.minute1ButtonPosX = this.timerCenterX + 45 - 90;
this.timePlusButtonPosY = this.timerCenterY - 82;
this.timeMinusButtonPosY = this.timerCenterY + 75;
}
Timer.prototype.loadDataFromServer = function() {
this.timeStart = Timer.TIME_DEFAULT_SEC;
this.timeLeft = Timer.TIME_DEFAULT_SEC; this.timeLeft = Timer.TIME_DEFAULT_SEC;
this.timerEvent = null; this.updateTimeText();
// if( there is saved time record) {
// this.isTimerGoingOn = false;
// this.setTimerTextColor(0xffffff);
// }
this.setTimerTextColor(0xc04040);
} }
Timer.prototype.makeTimer = function() { Timer.prototype.makeTimer = function() {
@@ -41,43 +64,34 @@ Timer.prototype.makeTimer = function() {
} }
Timer.prototype.makeTimerButtons = function() { Timer.prototype.makeTimerButtons = function() {
var hour10PosX = this.timerCenterX - 285 - 90;
var hour1PosX = this.timerCenterX - 195 - 90;
var minute10PosX = this.timerCenterX - 45 - 90;
var minute1PosX = this.timerCenterX + 45 - 90;
var plusPosY = this.timerCenterY - 82;
var minusPosY = this.timerCenterY + 75;
// hour button // hour button
this.hourPlus10Button = this.makeTimePlusButton(hour10PosX, plusPosY, "▲", this.hourPlus10Button = this.makeTimePlusButton(this.hour10ButtonPosX, this.timePlusButtonPosY, "▲",
(function() { this.timePlus(10, Timer.TYPE_HOUR); }).bind(this) (function() { this.timePlus(10, Timer.TYPE_HOUR); }).bind(this)
); );
// this.hourPlus10Button.setInputEnabled(false); // this.hourPlus10Button.setInputEnabled(false);
this.hourMinus10Button = this.makeTimeMinusButton(hour10PosX, minusPosY, "▼", this.hourMinus10Button = this.makeTimeMinusButton(this.hour10ButtonPosX, this.timeMinusButtonPosY, "▼",
(function() { this.timeMinus(10, Timer.TYPE_HOUR); }).bind(this) (function() { this.timeMinus(10, Timer.TYPE_HOUR); }).bind(this)
); );
this.hourPlus1Button = this.makeTimePlusButton(hour1PosX, plusPosY, "▲", this.hourPlus1Button = this.makeTimePlusButton(this.hour1ButtonPosX, this.timePlusButtonPosY, "▲",
(function() { this.timePlus(1, Timer.TYPE_HOUR); }).bind(this) (function() { this.timePlus(1, Timer.TYPE_HOUR); }).bind(this)
); );
this.hourMinus1Button = this.makeTimeMinusButton(hour1PosX, minusPosY, "▼", this.hourMinus1Button = this.makeTimeMinusButton(this.hour1ButtonPosX, this.timeMinusButtonPosY, "▼",
(function() { this.timeMinus(1, Timer.TYPE_HOUR); }).bind(this) (function() { this.timeMinus(1, Timer.TYPE_HOUR); }).bind(this)
); );
// minute button // minute button
this.minutePlus10Button = this.makeTimePlusButton(minute10PosX, plusPosY, "▲", this.minutePlus10Button = this.makeTimePlusButton(this.minute10ButtonPosX, this.timePlusButtonPosY, "▲",
(function() { this.timePlus(10, Timer.TYPE_MINUTE); }).bind(this) (function() { this.timePlus(10, Timer.TYPE_MINUTE); }).bind(this)
); );
this.minuteMinus10Button = this.makeTimeMinusButton(minute10PosX, minusPosY, "▼", this.minuteMinus10Button = this.makeTimeMinusButton(this.minute10ButtonPosX, this.timeMinusButtonPosY, "▼",
(function() { this.timeMinus(10, Timer.TYPE_MINUTE); }).bind(this) (function() { this.timeMinus(10, Timer.TYPE_MINUTE); }).bind(this)
); );
this.minutePlus1Button = this.makeTimePlusButton(minute1PosX, plusPosY, "▲", this.minutePlus1Button = this.makeTimePlusButton(this.minute1ButtonPosX, this.timePlusButtonPosY, "▲",
(function() { this.timePlus(1, Timer.TYPE_MINUTE); }).bind(this) (function() { this.timePlus(1, Timer.TYPE_MINUTE); }).bind(this)
); );
this.minuteMinus1Button = this.makeTimeMinusButton(minute1PosX, minusPosY, "▼", this.minuteMinus1Button = this.makeTimeMinusButton(this.minute1ButtonPosX, this.timeMinusButtonPosY, "▼",
(function() { this.timeMinus(1, Timer.TYPE_MINUTE); }).bind(this) (function() { this.timeMinus(1, Timer.TYPE_MINUTE); }).bind(this)
); );
} }
@@ -114,7 +128,7 @@ Timer.prototype.makeResetButton = function() {
return new RoundRectButton( return new RoundRectButton(
setting, setting,
null, "C", null, "C",
(function() { console.log("리셋"); }).bind(this) (function() { this.resetTimer(); }).bind(this)
); );
} }
@@ -151,13 +165,13 @@ Timer.prototype.makePlayButton = function() {
return new RoundRectButton( return new RoundRectButton(
setting, setting,
null, "▶", null, "▶",
(function() { console.log("플레이"); }).bind(this) (function() { this.startTimer(); }).bind(this)
); );
} }
Timer.prototype.makePauseButton = function() { Timer.prototype.makePauseButton = function() {
var setting = new RoundRectButtonSetting(0, 0, 0, 0); var setting = new RoundRectButtonSetting(0, 0, 0, 0);
setting.x = game.world.width - 200; setting.x = game.world.width - 100;
setting.y = this.timerCenterY; setting.y = this.timerCenterY;
setting.width = 120; setting.width = 120;
setting.height = 120; setting.height = 120;
@@ -189,7 +203,7 @@ Timer.prototype.makePauseButton = function() {
return new RoundRectButton( return new RoundRectButton(
setting, setting,
null, "∥", null, "∥",
(function() { console.log("일시 정지"); }).bind(this) (function() { this.pauseTimer(); }).bind(this)
); );
} }
@@ -202,22 +216,74 @@ Timer.prototype.showButton = function(button, flag) {
button.move(backupPosX, -200); button.move(backupPosX, -200);
} }
Timer.prototype.hideTimerButtons = function() {
this.hourPlus10Button.move(-200, -200);
this.hourPlus1Button.move(-200, -200);
this.hourMinus10Button.move(-200, -200);
this.hourMinus1Button.move(-200, -200);
this.minutePlus10Button.move(-200, -200);
this.minutePlus1Button.move(-200, -200);
this.minuteMinus10Button.move(-200, -200);
this.minuteMinus1Button.move(-200, -200);
}
Timer.prototype.showTimerButtons = function() {
this.hourPlus10Button.move(this.hour10ButtonPosX, this.timePlusButtonPosY);
this.hourMinus10Button.move(this.hour10ButtonPosX, this.timeMinusButtonPosY);
this.hourPlus1Button.move(this.hour1ButtonPosX, this.timePlusButtonPosY);
this.hourMinus1Button.move(this.hour1ButtonPosX, this.timeMinusButtonPosY);
this.minutePlus10Button.move(this.minute10ButtonPosX, this.timePlusButtonPosY);
this.minuteMinus10Button.move(this.minute10ButtonPosX, this.timeMinusButtonPosY);
this.minutePlus1Button.move(this.minute1ButtonPosX, this.timePlusButtonPosY);
this.minuteMinus1Button.move(this.minute1ButtonPosX, this.timeMinusButtonPosY);
}
Timer.prototype.setTimerTextColor = function(color) {
this.timeHourText.tint = color;
this.timeHourMinuteSeperator.tint = color;
this.timeMinuteText.tint = color;
this.timeMinuteSecondSeperator.tint = color;
this.timeSecondText.tint = color;
}
Timer.prototype.startTimer = function() { Timer.prototype.startTimer = function() {
this.isTimerGoingOn = true;
this.setTimerTextColor(0x40c0c0);
this.updateTimeText(); this.updateTimeText();
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS); ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
this.prevTime = this.getNowTime(); this.prevTime = this.getNowTime();
this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this); this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this);
this.showButton(this.playButton, false);
this.showButton(this.pauseButton, true);
this.hideTimerButtons();
} }
Timer.prototype.pauseTimer = function() { Timer.prototype.pauseTimer = function() {
this.setTimerTextColor(0xa0a0a0);
this.updateTimeText(); this.updateTimeText();
CancelNotifyTimeOver(); CancelNotifyTimeOver();
game.time.events.remove(this.timerEvent); game.time.events.remove(this.timerEvent);
this.showButton(this.playButton, true);
this.showButton(this.pauseButton, false);
this.showTimerButtons();
}
Timer.prototype.resetTimer = function() {
this.timeLeft = this.timeStart;
this.pauseTimer();
this.isTimerGoingOn = false;
this.setTimerTextColor(0xc04040);
// this.loadDataFromServer();
} }
Timer.prototype.tickTimeLeft = function() { Timer.prototype.tickTimeLeft = function() {
@@ -235,8 +301,10 @@ Timer.prototype.tickTimeLeft = function() {
this.updateTimeText(); this.updateTimeText();
if(this.timeLeft < 0) if(this.timeLeft < 0) {
this.setTimerTextColor(0xff0000);
this.timeOver(); this.timeOver();
}
} }
Timer.prototype.timeOver = function() { Timer.prototype.timeOver = function() {
@@ -368,13 +436,15 @@ Timer.prototype.timePlus = function(timePlusSecond, type) {
break; break;
} }
console.log(timeAmount); // console.log(timeAmount);
this.timeLeft += timeAmount; this.timeLeft += timeAmount;
var maxTime = 99 * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE * Timer.TIME_SECONDS_FOR_MINUTE; var maxTime = 99 * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE * Timer.TIME_SECONDS_FOR_MINUTE;
if(this.timeLeft > maxTime) if(this.timeLeft > maxTime)
this.timeLeft = maxTime; this.timeLeft = maxTime;
this.updateTimeText(); this.updateTimeText();
if(!this.isTimerGoingOn)
this.sendStartTimeToServer(this.timeLeft);
this.sendTimeLeftToServer(); this.sendTimeLeftToServer();
} }
@@ -392,12 +462,14 @@ Timer.prototype.timeMinus = function(timeMinusSecond, type) {
break; break;
} }
console.log(timeAmount); // console.log(timeAmount);
this.timeLeft -= timeAmount; this.timeLeft -= timeAmount;
if(this.timeLeft < 0) if(this.timeLeft < 0)
this.timeLeft = 0; this.timeLeft = 0;
this.updateTimeText(); this.updateTimeText();
if(!this.isTimerGoingOn)
this.sendStartTimeToServer(this.timeLeft);
this.sendTimeLeftToServer(); this.sendTimeLeftToServer();
} }
@@ -409,23 +481,6 @@ Timer.prototype.setTime =function(sec) {
this.updateTimeText(); this.updateTimeText();
} }
Timer.prototype.timeUp = function(sec) {
// console.log("time up : " + sec);
this.timeLeft += sec;
this.updateTimeText();
// this.sendTimeLeftToServer();
}
Timer.prototype.timeDown = function(sec) {
// console.log("time down : " + sec);
this.timeLeft -= sec;
if(this.timeLeft < 0)
this.timeLeft = 0;
this.updateTimeText();
// this.sendTimeLeftToServer();
}
Timer.prototype.updateTimeText = function() { Timer.prototype.updateTimeText = function() {
var secondsForHour = Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE; var secondsForHour = Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE;
@@ -466,6 +521,15 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) {
} }
} }
Timer.prototype.sendStartTimeToServer = function(time) {
this.timeStart = time;
// send to server
console.log(this.timeStart);
}
Timer.prototype.sendTimeLeftToServer = function() { Timer.prototype.sendTimeLeftToServer = function() {
return; return;