寻找重置“数学”函数的方法

Looking for a Way to Reset the `Math` Function

本文关键字:函数 方法 数学 寻找      更新时间:2023-09-26

我正在尝试为我的孩子制作一个依赖于计数器的游戏。 我的计数器工作正常,除了在第三次通关时计数器的速度翻倍。

前两个玩计数器一次递增 1 秒,然后第三轮它一次递增两秒,

然后第四轮它一次递增 4 秒,依此类推......

我的代码:

timeLeft = {
    total: gameTime,
    mins: function(){
        return Math.floor(timeLeft.total/60);
    },
    secs: function(){
        tempSecs=timeLeft.total-(60*timeLeft.mins());
        if (tempSecs < 10) {
            tempSecs='0'+tempSecs;
        }
        return tempSecs;
    }
};
function timer(){
    $('#time').html(timeLeft.mins() + " : " + timeLeft.secs());
    timeLeft.total=timeLeft.total-1;
    if (timeLeft.total>=0) {
        setTimeout(function(){
            timer()}, 1000);
        }
    }
};

将超时设置为变量:var myTimeout = setTimeout...,重置游戏时,运行clearTimeout(myTimeout);