我有这个:
Strength: Lv <span id="Strengthlv">1</span> <span
id="StrengthCexp">0</span> / <span id="StrengthMexp">100</span>
<br />
显示力量:Lv 1 0/100
我正在尝试做一个函数(以后我希望它与我的Cookie答题器绑定,每次按该按钮可获得1 exp的强度),每次按此按钮可获得1 exp。然后它一直上升直到与最大exp相同。
我已经尝试了我在以前的功能中所做的事情(我为Cookie Clicker做的事情),但结果却不一样。
我的JavaScript代码:
var Strength = 1;
var Strengthlv = 1;
var StrengthCexp = 0;
var StrengthMexp = 100;
var Magic = 1;
var MagicCexp = 0;
var MagicMexp = 100;
function Strengthexp(){
if (StrengthCexp != StrengthMexp){
StrengthCexp = StrengthCexp + 1;
document.getElementById("StrengthCexp").innerHTML = StrengthCexp;
}else{
Strengthlv = Strengthlv + 1
StrengthCexp = 0
Strength = Strength + 1
document.getElementById('Strengthlv').innerHTML = Strengthlv;
document.getElementById('StrengthCexp').innerHTML = StrengthCexp;
document.getElementById('Strength').innerHTML = Strength;
}
var NextMaxStrengthExp = StrengthMexp * 1.5;
document.getElementById('StrengthMexp').innerHTML =
NextMaxStrengthExp;
}
用于测试onclick gain exp是否有效的HTML代码:
<button onclick="Strengthexp()">Click Me!</button>
<br />
我希望单击该按钮后,StrengthCexp会继续增加1,直到StrengthCexp = StrengthMexp。然后,它将lv增加1,强度数量增加1,然后将StrengthCexp重置为零,然后将StrengthMexp更改为大于第一个数量。实际输出它没有做任何onclick,所以我觉得我做错了。
最佳答案
var Strength = 1;
var Strengthlv = 1;
var StrengthCexp = 0;
var StrengthMexp = 100;
var Magic = 1;
var MagicCexp = 0;
var MagicMexp = 100;
var NextMaxStrengthExp = StrengthMexp;
function Strengthexp(){
if (StrengthCexp <= NextMaxStrengthExp){
StrengthCexp = StrengthCexp + 1;
document.getElementById("StrengthCexp").innerHTML = StrengthCexp;
}else{
Strengthlv = Strengthlv + 1
StrengthCexp = 0
Strength = Strength + 1
NextMaxStrengthExp = NextMaxStrengthExp * 1.5;
document.getElementById('StrengthMexp').innerHTML = NextMaxStrengthExp;
document.getElementById('Strengthlv').innerHTML = Strengthlv;
document.getElementById('StrengthCexp').innerHTML = StrengthCexp;
document.getElementById('Strength').innerHTML = Strength;
}
}