ノバクエスト
スタート
リセット
スコア:0
<!DOCTYPE html>
<html>
<head>
<title>ノバクエスト</title>
<style>
body {
background-color: red;
text-align: center;
}
.button {
width: 100px;
height: 100px;
background-color: white;
border-radius: 50%;
margin: 10px;
font-size: 1.5em;
cursor: pointer;
}
.button.black {
background-color: black;
color: white;
}
</style>
</head>
<body>
<h1>ノバクエスト</h1>
<div class="button start" onclick="startGame()">スタート</div>
<div class="button reset" onclick="resetGame()">リセット</div>
<div id="score">スコア:0</div>
<script>
var score = 0;
var buttons = document.getElementsByClassName("button");
// スタートボタンを押したときの処理
function startGame() {
// ボタンをランダムに一つ黒くする
var randomButtonIndex = Math.floor(Math.random() * buttons.length);
buttons[randomButtonIndex].classList.add("black");
buttons[randomButtonIndex].onclick = function() {
increaseScore(randomButtonIndex);
};
}
// リセットボタンを押したときの処理
function resetGame() {
// スコアをリセットして黒いボタンとのイベントをクリアする
score = 0;
document.getElementById("score").innerText = "スコア:" + score;
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.remove("black");
buttons[i].onclick = null;
}
}
// 黒いボタンが押されたときの処理
function increaseScore(buttonIndex) {
score += 1;
document.getElementById("score").innerText = "スコア:" + score;
buttons[buttonIndex].classList.remove("black");
buttons[buttonIndex].onclick = null;
startGame();
}
</script>
</body>
</html>
**ジョーク:**
Q: 宇宙船の中で一番人気のある飲み物は何でしょうか?
A: コーハビ