因此,我设置了一个Clicker游戏,当您单击一个按钮时,您会获得1分,但是我很难设置第二个按钮,而该按钮的花费是购买点数,然后与该按钮绑定的功能应该开始增加您的得分每秒1个。
我对此感到厌倦(忽略函数名称/ if语句):
function wolfXpUp(wolfChecked) {
clearInterval(wolfInterval);
if (wolfChecked && WolfCexp < WolfMexp) {
wolfInterval = setInterval(function () { wolfXpUp(wolfChecked); }, 200);
WolfCexp = WolfCexp + 1;
document.getElementById("WolfCexp").innerHTML = WolfCexp;
我试图重新格式化它,以便它可以与我的buy ant功能一起使用,但我无法使其正常工作。设置的时间间隔应仅在购买该功能后才能结束。
JavaScript:
var cookies = 0;
var Strength = 1;
function cookieClick(){
cookies = cookies + Strength;
document.getElementById("cookies").innerHTML = cookies;
checkCursor()
};
var ants = 0;
function buyAnt(){
var antCost = Math.floor(10 * Math.pow(1.1,ants)); //works out the
cost of this cursor
if(cookies >= antCost){ //checks
that the player can afford the cursor
ants = ants + 1; //increases
number of cursors
cookies = cookies - antCost; //removes
the cookies spent
document.getElementById('ants').innerHTML = ants; //updates the
number of cursors for the user
document.getElementById('cookies').innerHTML = cookies; //updates
the number of cookies for the user
};
var nextCost = Math.floor(10 * Math.pow(1.1,ants)); //works out the
cost of the next cursor
document.getElementById('antCost').innerHTML = nextCost; //updates the
cursor cost for the user
};
HTML:
<span id="cookies">0</span>
<br />
<span id="rebirths">0</span>
<br />
<button onclick="cookieClick(); Strengthexp()">Click Me!
</button>
<br />
Cost: 10mp <button id="BigClickBtn"
onclick="Bigclick()">BigClick</button>
<br />
Cost: <span id="antCost">10</span> <button onclick="buyAnt()"
id="antCostBtn" >Buy Ant</button> <span id="ants">0</span>
我希望在购买了cookie的ant函数之后,每秒会开始增加1。但是我当前的输出无法正常工作。