🎮ArcadeLab

NEON SNAKE ARENA

by ChromeFlame24
389 lines8.0 KB
▶ Play

<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>NEON SNAKE ARENA</title>
<style>
*{box-sizing:border-box}
body{
 margin:0;background:#080b14;color:white;
 font-family:Arial;text-align:center;
}
h1{color:#42ffc5;text-shadow:0 0 15px #00ffae}
.panel{padding:12px}
.stats{display:flex;justify-content:space-around;color:#42ffc5;font-weight:bold}
canvas{
 width:min(94vw,500px);height:auto;
 background:#101a26;border:2px solid #42ffc5;
 border-radius:15px;box-shadow:0 0 25px #00ff7755;
 touch-action:none;
}
button{
 background:#132c35;color:#42ffc5;
 border:1px solid #42ffc5;border-radius:12px;
 padding:13px 20px;font-size:17px;font-weight:bold;
 margin:5px;
}
#controls{
 display:grid;grid-template-columns:65px 65px 65px;
 justify-content:center;gap:6px;margin:10px;
}
#controls button{height:55px;padding:5px;font-size:22px}
#overlay{
 position:fixed;inset:0;background:#050914ed;
 display:flex;align-items:center;justify-content:center;
 z-index:5;
}
.box{
 background:#101b2b;border:2px solid #42ffc5;
 border-radius:20px;padding:25px;width:85%;max-width:350px;
 box-shadow:0 0 30px #00ff7755;
}
.box h2{color:#42ffc5}
.hidden{display:none!important}
</style>
</head>
<body>

<div class="panel">
<h1>🐍 NEON SNAKE</h1>
<div class="stats">
<span>🍎 SCORE: <b id="score">0</b></span>
<span>🏆 BEST: <b id="best">0</b></span>
<span>⚡ LEVEL: <b id="level">1</b></span>
</div>
</div>

<canvas id="game" width="500" height="500"></canvas>

<div>
<button id="pause">⏸ إيقاف</button>
<button id="restart">🔄 إعادة</button>
</div>

<div id="controls">
<div></div><button data-dir="up">⬆️</button><div></div>
<button data-dir="left">⬅️</button>
<button data-dir="down">⬇️</button>
<button data-dir="right">➡️</button>
</div>

<div id="overlay">
<div class="box">
<h2>🐍 NEON SNAKE ARENA</h2>
<p>اجمع التفاح والذهب وابتعد عن الجدران!</p>
<p>هل أنت مستعد للتحدي؟</p>
<button id="start">🚀 ابدأ اللعب</button>
</div>
</div>

<script>
"use strict";

const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");

const N=25;
const CELL=20;
const W=500;

let snake,apple,coins,rocks;
let dir,nextDir;
let score=0,level=1,best=0;
let running=false,paused=false,over=false;
let timer=null;
let particles=[];

try {
 best=Number(localStorage.getItem("snakeBest"))||0;
} catch(e){best=0}

document.getElementById("best").textContent=best;

function randomCell(){
 return Math.floor(Math.random()*N);
}

function freeCell(){
 let p;
 do{
  p={x:randomCell(),y:randomCell()};
 }while(
  snake.some(s=>s.x===p.x&&s.y===p.y)||
  (rocks||[]).some(r=>r.x===p.x&&r.y===p.y)||
  (apple&&apple.x===p.x&&apple.y===p.y)
 );
 return p;
}

function init(){
 snake=[
  {x:12,y:12},
  {x:11,y:12},
  {x:10,y:12}
 ];

 dir={x:1,y:0};
 nextDir={x:1,y:0};
 score=0;level=1;
 over=false;paused=false;
 rocks=[];
 particles=[];
 apple=null;
 coins=[];
 spawnApple();
 spawnCoins();
 updateStats();
 running=true;
 document.getElementById("overlay").classList.add("hidden");
 document.getElementById("pause").textContent="⏸ إيقاف";
 startTimer();
 draw();
}

function spawnApple(){
 apple=freeCell();
}

function spawnCoins(){
 coins=[];
 for(let i=0;i<3;i++)coins.push(freeCell());
}

function updateStats(){
 document.getElementById("score").textContent=score;
 document.getElementById("level").textContent=level;
 document.getElementById("best").textContent=best;
}

function startTimer(){
 clearInterval(timer);
 timer=setInterval(update,Math.max(65,155-(level-1)*12));
}

function setDirection(name){
 if(!running||paused||over)return;

 const directions={
  up:{x:0,y:-1},
  down:{x:0,y:1},
  left:{x:-1,y:0},
  right:{x:1,y:0}
 };

 const d=directions[name];
 if(!d)return;

 if(d.x===-dir.x&&d.y===-dir.y)return;
 nextDir=d;
}

document.addEventListener("keydown",e=>{
 const map={
  ArrowUp:"up",w:"up",
  ArrowDown:"down",s:"down",
  ArrowLeft:"left",a:"left",
  ArrowRight:"right",d:"right"
 };
 if(map[e.key]){
  e.preventDefault();
  setDirection(map[e.key]);
 }
});

document.querySelectorAll("[data-dir]").forEach(btn=>{
 btn.addEventListener("pointerdown",e=>{
  e.preventDefault();
  setDirection(btn.dataset.dir);
 });
});

function update(){
 if(!running||paused||over)return;

 dir=nextDir;

 const head={
  x:snake[0].x+dir.x,
  y:snake[0].y+dir.y
 };

 const eating=head.x===apple.x&&head.y===apple.y;
 const collecting=coins.some(c=>c.x===head.x&&c.y===head.y);

 if(
  head.x<0||head.x>=N||
  head.y<0||head.y>=N
 ){
  endGame();return;
 }

 const body=eating?snake:snake.slice(0,-1);

 if(body.some(s=>s.x===head.x&&s.y===head.y)){
  endGame();return;
 }

 if(rocks.some(r=>r.x===head.x&&r.y===head.y)){
  endGame();return;
 }

 snake.unshift(head);

 if(eating){
  score+=10;
  spawnApple();
  createParticles(head.x,head.y,"#ff405e");
 }else{
  snake.pop();
 }

 if(collecting){
  coins=coins.filter(c=>c.x!==head.x||c.y!==head.y);
  score+=25;
  createParticles(head.x,head.y,"#ffe45c");
  if(coins.length===0)spawnCoins();
 }

 const newLevel=Math.floor(score/100)+1;
 if(newLevel>level){
  level=newLevel;
  startTimer();
  rocks=[];
  for(let i=0;i<Math.min(level-1,8);i++){
   let p=freeCell();
   rocks.push(p);
  }
 }

 if(score>best){
  best=score;
  try{localStorage.setItem("snakeBest",best)}catch(e){}
 }

 updateStats();
 updateParticles();
 draw();
}

function createParticles(x,y,color){
 for(let i=0;i<8;i++){
  particles.push({
   x:x*CELL+10,y:y*CELL+10,
   vx:(Math.random()-.5)*5,
   vy:(Math.random()-.5)*5,
   life:20,color
  });
 }
}

function updateParticles(){
 particles.forEach(p=>{
  p.x+=p.vx;p.y+=p.vy;p.life--;
 });
 particles=particles.filter(p=>p.life>0);
}

function roundedRect(x,y,w,h,r,color){
 ctx.fillStyle=color;
 ctx.beginPath();
 ctx.roundRect(x,y,w,h,r);
 ctx.fill();
}

function draw(){
 ctx.fillStyle="#101a26";
 ctx.fillRect(0,0,W,W);

 // شبكة
 ctx.strokeStyle="#1a2a37";
 ctx.lineWidth=.6;
 for(let i=0;i<=W;i+=CELL){
  ctx.beginPath();ctx.moveTo(i,0);ctx.lineTo(i,W);ctx.stroke();
  ctx.beginPath();ctx.moveTo(0,i);ctx.lineTo(W,i);ctx.stroke();
 }

 // الصخور
 rocks.forEach(r=>{
  roundedRect(r.x*CELL+2,r.y*CELL+2,16,16,3,"#7a8291");
 });

 // التفاحة
 ctx.shadowBlur=15;
 ctx.shadowColor="#ff405e";
 roundedRect(apple.x*CELL+3,apple.y*CELL+3,14,14,6,"#ff405e");
 ctx.shadowBlur=0;
 ctx.fillStyle="#42ff9a";
 ctx.fillRect(apple.x*CELL+11,apple.y*CELL,3,5);

 // الذهب
 coins.forEach(c=>{
  ctx.shadowBlur=12;
  ctx.shadowColor="#ffdd44";
  ctx.fillStyle="#ffdd44";
  ctx.beginPath();
  ctx.arc(c.x*CELL+10,c.y*CELL+10,7,0,Math.PI*2);
  ctx.fill();
 });
 ctx.shadowBlur=0;

 // الثعبان
 snake.forEach((s,i)=>{
  ctx.shadowBlur=i===0?15:5;
  ctx.shadowColor="#42ffc5";
  roundedRect(
   s.x*CELL+1,s.y*CELL+1,18,18,5,
   i===0?"#b5ffdd":"#28dca0"
  );

  if(i===0){
   ctx.fillStyle="#102126";
   const ex=dir.x===1?13:dir.x===-1?4:5;
   const ey=dir.y===1?13:dir.y===-1?4:5;
   ctx.fillRect(s.x*CELL+ex,s.y*CELL+ey,3,3);
   if(dir.y===0)
    ctx.fillRect(s.x*CELL+ex,s.y*CELL+ey+7,3,3);
   if(dir.x===0)
    ctx.fillRect(s.x*CELL+ex+7,s.y*CELL+ey,3,3);
  }
 });
 ctx.shadowBlur=0;

 particles.forEach(p=>{
  ctx.globalAlpha=p.life/20;
  ctx.fillStyle=p.color;
  ctx.fillRect(p.x,p.y,4,4);
 });
 ctx.globalAlpha=1;
}

function endGame(){
 over=true;
 running=false;
 clearInterval(timer);
 document.getElementById("overlay").classList.remove("hidden");
 document.querySelector(".box").innerHTML=`
  <h2 style="color:#ff405e">GAME OVER</h2>
  <h3>نتيجتك: ${score}</h3>
  <p>أفضل نتيجة: ${best}</p>
  <button id="again">🔄 العب مرة أخرى</button>
 `;
 document.getElementById("again").onclick=init;
}

document.getElementById("start").onclick=init;
document.getElementById("restart").onclick=init;

document.getElementById("pause").onclick=()=>{
 if(!running||over)return;
 paused=!paused;
 document.getElementById("pause").textContent=
  paused?"▶ متابعة":"⏸ إيقاف";
};

draw();
</script>
</body>
</html>

Game Source: NEON SNAKE ARENA

Creator: ChromeFlame24

Libraries: none

Complexity: complex (389 lines, 8.0 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: neon-snake-arena-chromeflame24" to link back to the original. Then publish at arcadelab.ai/publish.