因此,我有一个工作按钮,可以将exp添加到我的总exp中,然后有机会在单击时给您1枚青铜。我想在我的矿山> = 10的时候添加白银。
我尝试过另外一个if语句(可能是错误的格式),即if(mininglv> = 10 && mininglv <20),然后重复上述步骤以获取青铜并挖掘exp,然后添加一个随机的白银元素。我不知道如何在单击按钮的机会中添加白银,并赋予它0.25的机会。
这是我的javaScript代码:
var Bronzechance = 0.5
var Silverchance = 0.25
function Miningaction() {
if (MiningCexp < NextMaxMiningExp && Mininglv >= 1) {
MiningCexp = MiningCexp + 1;
if (Math.random() < Bronzechance)
Bronze = Bronze + 1
document.getElementById("Bronze").innerHTML = Bronze;
document.getElementById("MiningCexp").innerHTML = MiningCexp;
}
if(Mininglv >=10 && Mininglv <20){
MiningCexp = MiningCexp + 1;
if (Math.random() < Silverchance){
Silver = Silver + 1;
}
document.getElementById("Bronze").innerHTML = Bronze;
document.getElementById("Silver").innerHTML = Silver;
document.getElementById("MiningCexp").innerHTML = MiningCexp;
} else {
Mininglv = Mininglv + 1
MiningCexp = 0
Mining = Mining + 1
NextMaxMiningExp = NextMaxMiningExp * 1.5;
document.getElementById('MiningMexp').innerHTML = NextMaxMiningExp;
document.getElementById('Mininglv').innerHTML = Mininglv;
document.getElementById('MiningCexp').innerHTML = MiningCexp;
document.getElementById('Mining').innerHTML = Mining;
}
}
HTML代码:
Bronze: <span id="Bronze">0</span>
<br />
Silver: <span id="Bronze">0</span>
<button onclick="Miningaction()"><img src="cave.png" alt="cave"
height="45" width="45"> </button>
我希望在采矿级别为10或更高但不高于20的情况下单击按钮时,有机会给您白银。但是实际输出我无法让银掉下来。
答案 0 :(得分:1)
这是您要找的吗?
var Bronzechance = 0.5;
var Silverchance = 0.25;
var Bronze = 0;
var Silver = 0;
function Miningaction() {
MiningCexp = MiningCexp + 1;
if (Mininglv >= 1) {
if (Math.random() < Bronzechance)
Bronze = Bronze + 1;
document.getElementById("Bronze").innerHTML = Bronze;
document.getElementById("MiningCexp").innerHTML = MiningCexp;
}
if(Mininglv >=10 && Mininglv < 20){
if (Math.random() < Silverchance){
Silver = Silver + 1;
}
document.getElementById("Silver").innerHTML = Silver;
document.getElementById("MiningCexp").innerHTML = MiningCexp;
if(MiningCexp >= NextMaxMiningExp)
Mininglv = Mininglv + 1;
MiningCexp = 0;
Mining = Mining + 1;
NextMaxMiningExp = NextMaxMiningExp * 1.5;
document.getElementById('MiningMexp').innerHTML = NextMaxMiningExp;
document.getElementById('Mininglv').innerHTML = Mininglv;
document.getElementById('MiningCexp').innerHTML = MiningCexp;
document.getElementById('Mining').innerHTML = Mining;
}
}