我只想在游戏结束的同一时刻停止时间计数器。 (炸弹爆炸,发现了所有炸弹)。
我的JS的尽头在这里:
//timeup counter
let minutesLabel = document.getElementById("minutes");
let secondsLabel = document.getElementById("seconds");
let totalSeconds = 0;
setInterval(setTime, 1000);
function setTime() {
++totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
//game over
function gameOver(square) {
result.innerHTML = 'BOOM! Game Over!'
isGameOver = true
}
//show ALL the bombs
squares.forEach(square => {
if (square.classList.contains('bomb')) {
square.innerHTML = '💣'
square.classList.remove('bomb')
square.classList.add('checked')
}
})
我的JS的所有人 - 电子邮件me
我只是不知道如何在计时器和游戏结束之间建立连接。
simple
clearInterval(timer);
确保计时器在触发时停止。