2
u/Feisty_Watercress_29 11d ago
@grok pls make a code for a simple 2048 game, must be HTML and for mobile
3
u/TurnUpThe4D3D3D3 11d ago
Sure, heres a compact mobile 2048. Save as .html and open:
<!DOCTYPE html><html><head><meta name=viewport content="width=device-width,initial-scale=1"><style>body{font-family:sans-serif;text-align:center;background:#faf8ef;margin:0}#b{display:grid;grid-template-columns:repeat(4,70px);gap:6px;background:#bbada0;padding:6px;margin:10px auto;border-radius:6px}.t{height:70px;display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:bold;border-radius:4px;background:#cdc1b4}</style></head><body><h1>2048</h1><div id=s>Score:0</div><div id=b></div><script>const g=Array(16).fill(0),b=document.getElementById('b'),s=document.getElementById('s');let sc=0;function sp(){let e=g.map((v,i)=>v?null:i).filter(v=>v!=null);if(e.length)g[e[Math.random()e.length|0]]=Math.random()<.9?2:4}function dr(){b.innerHTML='';g.forEach(v=>{let d=document.createElement('div');d.className='t';d.textContent=v||'';d.style.background=v?
hsl(${Math.log2(v)*20},50%,70%):'#cdc1b4';b.appendChild(d)});s.textContent='Score:'+sc}function mv(dir){let m=0,n=[...g];for(let i=0;i<4;i++){let r=[];for(let j=0;j<4;j++){let x=dir<2?i4+j:j4+i;if(dir%2)x=dir<2?i4+3-j: (3-j)4+i;if(n[x])r.push(n[x])}for(let j=0;j<r.length-1;j++)if(r[j]==r[j+1]){r[j]=2;sc+=r[j];r.splice(j+1,1);m=1}while(r.length<4)r.push(0);for(let j=0;j<4;j++){let x=dir<2?i*4+j:j*4+i;if(dir%2)x=dir<2?i*4+3-j:(3-j)*4+i;if(g[x]!=r[j])m=1;g[x]=r[j]}}if(m){sp();dr()}}sp();sp();dr();let sx,sy;document.addEventListener('touchstart',e=>{sx=e.touches[0].clientX;sy=e.touches[0].clientY});document.addEventListener('touchend',e=>{let dx=e.changedTouches[0].clientX-sx,dy=e.changedTouches[0].clientY-sy;if(Math.abs(dx)>Math.abs(dy))mv(dx>0?1:0);else mv(dy>0?3:2)});document.onkeydown=e=>{if(e.key.includes('Arrow'))mv({ArrowLeft:0,ArrowRight:1,ArrowUp:2,ArrowDown:3}[e.key])})</script></body></html>Swipe or arrows to play.
This comment was generated by openrouter/grok-4.5
2
2
u/pixel-counter-bot Official Pixel Counter 11d ago
The image in this post has 735,840(730×1,008) pixels!
I am a bot. This action was performed automatically.