🎮ArcadeLab

جمع وتفریق اعداد صحیح

by PixelPanda95
57 lines2.2 KB
▶ Play
px)`;
        }

        function nextQuestion() {
            feedbackEl.innerText = "";
            // تولید سوال (جمع یا تفریق)
            let n1 = Math.floor(Math.random() * 15) - 7; // عدد اول بین 7- تا 7
            let op = Math.random() > 0.5 ? '+' : '-';
            let n2 = Math.floor(Math.random() * 10) - 5; // عدد دوم بین 5- تا 5

            // محاسبه جواب واقعی
            currentAnswer = (op === '+') ? (n1 + n2) : (n1 - n2);

            // نمایش سوال
            questionEl.innerText = `${n1} ${op} (${n2}) = ?`;

            // ایجاد گزینه‌ها
            let wrongAns = currentAnswer + (Math.random() > 0.5 ? 2 : -2);
            if(wrongAns === currentAnswer) wrongAns += 3;
            
            let choices = [currentAnswer, wrongAns].sort(() => Math.random() - 0.5);
            
            document.getElementById('opt0').innerText = choices[0];
            document.getElementById('opt1').innerText = choices[1];
            
            // ذخیره ایندکس درست
            window.correctIdx = choices.indexOf(currentAnswer);

            // ریست کردن مکان غول به صفر در هر سوال جدید (یا می‌توانید غول را در جای قبلی نگه دارید)
            movePlayerTo(0); 
        }

        function checkAns(idx) {
            if (idx === window.correctIdx) {
                score += 10;
                feedbackEl.innerText = "✅ عالی! غول درست پرید";
                feedbackEl.style.color = "green";
                
                // حرکت غول به جواب درست برای نمایش بصری
                movePlayerTo(currentAnswer);
                
                document.getElementById('score').innerText = score;
                setTimeout(nextQuestion, 1500);
            } else {
                feedbackEl.innerText = "❌ اوه! غول زمین خورد";
                feedbackEl.style.color = "red";
                score = Math.max(0, score - 5);
                document.getElementById('score').innerText = score;
            }
        }

        setupLine();
        movePlayerTo(0);
        nextQuestion();
    </script>
</body>
</html>

Game Source: جمع وتفریق اعداد صحیح

Creator: PixelPanda95

Libraries: none

Complexity: moderate (57 lines, 2.2 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: game-pixelpanda95-mtbwy433" to link back to the original. Then publish at arcadelab.ai/publish.