@real_one_chess_king/game-logic
Version:
R.O.C.K. chess game logic
26 lines • 636 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timer = void 0;
class Timer {
timeLeft;
onTimeEnd;
constructor(timeLeft, //MS
onTimeEnd) {
this.timeLeft = timeLeft;
this.onTimeEnd = onTimeEnd;
}
lastTimestamp = 0;
timeout;
start() {
this.lastTimestamp = Date.now();
this.timeout = setTimeout(() => {
this.onTimeEnd();
}, this.timeLeft);
}
pause() {
clearTimeout(this.timeout);
this.timeLeft -= Date.now() - this.lastTimestamp;
}
}
exports.Timer = Timer;
//# sourceMappingURL=timer.js.map