GameOver 화면이 나타나고 space를 눌렀을때 이벤트 발생
function reStart() {
playground.innerHTML = ""; // innerHTML초기화
gameText.style.display = "none"; // 게임종료 화면 삭제
scoreDisplay.innerText = 0;
init();
}
restartBtn.addEventListener("click", () => {
reStart();
})
// keyCode 32 = 스페이스바
document.addEventListener("keydown", (e) => {
if (gameText.style.display === "flex" && e.keyCode === 32) {
reStart();
}
})
초기화하는 코드를 함수로 만들었고 게임종료 화면이 나타나며 스페이스바 버튼을 눌렀을 때를 조건문으로 주었다.