<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>クリックゲーム</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color:
margin: 0;
padding: 20px;
}
margin-top: 50px;
}
font-size: 24px;
padding: 15px 30px;
background-color:
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
background-color:
cursor: not-allowed;
}
font-size: 24px;
margin: 20px 0;
}
</style>
</head>
<body>
<h1>クリックゲーム</h1>
<p id="instructions">10秒間でボタンをできるだけ多くクリックしてください!</p>
<div id="game-area">
<button id="click-button" disabled>クリック!</button>
<p id="score">スコア: 0</p>
<p id="timer">残り時間: 10秒</p>
<button id="start-button">ゲームを開始</button>
</div>
<script>
let score = 0;
let timeLeft = 10;
let timerInterval;
const clickButton = document.getElementById('click-button');
const startButton = document.getElementById('start-button');
const scoreDisplay = document.getElementById('score');
const timerDisplay = document.getElementById('timer');
startButton.addEventListener('click', () => {
score = 0;
timeLeft = 10;
scoreDisplay.textContent = "スコア: 0";
timerDisplay.textContent = "残り時間: 10秒";
clickButton.disabled = false;
startButton.disabled = true;
timerInterval = setInterval(() => {
timeLeft--;
timerDisplay.textContent = `残り時間: ${timeLeft}秒`;
if (timeLeft <= 0) {
clearInterval(timerInterval);
clickButton.disabled = true;
startButton.disabled = false;
timerDisplay.textContent = "ゲーム終了!";
alert(`ゲーム終了!最終スコアは ${score} です!`);
}
}, 1000);
});
clickButton.addEventListener('click', () => {
score++;
scoreDisplay.textContent = `スコア: ${score}`;
});
</script>
</body>
</html>