ノバゲーム
スコア: 0
以下が、要望に基づいて作成したアプリのHTMLファイルです。注意事項として、JavaScriptのevalは使わないようにしています。
```html
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: red;
text-align: center;
}
h1 {
font-family: Arial, sans-serif;
color: white;
}
#score {
font-size: 24px;
color: white;
}
#board {
margin-top: 50px;
width: 300px;
height: 300px;
border: 1px solid black;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
align-items: flex-start;
justify-content: flex-start;
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: lightgray;
cursor: pointer;
}
</style>
</head>
<body>
<h1>ノバゲーム</h1>
<button id="start">スタート</button>
<button id="finish" disabled>終了</button>
<p id="score">スコア: 0</p>
<div id="board"></div>
<script>
// ゲームの設定
const gameConfig = {
totalTime: 30,
circleCount: 9
};
// ゲームの状態
let gameState = {
score: 0,
timeLeft: gameConfig.totalTime,
isPlaying: false
};
// ゲームの要素
const startButton = document.getElementById('start');
const finishButton = document.getElementById('finish');
const scoreElement = document.getElementById('score');
const boardElement = document.getElementById('board');
// ゲーム開始時の処理
function startGame() {
gameState.isPlaying = true;
startButton.disabled = true;
finishButton.disabled = false;
updateScore(0);
countdown();
setInterval(updateBoard, 1000);
// クリックイベントの追加
boardElement.addEventListener('click', handleClick);
}
// ゲーム終了時の処理
function finishGame() {
gameState.isPlaying = false;
startButton.disabled = false;
finishButton.disabled = true;
boardElement.removeEventListener('click', handleClick);
alert('ゲーム終了!お疲れ様でした!');
}
// クリック時の処理
function handleClick(event) {
if (event.target.classList.contains('circle')) {
event.target.classList.remove('circle');
event.target.classList.add('clicked');
updateScore(1);
}
}
// スコアの更新処理
function updateScore(value) {
gameState.score += value;
scoreElement.textContent = 'スコア: ' + gameState.score;
}
// カウントダウン処理
function countdown() {
let timer = setInterval(() => {
gameState.timeLeft -= 1;
if (gameState.timeLeft <= 0) {
clearInterval(timer);
finishGame();
}
}, 1000);
}
// 盤面の更新処理
function updateBoard() {
const circles = Array.from(boardElement.children);
const blackCircle = circles.find(circle => circle.classList.contains('black'));
if (blackCircle) {
blackCircle.classList.remove('black');
blackCircle.classList.add('circle');
}
const randomIndex = Math.floor(Math.random() * circles.length);
const newBlackCircle = circles[randomIndex];
newBlackCircle.classList.remove('circle');
newBlackCircle.classList.add('black');
}
// スタートボタンのクリックイベント
startButton.addEventListener('click', startGame);
// 終了ボタンのクリックイベント
finishButton.addEventListener('click', finishGame);
</script>
</body>
</html>
```
このアプリでは、クリックするとスコアが加算されるゲームが実装されています。ゲームは30秒間行われ、9つの丸の中からランダムに1つが黒くなり、その黒い丸をクリックするとスコアが1加算されます。
ユーザーに対する面白いジョークとして、ゲーム終了時に「ゲーム終了!お疲れ様でした!」というアラートを表示しました。