Untitled

 avatar
unknown
plain_text
9 months ago
2.9 kB
10
Indexable
<!doctype html> <html lang="bn"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>ছোট 1-D Game</title> <style> body{font-family:system-ui;background:#081020;color:#eef;padding:12px;display:flex;flex-direction:column;align-items:center} #row{display:flex;gap:6px;margin:12px} .c{width:26px;height:26px;border-radius:6px;display:flex;align-items:center;justify-content:center;background:#061022} .p{background:#2a9;color:#012} .o{background:#d24;color:#fff} #hud{display:flex;gap:12px;align-items:center} button{padding:6px 10px;border-radius:6px;border:none} </style> </head> <body> <h3>ছোট 1-D Game — বাঁ/ডান সরো</h3> <div id="hud">Score: <span id="s">0</span> <button id="start">Start</button></div> <div id="row"></div> <div id="msg" style="margin-top:10px;color:#ffd"></div> <script> (() => { const N = 15; let player = Math.floor(N/3), obs = [], score=0, running=false; const row = document.getElementById('row'), s = document.getElementById('s'), msg = document.getElementById('msg'); function build(){ row.innerHTML=''; for(let i=0;i<N;i++){const d=document.createElement('div');d.className='c';d.dataset.i=i; row.appendChild(d)} } function render(){ for(let i=0;i<N;i++){ const el=row.children[i]; el.className='c'; el.textContent=''; } obs.forEach(o=>{ if(o>=0&&o<N){ row.children[o].className='c o'; row.children[o].textContent='X' }}); row.children[player].className='c p'; row.children[player].textContent='P'; s.textContent = score; } function spawn(){ obs.push(N-1); if(Math.random()<0.12) obs.push(N-1); } function tick(){ obs = obs.map(x=>x-1).filter(x=>x>=0); if(obs.includes(player)){ gameOver(); return; } score++; render(); } let t1, t2; function start(){ if(running) return reset(); running=true; score=0; obs=[]; player=Math.floor(N/3); msg.textContent=''; render(); t1 = setInterval(tick,180); t2 = setInterval(spawn,900); document.getElementById('start').textContent='Restart'; } function reset(){ clearInterval(t1); clearInterval(t2); running=false; start(); } function gameOver(){ clearInterval(t1); clearInterval(t2); running=false; msg.textContent = 'Game Over — স্কোর: '+score; } function moveLeft(){ if(player>0) player--; render(); } function moveRight(){ if(player<N-1) player++; render(); } window.addEventListener('keydown', e=>{ if(e.key==='a'||e.key==='A'||e.key==='ArrowLeft') moveLeft(); else if(e.key==='d'||e.key==='D'||e.key==='ArrowRight') moveRight(); else if(e.key===' ') { if(player < N-2) player+=2; render(); } else if(e.key==='p'||e.key==='P'){ if(running) { clearInterval(t1); clearInterval(t2); running=false; msg.textContent='Paused'; } else start(); } }); document.getElementById('start').addEventListener('click', start); build(); render(); msg.textContent = 'A/D বা ←/→ চলবে। START টেনে শুরু করো।'; })(); </script> </body> </html> 
Editor is loading...
Leave a Comment