私は最初のテストに行って何らかの理由で敵のカウンターにダメージを与える何らかの理由でブラウザのゲームのアイデアを乱してしまった。数学ジェネレーターは何とか戦闘ボタンを再表示するのを止めるだろうか?(HaimheadFunction { )何らかの理由でdivが再表示されないことがありますか?
私はコードの汚れをお詫びします、それはちょうど大まかなものでした。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<script>
var enemy = 100;
if (enemy > 0) {
document.write(enemy);
function fightFunction() {
document.getElementById('2ndmenu').style.display = "block";
document.getElementById('1stmenu').style.display = "none";
}
function headsmashFunction() {
document.getElementById('headsmashmenu').style.display = "block";
document.getElementById('2ndmenu').style.display = "none";
}
function punchFunction() {
document.getElementById('punchmenu').style.display = "block";
document.getElementById('2ndmenu').style.display = "none";
}
function kickFunction() {
document.getElementById('kickmenu').style.display = "block";
document.getElementById('2ndmenu').style.display = "none";
}
function HaimheadFunction() {
document.getElementById('1stmenu').style.display = "block";
document.getElementById('headsmashmenu').style.display = "none";
var number = Math.floor((Math.random() * 100));
document.write(number);
if (number < 30) {
document.write('damage= 30!');
enemy = enemy - 100 ;
document.write(enemy);
}
else{
document.write('you missed');
}
}
}
else{
document.write('<p> you win! </p>');
}
</script>
<div id="1stmenu" style="display: block;">
<button onclick="fightFunction()">FIGHT</button>
</div>
<div id="2ndmenu" style="display: none;">
<button onclick="headsmashFunction()">Headsmash</button>
<button onclick="punchFunction()">Punch</button>
<button onclick="kickFunction()">kick</button>
</div>
<div id="headsmashmenu" style="display: none;">
<button onclick="HaimheadFunction()">AIM FOR HEAD</button>
<button onclick="HaimbodyFunction()">AIM FOR BODY</button>
<button onclick="HaimlegFunction()">AIM FOR LEGS</button>
</div>
<div id="punchmenu" style="display: none;">
<button onclick="BaimheadFunction()">AIM FOR HEAD</button>
<button onclick="BaimbodyFunction()">AIM FOR BODY</button>
<button onclick="BaimlegFunction()">AIM FOR LEGS</button>
</div>
<div id="kickmenu" style="display: none;">
<button onclick="LaimheadFunction()">AIM FOR HEAD</button>
<button onclick="LaimbodyFunction()">AIM FOR BODY</button>
<button onclick="LaimlegFunction()">AIM FOR LEGS</button>
</div>
</body>
</html>
jQueryの使用を検討してください:DOM内の要素の更新などの操作を大幅に簡素化します。 – sal
はい、私は今jqueryを使用しています!再度、感謝します! –