export enum TimerType { countDown, CountUp, } export default class Timer { private _timer: number = 0; private _paused: boolean = true; private _type: TimerType; constructor(type: TimerType) { this._type = type; } public get time() { return this._timer; } public get timeRound() { return Math.round(this._timer); } public set time(value: number) { this._timer = value; } public update(dt: number): void { if (this._paused) return; if (this._type == TimerType.CountUp) { this._timer += dt; } else { this._timer -= dt; } } public startCount() { this._paused = false; } public stopCount() { this._paused = true; } }