diff --git a/mogura.html b/mogura.html index 8a3a383..6447dc2 100644 --- a/mogura.html +++ b/mogura.html @@ -19,8 +19,6 @@

- diff --git a/mogura.js b/mogura.js index a8f03da..a1c02bf 100755 --- a/mogura.js +++ b/mogura.js @@ -2,7 +2,7 @@ (() => { var timer = null, count = 10; point = 0; ana=6; - var tataki = ana+1; tataki2 = ana+1; //存在しないdivs添字 + var hit = ana+1; hit_new = ana+1; //存在しないdivs添字にしたくて+1 var msgArea = null; ptArea = null; function countdown() { console.log('countdown'); @@ -23,35 +23,36 @@ function stop() { console.log('stop'); alert("しゅーーりょーー"); - ptArea.innerText = `今回のスコア: ${point}回`; //ptArea + ptArea.innerText = `今回のスコア: ${point}回`; ptArea.style.textDecoration = "underline"; //atari.innerHTML = "" //もぐら画像削除 } function whack() { // whack-a-mole(英):モグラ叩き console.log('whack'); - if (count>=0) { // 時間すぎると加算されない + if (count>=0) { // 制限時間すぎたら動かさない point ++; ptArea.innerText = `現在: ${point}回`; ptArea.style.textDecoration = "none"; atari.innerHTML = ""; //もぐら画像削除 atari.removeEventListener('click', whack); //イベントリスナー削除 - rand(); + // ここで削除しないと一度atariになった空のdivを押してもatari判定になる + rand(); } } function rand() { console.log('rand'); var divs = document.querySelectorAll("div"); - tataki2 = Math.floor(Math.random()*ana); - if (count>=0) { - if (tataki == tataki2) { //数字がかぶったらやり直し + hit_new = Math.floor(Math.random()*ana); + if (count>=0) { // 制限時間すぎたら動かさない + if (hit == hit_new) { //数字がかぶったらやり直し rand(); } else { - tataki = tataki2; - atari = divs[tataki]; + hit = hit_new; + atari = divs[hit]; atari.innerHTML = ""; //もぐら画像表示 - atari.addEventListener('click', whack); + atari.addEventListener('click', whack); //イベントリスナー追加 } - console.log(`${tataki}`); + console.log(`${hit}`); } } function init() {