```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ブロック崩しゲーム</title> <style> #player { width: 100px; height: 20px; background-color: black; position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); } #ball { width: 20px; height: 20px; background-color: red; position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); border-radius: 50%; } .block { width: 80px; height: 20px; background-color: blue; position: absolute; top: 0; left: 0; } </style> </head> <body> <div id="player"></div> <div id="ball"></div> <div class="blocks"></div> <script> document.addEventListener('DOMContentLoaded', function() { const player = document.getElementById('player'); const ball = document.getElementById('ball'); const blocks = document.querySelector('.blocks'); let gameInterval; let blockInterval; let playerPosition = 50; let ballX = 50; let ballY = 40; let dx = 1; let dy = -1; player.style.left = `${playerPosition}%`; ball.style.left = `${ballX}%`; ball.style.bottom = `${ballY}px`; function createBlocks() { for (let i = 0; i < 5; i++) { for (let j = 0; j < 10; j++) { const block = document.createElement('div'); block.classList.add('block'); block.style.top = `${i * 25}px`; block.style.left = `${j * 90}px`; blocks.appendChild(block); } } } createBlocks(); function updateBall() { ballY += dy; ballX += dx; if (ballY >= 100) { clearInterval(gameInterval); clearInterval(blockInterval); alert('ゲームオーバー!クリックしてリトライ!'); document.location.reload(true); } if (ballY <= 0) { dy = 1; } if (ballX <= 0 || ballX >= 100) { dx = -dx; } if (ballY >= 10 && ballY <= 15 && ballX >= playerPosition && ballX <= playerPosition + 10) { dy = -1; } const allBlocks = document.querySelectorAll('.block'); allBlocks.forEach((block) => { const rect = block.getBoundingClientRect(); if (ballY <= rect.bottom && ballY >= rect.top && ballX >= rect.left && ballX <= rect.right) { block.remove(); dy = -dy; } }); ball.style.left = `${ballX}%`; ball.style.bottom = `${ballY}%`; } document.addEventListener('mousemove', function(e) { playerPosition = (e.clientX / window.innerWidth) * 100; player.style.left = `${playerPosition}%`; }); document.addEventListener('click', function() { clearInterval(gameInterval); clearInterval(blockInterval); document.location.reload(true); }); gameInterval = setInterval(updateBall, 10); }); </script> </body> </html> ``` このプログラムは単純なブロック崩しゲームを実装しています。クリックでリセットできるようになっており、マウスを動かしてパドルを操作することができます。ブロックを全て壊すとゲームクリアです。楽しんでプレイしてみてください!