我創建一個遊戲,現在的代碼,當我點擊攻擊,敵人電源隨機降低對單一的點擊減,但我想同樣用的球員,但隨機值應該是不同的從一個在敵人..如果可能的話,可以有ASO是治療選項,隨意提高球員能力和太降低,因爲敵人仍然是進攻如何添加和使用兩個不同的值
appearence(電流):http://amerish.webs.com/amerish/testgame.html
代碼:
<head>
<script>
var playerHealth=100;
var enemyHealth=100;
var strength=10;
function begin(){
document.getElementById'playerhealth').innerHTML= playerHealth;
document.getElementById('enemyhealth').innerHTML =enemyHealth;
}
function hitEnemy(){
var attack=Math.floor(Math.random()*20 +strength);
enemyHealth =enemyHealth - attack;
document.getElementById('damage').innerHTML= attack;
document.getElementById('enemyhealth').innerHTML =enemyHealth;
}
</script>
<body onload="begin()">
<input type="button" name="doit" id="doit" value="Attack!"
onclick="hitEnemy();">
<br/
<span>playerhealth</span>
<div style="font-ize:3em;"id="playerhealth"></div>
<span>enemyhealth</span>
<div style="font-size:3em;"id="enemyhealth"></div>
<br />
<span>You Did:</span><span style="font-size:3em;"id="damage"></span>
<span>damage</span>
</body>
請張貼代碼在你的問題 –
很難從移動做的,感謝 –