Javascript 在我按下重生键后,我想把总数加10到2。不起作用
所以我正在做一个游戏,我想当我按下重生键的时候,生命值和法力值会上升10 我尝试了一些方法,包括按照我所做的增加饼干数量,但似乎没有任何效果 这是我的html代码:Javascript 在我按下重生键后,我想把总数加10到2。不起作用,javascript,html,Javascript,Html,所以我正在做一个游戏,我想当我按下重生键的时候,生命值和法力值会上升10 我尝试了一些方法,包括按照我所做的增加饼干数量,但似乎没有任何效果 这是我的html代码: <span id="cookies">0</span> <br /> <button onclick="cookieClick(1)">Click Me!</button> &l
<span id="cookies">0</span>
<br />
<button onclick="cookieClick(1)">Click Me!</button>
<br />
Cost: 50 <button id="BigClickBtn"
onclick="cookieClick(50)">BigClick</button>
<br />
Cost: <span id="cursorCost">10</span> <button
id="cursorCostBtn" onclick="buyCursor()">Buy Cursor</button>
<br />
Cost: <span id="catCost">50</span> <button
onclick="buyCat()" id="catCostBtn">Buy Cat</button>
<br />
Cost: <span id="dogCost">100</span> <button
onclick="buyDog()" id="dogCostBtn">Buy Dog</button>
<br />
Cost: <span id="humanCost">200</span> <button
onclick="buyHuman()" id="humanCostBtn">Buy Human</button>
<br />
Cost: <span id="rebirthCost">10</span> <button
onclick="buyRebirth()" id="rebirthCostBtn">Rebirth</button>
<br />
Hp:<span id="HitPoints">0</span> Mp:<span
id="ManaPoints">0</span>
我希望我的hp和mp在按下“重生”时更新为hp:10和mp:10。目前,实际输出为Hp:0和Mp:0(无更改)。参考错误:
未定义生命点,这将中断代码的其余部分。例如,一个打字错误…对不起,我错过了一些正在修复的东西,因为我忘了把那个部分放进去。我在我的代码中有这一点,这不是我的意思,你将生命点
误输入为生命点
,该值被输入到的innerHTML
中,这就破坏了代码的其余部分。例如,一个打字错误…对不起,我错过了一些正在修复的东西,因为我忘了把那个部分放进去。我在我的代码中有这一点,这不是我的意思,你将生命点
误输入为生命点
,该值被输入生命点
的innerHTML
。我修正了当我按下“重生”按钮时,法力或生命值仍然没有增加的问题
}
var rebirths = 0;
var HitPoints = 0;
var ManaPoints = 0;
function buyRebirth() {
var rebirthCost = Math.floor(10 * Math.pow(1.5, rebirths));
if (cookies >= rebirthCost) {
HitPoints = HitPoints + 10;
ManaPoints = ManaPoints + 10;
rebirths = rebirths + 1;
if (rebirths>1)
rebirths = rebirths + 1;
cookies = cookies - rebirthCost;
document.getElementById('rebirths').innerHTML = rebirths;
//updates the number of cursors for the user
document.getElementById('cookies').innerHTML = cookies; //updates
the number of cookies for the user
document.getElementById("HitPoints").innerHTML = Hitpoints;
document.getElementById("ManaPoints").innerHTML = ManaPoints;
}
var nextCost = Math.floor(10 * Math.pow(1.5, rebirths)); //works out
the cost of the next cursor
document.getElementById('rebirthCost').innerHTML = nextCost; //updates
the cursor cost for the user
checkCursor()
}