UNPKG

@real_one_chess_king/game-logic

Version:
22 lines 519 B
export 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; } } //# sourceMappingURL=timer.js.map