-
Notifications
You must be signed in to change notification settings - Fork 118
منچ کلاسیک #105
Copy link
Copy link
Open
Description
mobilemohammad7283-jpg
opened on Jun 12, 2026
Issue body actions
<title>منچ سلطنتی - بازی کامل آنلاین و آفلاین</title>
<style>
* {
box-sizing: border-box;
user-select: none;
}
<script>
(function(){
// ---------- ذخیرهسازی کاربر ----------
let currentUser = {
uid: "p"+Math.random().toString(36).substr(2,8),
name: "مسافر",
phone: "09123456789",
coins: 5000,
avatar: "🐉",
diceSkin: "default",
pawnSkin: "default",
bgTheme: "default",
referralCode: "",
referred: false,
registered: true
};
function saveUser(){ localStorage.setItem("ludoUser", JSON.stringify(currentUser)); }
function loadUser(){
let d = localStorage.getItem("ludoUser");
if(d){ let u=JSON.parse(d); currentUser={...currentUser, ...u}; }
if(!currentUser.referralCode) currentUser.referralCode = currentUser.uid.slice(0,6)+Math.floor(Math.random()*10000);
saveUser(); updateUI();
}
function updateUI(){
document.getElementById("displayName").innerText = currentUser.name;
document.getElementById("phoneNumber").innerText = currentUser.phone;
document.getElementById("coinAmount").innerText = currentUser.coins;
document.getElementById("avatarPreview").innerText = currentUser.avatar;
document.getElementById("myRefCode").innerText = currentUser.referralCode;
}
function addCoins(amount){ currentUser.coins += amount; updateUI(); saveUser(); }
function deductCoins(amount){ if(currentUser.coins >= amount){ currentUser.coins -= amount; updateUI(); saveUser(); return true; } else { alert("سکه کافی نیست!"); return false; } }
// پنلها
document.querySelectorAll(".nav-btn").forEach(btn=>{ btn.addEventListener("click",()=>{ document.querySelectorAll(".panel").forEach(p=>p.classList.remove("active-panel")); document.getElementById(`panel-${btn.dataset.panel}`).classList.add("active-panel"); }); });
document.getElementById("profileBtn").addEventListener("click",()=>{ document.querySelector("[data-panel='profilePanel']").click(); });
document.getElementById("saveProfileBtn").addEventListener("click",()=>{ let n=document.getElementById("editName").value; if(n) currentUser.name=n; let p=document.getElementById("editPhone").value; if(p) currentUser.phone=p; updateUI(); saveUser(); alert("پروفایل ذخیره شد"); });
document.querySelectorAll("#avatarOptions div").forEach(av=>{ av.addEventListener("click",()=>{ currentUser.avatar=av.innerText; updateUI(); saveUser(); }); });
document.getElementById("applyReferralBtn").addEventListener("click",()=>{ let code=document.getElementById("refCodeInput").value; if(code && !currentUser.referred && code!==currentUser.referralCode){ currentUser.referred=true; addCoins(1000); alert("۱۰۰۰ سکه هدیه دریافت شد"); saveUser(); } else alert("کد نامعتبر یا قبلاً استفاده شده"); });
// خریدها
document.querySelectorAll("#shopCoins .shop-card").forEach(c=>{ c.addEventListener("click",()=>{ let coins=parseInt(c.dataset.coins); addCoins(coins); alert(`خرید ${coins} سکه انجام شد (شبیهسازی درگاه)`); }); });
document.querySelectorAll("#diceSkinsShop .shop-card").forEach(c=>{ c.addEventListener("click",()=>{ if(currentUser.coins>=10000){ deductCoins(10000); currentUser.diceSkin=c.dataset.skin; saveUser(); alert("تاس جدید خریداری شد"); } else alert("سکه کافی نیست"); }); });
document.querySelectorAll("#pawnSkinsShop .shop-card").forEach(c=>{ c.addEventListener("click",()=>{ if(currentUser.coins>=10000){ deductCoins(10000); currentUser.pawnSkin=c.dataset.pawn; saveUser(); alert("مهره جدید خریداری شد"); } }); });
document.getElementById("buyBgBtn").addEventListener("click",()=>{ if(currentUser.coins>=300000){ deductCoins(300000); currentUser.bgTheme="gold"; saveUser(); alert("زمین طلایی فعال شد"); } else alert("سکه کافی نیست"); });
// ---------- موتور کامل بازی منچ (Ludo) ----------
// رنگها: قرمز(0), سبز(1), زرد(2), آبی(3)
const COLORS = ["red","green","yellow","blue"];
const COLOR_SYMBOLS = ["🔴","🟢","🟡","🔵"];
const HOME_PATH = [0,13,26,39]; // شروع هر رنگ در مسیر اصلی (حلقه 52 خانه)
const SAFE_SPOTS = [0,8,13,21,26,34,39,47]; // خانههای امن
class LudoGame {
constructor(playersColors, onUpdate) {
this.players = playersColors; // آرایهای از نام بازیکنان به ترتیب نوبت [ "قرمز", "سبز", ...]
this.colorIndex = playersColors.map(c=>COLORS.indexOf(c));
this.turnIdx = 0;
this.pawns = {}; // هر بازیکن: 4 مهره موقعیت -1 (خارج) تا 51 و 100 (خانه)
for(let i=0;i=0 && positions[i]<100){
let newPos = this.getNewPosition(color, positions[i], dice);
if(newPos !== -1) return true;
}
}
return false;
}
getNewPosition(color, pos, steps){
if(pos===-1){
if(steps===6) return HOME_PATH[COLORS.indexOf(color)];
else return -1;
}
if(pos>=0 && pos<52){
let np = pos+steps;
if(np>=52) return -1; // هنوز نرسیده به خانهها
// بررسی برخورد با مهره حریف (ضربه)
return np;
}
return -1;
}
tryMove(pawnIdx){
if(!this.waitingForMove) return false;
let color = this.players[this.turnIdx];
let pos = this.pawns[color][pawnIdx];
let steps = this.diceValue;
if(pos===-1 && steps!==6) return false;
let newPos = this.getNewPosition(color, pos, steps);
if(newPos === -1) return false;
// ضربه زدن
let hit = false;
for(let i=0;i= 52 && newPos < 100){} // فعلاً ignore
this.waitingForMove = false;
clearInterval(this.timerInterval);
// چک برنده
let allFinished = true;
for(let i=0;i<4;i++) if(this.pawns[color][i] !== 100) allFinished=false;
if(allFinished){
this.winner = color;
this.finished = true;
this.onUpdate();
return true;
}
if(steps !== 6) this.turnIdx = (this.turnIdx+1)%this.players.length;
this.onUpdate();
return true;
}
startTimer(){
this.timeLeft = 6;
if(this.timerInterval) clearInterval(this.timerInterval);
this.timerInterval = setInterval(()=>{
if(this.waitingForMove && !this.finished){
this.timeLeft -= 0.1;
if(this.timeLeft <= 0){
clearInterval(this.timerInterval);
this.endTurn();
}
this.onUpdate();
} else clearInterval(this.timerInterval);
},100);
}
endTurn(){
if(this.waitingForMove){
this.waitingForMove = false;
clearInterval(this.timerInterval);
this.turnIdx = (this.turnIdx+1)%this.players.length;
this.onUpdate();
}
}
getCurrentColor(){ return this.players[this.turnIdx]; }
}
let activeGame = null;
let canvas = null, ctx = null;
function drawBoard(){
if(!canvas) return;
let w=600, h=600;
ctx.fillStyle="#f0d9b5"; ctx.fillRect(0,0,w,h);
// رسم ساده مسیر (برای نمایش نمادین)
ctx.font="bold 20px sans-serif";
ctx.fillStyle="black";
ctx.fillText("بازی منچ",20,50);
if(activeGame){
let players = activeGame.players;
for(let i=0;i=0?"♟️":"🏁");
ctx.fillStyle = colorName;
ctx.fillText(`${COLOR_SYMBOLS[COLORS.indexOf(colorName)]}${state}`, x+p*30, y);
}
}
ctx.fillStyle = "black";
ctx.fillText(`نوبت: ${COLOR_SYMBOLS[COLORS.indexOf(activeGame.getCurrentColor())]}`, 20, 120);
ctx.fillText(`تاس: ${activeGame.diceValue || "🎲"}`, 20, 170);
if(activeGame.waitingForMove) ctx.fillText(`زمان: ${activeGame.timeLeft.toFixed(1)}ثانیه`,20,220);
if(activeGame.winner) ctx.fillText(`برنده: ${activeGame.winner}`,20,270);
}
}
function renderGame(){
if(activeGame && canvas) drawBoard();
}
// شروع بازی با موتور
function startGameWithPlayers(playersColors, entryFee, winPrize, isTeam=false, teamCallback=null){
if(entryFee>0 && !deductCoins(entryFee)) return false;
activeGame = new LudoGame(playersColors, ()=>{ renderGame(); });
document.querySelector(".panel.active-panel").classList.remove("active-panel");
document.getElementById("gameBoardPanel").style.display = "block";
canvas = document.getElementById("ludoCanvas");
ctx = canvas.getContext("2d");
renderGame();
// رویداد تاس
const diceBtn = document.getElementById("diceBtn");
const newRoll = ()=>{
if(activeGame && !activeGame.finished && activeGame.getCurrentColor() === playersColors[0] && !activeGame.waitingForMove){
activeGame.rollDice();
renderGame();
} else if(activeGame && activeGame.finished){
let winnerColor = activeGame.winner;
if(winnerColor === playersColors[0]){
addCoins(winPrize);
alert(`تبریک! شما برنده شدید و +${winPrize} سکه گرفتید.`);
} else alert(`بازنده! ${winnerColor} برنده شد.`);
endCurrentGame();
} else if(activeGame && activeGame.waitingForMove){
// انتخاب مهره
}
};
diceBtn.onclick = newRoll;
// انتخاب مهره روی canvas (ساده: کلیک بر روی متن مهره)
canvas.onclick = (e)=>{
if(!activeGame || activeGame.finished) return;
let rect = canvas.getBoundingClientRect();
let scale = canvas.width/rect.width;
let mx = (e.clientX - rect.left)*scale;
let my = (e.clientY - rect.top)*scale;
// تشخیص تقریبی
for(let i=0;i<4;i++){
let x=100 + i*30;
let y=500;
if(mx > x && mx < x+25 && my > y && my < y+30){
if(activeGame.getCurrentColor() === playersColors[0] && activeGame.waitingForMove){
activeGame.tryMove(i);
renderGame();
if(activeGame.finished){
let winnerColor = activeGame.winner;
if(winnerColor === playersColors[0]) addCoins(winPrize);
else alert(`باختید!`);
endCurrentGame();
}
}
break;
}
}
};
document.getElementById("exitGameBtn").onclick = ()=>{ endCurrentGame(); };
return true;
}
function endCurrentGame(){
if(activeGame && activeGame.timerInterval) clearInterval(activeGame.timerInterval);
activeGame = null;
document.getElementById("gameBoardPanel").style.display = "none";
document.getElementById("panel-main").classList.add("active-panel");
}
// شروع مودهای مختلف
function startOnline1v1(){
startGameWithPlayers([currentUser.avatarToColor?"قرمز":COLORS[0], COLORS[1]], 100, 300);
}
function startTeamMode(){
if(currentUser.coins>=1000){
deductCoins(1000);
alert("بازی تیمی: شما و یک همتیمی (ساختگی) در برابر دو حریف. اگر بردید هر کدام ۱۸۰۰ سکه میگیرید.");
setTimeout(()=>{ addCoins(1800); alert("تیم شما برد! +۱۸۰۰ سکه"); endCurrentGame(); }, 500);
document.getElementById("gameBoardPanel").style.display="block";
setTimeout(()=>endCurrentGame(),2000);
} else alert("سکه کافی نیست");
}
function createFriendlyRoom(){
let code = Math.random().toString(36).substr(2,6).toUpperCase();
localStorage.setItem("ludoRoom_"+code, JSON.stringify({host:currentUser.uid, players:[currentUser.name], color:"قرمز"}));
alert(`کد اتاق: ${code} - دوست شما میتواند با همین کد وارد شود. بعد از ورود هر دو، بازی شروع میشود.`);
// شبیهسازی ساده: بعد از 5 ثانیه بازی شروع میشود
setTimeout(()=>{
if(confirm("بازیکن دوم وارد شد؟ شروع بازی")) startGameWithPlayers([COLORS[0], COLORS[1]], 100, 250);
}, 2000);
}
function joinFriendlyRoom(){
let code = document.getElementById("joinRoomCode").value.trim();
if(code && localStorage.getItem("ludoRoom_"+code)){
startGameWithPlayers([COLORS[0], COLORS[1]], 100, 250);
} else alert("اتاق نامعتبر");
}
function startOfflineBot(){
let count = parseInt(document.getElementById("botCountSelect").value);
let players = [COLORS[0]];
for(let i=1;i
🐉
بارگذاری...
📞 ---
🪙 0
🎁 کد معرف
🏠 صفحه اصلی
🛒 فروشگاه
👤 پروفایل
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels