gpt-5.3· openai
from compar:IA French AI Arena
Code moi un jeu Snake en seulement 50 lignes en HTML
Private research annotation
Sign in to add a private research label or note.
- User
Code moi un jeu Snake en seulement 50 lignes en HTML
- Assistant
Voici un Snake en exactement 50 lignes :
html<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Snake</title> <style> body{margin:0;background:#000} canvas{background:#111;display:block;margin:auto} </style> </head> <body> <canvas id="c" width="400" height="400"></canvas> <script> const c=document.getElementById("c"),x=c.getContext("2d"); let s=[{x:10,y:10}],d={x:1,y:0},f={x:15,y:15},g=20,score=0; document.onkeydown=e=>{ if(e.key=="ArrowUp"&&d.y!=1)d={x:0,y:-1}; if(e.key=="ArrowDown"&&d.y!=-1)d={x:0,y:1}; if(e.key=="ArrowLeft"&&d.x!=1)d={x:-1,y:0}; if(e.key=="ArrowRight"&&d.x!=-1)d={x:1,y:0}; }; function loop(){ let h={x:s[0].x+d.x,y:s[0].y+d.y}; if(h.x<0||h.y<0||h.x>=20||h.y>=20||s.some(p=>p.x==h.x&&p.y==h.y))return reset(); s.unshift(h); if(h.x==f.x&&h.y==f.y){ score++; f={x:Math.floor(Math.random()*20),y:Math.floor(Math.random()*20)}; }else s.pop(); draw(); } function draw(){ x.fillStyle="#111";x.fillRect(0,0,400,400); x.fillStyle="lime"; s.forEach(p=>x.fillRect(p.x*g,p.y*g,g-2,g-2)); x.fillStyle="red"; x.fillRect(f.x*g,f.y*g,g-2,g-2); x.fillStyle="#fff"; x.fillText("Score:"+score,10,390); } function reset(){ s=[{x:10,y:10}];d={x:1,y:0};score=0; } setInterval(loop,100); draw(); </script> </body> </html> - User
améliore moi les textures du jeu
- Assistant
Ok, on garde le même jeu mais on remplace les carrés basiques par un rendu un peu plus stylé (dégradés, effet “glossy”, nourriture avec look fruit). Remplace juste la fonction
draw()par celle-ci :jsfunction draw(){ x.fillStyle="#0a0a0a"; x.fillRect(0,0,400,400); for(let i=0;i<s.length;i++){ let p=s[i]; let grd=x.createRadialGradient(p.x*g+10,p.y*g+10,2,p.x*g+10,p.y*g+10,12); grd.addColorStop(0,"#7CFC00"); grd.addColorStop(1,"#006400"); x.fillStyle=grd; x.beginPath(); x.roundRect(p.x*g,p.y*g,g-2,g-2,6); x.fill(); } let fx=f.x*g, fy=f.y*g; let foodGrad=x.createRadialGradient(fx+10,fy+10,2,fx+10,fy+10,12); foodGrad.addColorStop(0,"#ff8080"); foodGrad.addColorStop(1,"#8b0000"); x.fillStyle=foodGrad; x.beginPath(); x.arc(fx+10,fy+10,8,0,Math.PI*2); x.fill(); x.fillStyle="#fff"; x.font="16px monospace"; x.fillText("Score: "+score,10,390); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.