import { Game } from "./game";

export class TimedGame extends Game {
    constructor(time) {
        super();
        this._timeoutId = undefined;
        this.timeout = time;
    }

    start() {
        super.start();
        this._timeoutId = setInterval(() => {
            console.log("time end");
            this.end(this._win);
        }, this.timeout);
    }

    reset() {
        super.reset();
        clearTimeout(this._timeoutId);
        this._timeoutId = undefined;
    }

    end(status) {
        super.end(status);
        clearTimeout(this._timeoutId);
    }
}
