現在スコア: 0
制限時間: 30秒
以下が「ノバクエスト」の要件に基づいて作成した実際のプログラムです。
```html
<!DOCTYPE html>
<html>
<head>
<title>ノバクエスト</title>
<style>
body {
background-color: red;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
#game-container {
display: flex;
flex-wrap: wrap;
width: 200px;
height: 200px;
margin-bottom: 20px;
}
.circle {
width: 60px;
height: 60px;
background-color: white;
border-radius: 50%;
margin: 5px;
cursor: pointer;
}
.black {
background-color: black;
}
#score {
font-size: 20px;
margin-bottom: 10px;
}
#timer {
font-size: 17px;
margin-bottom: 10px;
}
#start-btn,
#reset-btn {
font-size: 16px;
padding: 8px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="game-container">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
<div>
<div id="score">現在スコア: 0</div>
<div id="timer">制限時間: 30秒</div>
<button id="start-btn">スタート</button>
<button id="reset-btn">リセット</button>
</div>
<script>
// ゲームロジックの実装
const circles = document.querySelectorAll('.circle');
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const scoreDisplay = document.getElementById('score');
const timerDisplay = document.getElementById('timer');
let score = 0;
let timer;
let timeLeft = 30;
let gameStarted = false;
startBtn.addEventListener('click', startGame);
resetBtn.addEventListener('click', resetGame);
circles.forEach(circle => {
circle.addEventListener('click', handleClick);
});
function startGame() {
if (!gameStarted) {
gameStarted = true;
startBtn.disabled = true;
resetBtn.disabled = true;
score = 0;
timeLeft = 30;
scoreDisplay.textContent = `現在スコア: ${score}`;
timerDisplay.textContent = `制限時間: ${timeLeft}秒`;
timer = setInterval(updateTimer, 1000);
resetCircles();
startBtn.textContent = 'ゲーム中...';
}
}
function resetGame() {
if (!gameStarted) {
resetCircles();
score = 0;
timeLeft = 30;
scoreDisplay.textContent = `現在スコア: ${score}`;
timerDisplay.textContent = `制限時間: ${timeLeft}秒`;
}
}
function handleClick() {
if (gameStarted && !this.classList.contains('black')) {
this.classList.add('black');
score++;
scoreDisplay.textContent = `現在スコア: ${score}`;
const remainingWhiteCircles = Array.from(circles).filter(circle => !circle.classList.contains('black'));
if (remainingWhiteCircles.length === 0) {
endGame();
} else {
const randomIndex = Math.floor(Math.random() * remainingWhiteCircles.length);
remainingWhiteCircles[randomIndex].classList.add('black');
}
}
}
function updateTimer() {
timeLeft--;
timerDisplay.textContent = `制限時間: ${timeLeft}秒`;
if (timeLeft === 0) {
endGame();
}
}
function endGame() {
clearInterval(timer);
gameStarted = false;
startBtn.disabled = false;
resetBtn.disabled = false;
resetBtn.textContent = 'もう一度プレイ';
startBtn.textContent = 'ゲーム終了';
alert(`ゲーム終了! 最終スコアは ${score} です!`);
}
function resetCircles() {
circles.forEach(circle => {
circle.classList.remove('black');
});
}
</script>
</body>
</html>
```
このプログラムは「ノバクエスト」というゲームを実装しています。初期画面には3x3の白い丸が表示されており、スタートボタンをクリックするとその中の1つが黒い丸に変わります。黒い丸をクリックするとスコアが加算され、黒い丸は再び白い丸に変わります。制限時間が終了すると合計スコアが表示されます。リセットボタンをクリックするとゲームがリセットされます。