robomath / index.html
olinux's picture
Add 2 files
28ad2a0 verified
Raw History Blame Contribute Delete
39.8 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RoboMath - Apprendre la programmation et les maths</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.code-block {
font-family: 'Courier New', monospace;
background-color: #2d3748;
color: #f7fafc;
border-radius: 0.5rem;
padding: 1rem;
min-height: 150px;
}
.robot {
transition: all 0.5s ease;
position: absolute;
bottom: 1rem;
left: 1rem;
}
.command-btn {
transition: all 0.2s ease;
}
.command-btn:hover {
transform: translateY(-2px);
}
.droppable {
min-height: 50px;
background-color: #4a5568;
border: 2px dashed #718096;
border-radius: 0.5rem;
}
.draggable {
cursor: move;
user-select: none;
}
.progress-track {
background-image: linear-gradient(45deg, rgba(255,255,255,0.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.15) 75%, transparent 75%, transparent);
background-size: 1rem 1rem;
}
.modal {
transition: opacity 0.3s ease;
}
</style>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="flex flex-col md:flex-row justify-between items-center mb-8">
<div class="flex items-center mb-4 md:mb-0">
<i class="fas fa-robot text-4xl text-blue-400 mr-3"></i>
<h1 class="text-3xl font-bold bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">RoboMath</h1>
</div>
<div class="flex items-center space-x-4">
<button id="help-btn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-medium transition">
<i class="fas fa-question-circle mr-1"></i> Aide
</button>
<div class="flex items-center">
<span class="mr-2 text-yellow-300"><i class="fas fa-star"></i></span>
<span id="score" class="font-bold">0</span>
</div>
<div class="relative">
<div class="h-3 w-32 bg-gray-700 rounded-full overflow-hidden">
<div id="progress-bar" class="h-full bg-gradient-to-r from-green-400 to-blue-500 rounded-full" style="width: 0%"></div>
</div>
<span id="level" class="absolute -top-6 left-0 text-xs font-bold">Niveau 1</span>
</div>
<button id="reset-btn" class="px-3 py-1 bg-red-600 hover:bg-red-700 rounded-md text-sm font-medium transition">
<i class="fas fa-redo mr-1"></i> Réinitialiser
</button>
</div>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Left Panel - Game Area -->
<div class="lg:col-span-2 space-y-6">
<!-- Problem Statement -->
<div class="bg-gray-800 rounded-xl p-6 shadow-lg">
<h2 class="text-xl font-bold mb-4 text-blue-300 flex items-center">
<i class="fas fa-question-circle mr-2"></i> Problème Mathématique
</h2>
<div id="problem-statement" class="text-lg">
Programmez le robot pour qu'il calcule la somme des nombres de 1 à 5 et affiche le résultat.
</div>
<div id="math-expression" class="mt-4 p-3 bg-gray-700 rounded-md text-center text-xl font-mono">
1 + 2 + 3 + 4 + 5 = ?
</div>
</div>
<!-- Robot Visualization -->
<div class="bg-gray-800 rounded-xl p-6 shadow-lg">
<h2 class="text-xl font-bold mb-4 text-purple-300 flex items-center">
<i class="fas fa-robot mr-2"></i> Zone du Robot
</h2>
<div class="flex flex-col items-center">
<div id="robot-container" class="relative w-full h-48 bg-gray-700 rounded-lg mb-4 overflow-hidden">
<div id="robot" class="robot w-16 h-24 bg-blue-500 rounded-t-lg flex flex-col items-center">
<div class="w-12 h-8 bg-blue-400 rounded-t-full mt-1 flex justify-center items-center">
<div class="w-2 h-2 bg-yellow-300 rounded-full mx-1"></div>
<div class="w-2 h-2 bg-yellow-300 rounded-full mx-1"></div>
</div>
<div class="w-14 h-12 bg-blue-400 rounded-b-lg mt-1 flex justify-center items-center text-white font-bold">
R-1
</div>
</div>
<div id="output-display" class="absolute bottom-4 right-4 w-32 h-10 bg-gray-600 rounded flex items-center justify-center font-mono text-lg">
?
</div>
</div>
<div class="w-full bg-gray-700 h-2 rounded-full overflow-hidden">
<div id="progress-track" class="progress-track h-full bg-gradient-to-r from-blue-500 to-purple-500" style="width: 0%"></div>
</div>
</div>
</div>
</div>
<!-- Right Panel - Programming Area -->
<div class="space-y-6">
<!-- Command Palette -->
<div class="bg-gray-800 rounded-xl p-6 shadow-lg">
<h2 class="text-xl font-bold mb-4 text-green-300 flex items-center">
<i class="fas fa-code mr-2"></i> Commandes Disponibles
</h2>
<div class="grid grid-cols-2 gap-2">
<button data-command="moveForward()" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-arrow-right mr-2"></i> Avancer
</button>
<button data-command="turnLeft()" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-undo mr-2"></i> Tourner Gauche
</button>
<button data-command="turnRight()" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-redo mr-2"></i> Tourner Droite
</button>
<button data-command="setVariable('x', 0)" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-memory mr-2"></i> Définir Variable
</button>
<button data-command="increment('x')" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-plus-circle mr-2"></i> Incrémenter
</button>
<button data-command="addTo('x', 1)" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-plus mr-2"></i> Ajouter à
</button>
<button data-command="print('x')" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-print mr-2"></i> Afficher
</button>
<button data-command="loop(5)" class="command-btn draggable px-3 py-2 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-mono flex items-center">
<i class="fas fa-repeat mr-2"></i> Boucle
</button>
</div>
</div>
<!-- Code Editor -->
<div class="bg-gray-800 rounded-xl p-6 shadow-lg">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold text-yellow-300 flex items-center">
<i class="fas fa-laptop-code mr-2"></i> Votre Programme
</h2>
<button id="clear-btn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-medium transition">
<i class="fas fa-trash-alt mr-1"></i> Effacer
</button>
</div>
<div id="code-block" class="code-block droppable">
<div id="code-placeholder" class="text-gray-400 italic">Glissez les commandes ici ou cliquez pour les ajouter</div>
</div>
<div class="mt-4 flex justify-between">
<button id="run-btn" class="px-4 py-2 bg-green-600 hover:bg-green-700 rounded-md font-medium flex items-center transition">
<i class="fas fa-play mr-2"></i> Exécuter
</button>
<button id="debug-btn" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium flex items-center transition">
<i class="fas fa-bug mr-2"></i> Déboguer
</button>
</div>
</div>
<!-- Variables Panel -->
<div class="bg-gray-800 rounded-xl p-6 shadow-lg">
<h2 class="text-xl font-bold mb-4 text-pink-300 flex items-center">
<i class="fas fa-memory mr-2"></i> Variables
</h2>
<div id="variables-panel" class="grid grid-cols-2 gap-2">
<div class="bg-gray-700 p-2 rounded">
<div class="text-xs text-gray-400">x</div>
<div id="var-x" class="font-mono">0</div>
</div>
<div class="bg-gray-700 p-2 rounded">
<div class="text-xs text-gray-400">y</div>
<div id="var-y" class="font-mono">0</div>
</div>
<div class="bg-gray-700 p-2 rounded">
<div class="text-xs text-gray-400">z</div>
<div id="var-z" class="font-mono">0</div>
</div>
<div class="bg-gray-700 p-2 rounded">
<div class="text-xs text-gray-400">result</div>
<div id="var-result" class="font-mono">0</div>
</div>
</div>
</div>
</div>
</div>
<!-- Console Output -->
<div class="mt-6 bg-gray-800 rounded-xl p-6 shadow-lg">
<h2 class="text-xl font-bold mb-4 text-red-300 flex items-center">
<i class="fas fa-terminal mr-2"></i> Console
</h2>
<div id="console-output" class="code-block h-24 overflow-y-auto">
<div class="text-gray-400">Bienvenue dans RoboMath! Commencez à programmer votre robot.</div>
</div>
</div>
</div>
<!-- Success Modal -->
<div id="success-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 rounded-xl p-8 max-w-md w-full mx-4 text-center">
<div class="text-6xl text-yellow-400 mb-4">
<i class="fas fa-trophy"></i>
</div>
<h2 class="text-2xl font-bold text-green-400 mb-2">Félicitations!</h2>
<p id="success-message" class="mb-6">Vous avez résolu le problème avec succès!</p>
<div class="flex justify-center space-x-4">
<button id="next-level-btn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium">
Niveau Suivant
</button>
<button id="close-modal-btn" class="px-6 py-2 bg-gray-600 hover:bg-gray-700 rounded-md font-medium">
Fermer
</button>
</div>
</div>
</div>
<!-- Help Modal -->
<div id="help-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 rounded-xl p-8 max-w-2xl w-full mx-4 max-h-[80vh] overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-blue-400 flex items-center">
<i class="fas fa-question-circle mr-3"></i> Aide RoboMath
</h2>
<button id="close-help-btn" class="text-gray-400 hover:text-white">
<i class="fas fa-times text-2xl"></i>
</button>
</div>
<div class="space-y-6">
<div>
<h3 class="text-xl font-bold text-purple-300 mb-3">Comment jouer</h3>
<p class="mb-4">RoboMath est un jeu éducatif qui combine programmation et mathématiques. Votre objectif est de programmer un robot virtuel pour résoudre des problèmes mathématiques.</p>
<div class="bg-gray-700 p-4 rounded-lg mb-4">
<h4 class="font-bold text-yellow-300 mb-2">Étapes pour réussir :</h4>
<ol class="list-decimal pl-5 space-y-2">
<li>Lisez attentivement le problème mathématique affiché</li>
<li>Construisez un programme en glissant-déposant les commandes disponibles</li>
<li>Exécutez votre programme avec le bouton "Exécuter"</li>
<li>Observez le résultat affiché par le robot</li>
<li>Si le résultat est correct, passez au niveau suivant!</li>
</ol>
</div>
</div>
<div>
<h3 class="text-xl font-bold text-green-300 mb-3">Commandes disponibles</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-arrow-right mr-2"></i> Avancer</h4>
<p class="text-sm mt-1">Fait avancer le robot dans la direction actuelle</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-undo mr-2"></i> Tourner Gauche</h4>
<p class="text-sm mt-1">Tourne le robot de 90° vers la gauche</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-redo mr-2"></i> Tourner Droite</h4>
<p class="text-sm mt-1">Tourne le robot de 90° vers la droite</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-memory mr-2"></i> Définir Variable</h4>
<p class="text-sm mt-1">Initialise une variable avec une valeur</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-plus-circle mr-2"></i> Incrémenter</h4>
<p class="text-sm mt-1">Augmente la valeur d'une variable de 1</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-plus mr-2"></i> Ajouter à</h4>
<p class="text-sm mt-1">Ajoute une valeur spécifique à une variable</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-print mr-2"></i> Afficher</h4>
<p class="text-sm mt-1">Affiche la valeur d'une variable</p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<h4 class="font-bold flex items-center"><i class="fas fa-repeat mr-2"></i> Boucle</h4>
<p class="text-sm mt-1">Répète un bloc d'instructions plusieurs fois</p>
</div>
</div>
</div>
<div>
<h3 class="text-xl font-bold text-red-300 mb-3">Conseils pour réussir</h3>
<div class="bg-gray-700 p-4 rounded-lg">
<ul class="list-disc pl-5 space-y-2">
<li>Commencez par analyser le problème mathématique</li>
<li>Décomposez le problème en étapes simples</li>
<li>Utilisez des variables pour stocker des résultats intermédiaires</li>
<li>Les boucles sont utiles pour répéter des opérations similaires</li>
<li>Testez souvent votre programme avec des valeurs simples</li>
<li>Consultez la console pour voir l'exécution pas à pas</li>
</ul>
</div>
</div>
<div class="text-center pt-4">
<button id="close-help-btn-2" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium">
J'ai compris!
</button>
</div>
</div>
</div>
</div>
<script>
// Game state
const gameState = {
level: 1,
score: 0,
progress: 0,
variables: {
x: 0,
y: 0,
z: 0,
result: 0
},
program: [],
problems: [
{
statement: "Programmez le robot pour qu'il calcule la somme des nombres de 1 à 5 et affiche le résultat.",
expression: "1 + 2 + 3 + 4 + 5 = ?",
solution: 15,
hint: "Utilisez une boucle et une variable pour accumuler la somme."
},
{
statement: "Calculez le produit des nombres de 1 à 4 (factorielle de 4) et affichez le résultat.",
expression: "1 × 2 × 3 × 4 = ?",
solution: 24,
hint: "Initialisez une variable à 1, puis multipliez-la par chaque nombre dans une boucle."
},
{
statement: "Trouvez la somme des nombres pairs entre 2 et 10 et affichez le résultat.",
expression: "2 + 4 + 6 + 8 + 10 = ?",
solution: 30,
hint: "Utilisez une condition dans votre boucle pour n'ajouter que les nombres pairs."
}
]
};
// DOM elements
const elements = {
level: document.getElementById('level'),
score: document.getElementById('score'),
progressBar: document.getElementById('progress-bar'),
problemStatement: document.getElementById('problem-statement'),
mathExpression: document.getElementById('math-expression'),
robot: document.getElementById('robot'),
robotContainer: document.getElementById('robot-container'),
outputDisplay: document.getElementById('output-display'),
progressTrack: document.getElementById('progress-track'),
codeBlock: document.getElementById('code-block'),
codePlaceholder: document.getElementById('code-placeholder'),
consoleOutput: document.getElementById('console-output'),
varX: document.getElementById('var-x'),
varY: document.getElementById('var-y'),
varZ: document.getElementById('var-z'),
varResult: document.getElementById('var-result'),
runBtn: document.getElementById('run-btn'),
debugBtn: document.getElementById('debug-btn'),
clearBtn: document.getElementById('clear-btn'),
resetBtn: document.getElementById('reset-btn'),
helpBtn: document.getElementById('help-btn'),
commandBtns: document.querySelectorAll('.command-btn'),
successModal: document.getElementById('success-modal'),
successMessage: document.getElementById('success-message'),
nextLevelBtn: document.getElementById('next-level-btn'),
closeModalBtn: document.getElementById('close-modal-btn'),
helpModal: document.getElementById('help-modal'),
closeHelpBtn: document.getElementById('close-help-btn'),
closeHelpBtn2: document.getElementById('close-help-btn-2')
};
// Initialize the game
function initGame() {
updateGameState();
setupEventListeners();
loadLevel(gameState.level);
}
// Update UI based on game state
function updateGameState() {
elements.level.textContent = `Niveau ${gameState.level}`;
elements.score.textContent = gameState.score;
elements.progressBar.style.width = `${gameState.progress}%`;
// Update variables display
elements.varX.textContent = gameState.variables.x;
elements.varY.textContent = gameState.variables.y;
elements.varZ.textContent = gameState.variables.z;
elements.varResult.textContent = gameState.variables.result;
}
// Load a specific level
function loadLevel(level) {
const problem = gameState.problems[level - 1];
if (!problem) {
// No more levels
elements.problemStatement.textContent = "Vous avez terminé tous les niveaux!";
elements.mathExpression.textContent = "Bravo!";
return;
}
elements.problemStatement.textContent = problem.statement;
elements.mathExpression.textContent = problem.expression;
// Reset variables and program
gameState.variables = {
x: 0,
y: 0,
z: 0,
result: 0
};
gameState.program = [];
updateCodeDisplay();
// Reset robot position
elements.robot.style.left = '1rem';
elements.robot.style.bottom = '1rem';
elements.robot.style.transform = 'rotate(0deg)';
elements.outputDisplay.textContent = '?';
elements.progressTrack.style.width = '0%';
// Clear console
elements.consoleOutput.innerHTML = '<div class="text-gray-400">Bienvenue dans RoboMath! Commencez à programmer votre robot.</div>';
updateGameState();
}
// Update the code display area
function updateCodeDisplay() {
if (gameState.program.length === 0) {
elements.codePlaceholder.classList.remove('hidden');
elements.codeBlock.innerHTML = '<div id="code-placeholder" class="text-gray-400 italic">Glissez les commandes ici ou cliquez pour les ajouter</div>';
return;
}
elements.codePlaceholder.classList.add('hidden');
elements.codeBlock.innerHTML = '';
gameState.program.forEach((cmd, index) => {
const cmdElement = document.createElement('div');
cmdElement.className = 'flex items-center mb-1 draggable';
cmdElement.dataset.index = index;
const cmdText = document.createElement('span');
cmdText.className = 'font-mono text-sm bg-gray-700 px-2 py-1 rounded mr-2';
cmdText.textContent = cmd;
const deleteBtn = document.createElement('button');
deleteBtn.className = 'text-red-400 hover:text-red-300';
deleteBtn.innerHTML = '<i class="fas fa-times"></i>';
deleteBtn.onclick = () => removeCommand(index);
cmdElement.appendChild(cmdText);
cmdElement.appendChild(deleteBtn);
elements.codeBlock.appendChild(cmdElement);
});
}
// Add a command to the program
function addCommand(command) {
gameState.program.push(command);
updateCodeDisplay();
}
// Remove a command from the program
function removeCommand(index) {
gameState.program.splice(index, 1);
updateCodeDisplay();
}
// Execute the program
function executeProgram() {
// Reset variables
gameState.variables = {
x: 0,
y: 0,
z: 0,
result: 0
};
// Reset robot position
elements.robot.style.left = '1rem';
elements.robot.style.bottom = '1rem';
elements.robot.style.transform = 'rotate(0deg)';
elements.outputDisplay.textContent = '?';
elements.progressTrack.style.width = '0%';
// Clear console
elements.consoleOutput.innerHTML = '';
// Add execution started message
addConsoleMessage("Début de l'exécution du programme...", "info");
// Execute each command with a delay for visualization
let position = { x: 16, y: 0 };
let rotation = 0;
let loopStack = [];
let loopCounters = {};
let currentLoop = null;
const executeNextCommand = (index) => {
if (index >= gameState.program.length) {
// Program finished
addConsoleMessage("Programme terminé.", "success");
checkSolution();
return;
}
const command = gameState.program[index];
let delay = 500; // Default delay between commands
// Parse and execute command
if (command.startsWith("moveForward()")) {
// Calculate new position based on rotation
const moveAmount = 40;
if (rotation === 0) {
position.x += moveAmount;
} else if (rotation === 90) {
position.y -= moveAmount;
} else if (rotation === 180) {
position.x -= moveAmount;
} else if (rotation === 270) {
position.y += moveAmount;
}
// Limit movement to container
const containerWidth = elements.robotContainer.offsetWidth;
const containerHeight = elements.robotContainer.offsetHeight;
const robotWidth = 64;
const robotHeight = 96;
position.x = Math.max(16, Math.min(position.x, containerWidth - robotWidth - 16));
position.y = Math.max(-containerHeight + robotHeight + 16, Math.min(position.y, 0));
elements.robot.style.left = `${position.x}px`;
elements.robot.style.bottom = `${-position.y}px`;
addConsoleMessage(`Robot avance (direction: ${rotation}°)`, "command");
}
else if (command.startsWith("turnLeft()")) {
rotation = (rotation - 90 + 360) % 360;
elements.robot.style.transform = `rotate(${rotation}deg)`;
addConsoleMessage("Robot tourne à gauche", "command");
}
else if (command.startsWith("turnRight()")) {
rotation = (rotation + 90) % 360;
elements.robot.style.transform = `rotate(${rotation}deg)`;
addConsoleMessage("Robot tourne à droite", "command");
}
else if (command.startsWith("setVariable(")) {
const matches = command.match(/setVariable\('(\w+)', (\d+)\)/);
if (matches) {
const varName = matches[1];
const value = parseInt(matches[2]);
gameState.variables[varName] = value;
updateGameState();
addConsoleMessage(`Variable ${varName} définie à ${value}`, "command");
}
}
else if (command.startsWith("increment(")) {
const varName = command.match(/increment\('(\w+)'\)/)[1];
gameState.variables[varName]++;
updateGameState();
addConsoleMessage(`Variable ${varName} incrémentée à ${gameState.variables[varName]}`, "command");
}
else if (command.startsWith("addTo(")) {
const matches = command.match(/addTo\('(\w+)', (\d+)\)/);
if (matches) {
const varName = matches[1];
const value = parseInt(matches[2]);
gameState.variables[varName] += value;
updateGameState();
addConsoleMessage(`Ajouté ${value} à ${varName} (nouvelle valeur: ${gameState.variables[varName]})`, "command");
}
}
else if (command.startsWith("print(")) {
const varName = command.match(/print\('(\w+)'\)/)[1];
const value = gameState.variables[varName];
elements.outputDisplay.textContent = value;
addConsoleMessage(`Affichage: ${varName} = ${value}`, "output");
}
else if (command.startsWith("loop(")) {
const loopCount = parseInt(command.match(/loop\((\d+)\)/)[1]);
loopStack.push({
startIndex: index,
count: loopCount,
current: 0
});
addConsoleMessage(`Début de boucle (${loopCount} itérations)`, "command");
delay = 0; // No delay for loop start
}
else if (command === "endLoop") {
const currentLoop = loopStack[loopStack.length - 1];
currentLoop.current++;
if (currentLoop.current < currentLoop.count) {
// Next iteration
index = currentLoop.startIndex;
addConsoleMessage(`Itération ${currentLoop.current + 1} de ${currentLoop.count}`, "command");
delay = 0; // No delay for loop iteration
} else {
// Loop finished
loopStack.pop();
addConsoleMessage("Fin de boucle", "command");
}
}
// Update progress track
const progress = (index + 1) / gameState.program.length * 100;
elements.progressTrack.style.width = `${progress}%`;
// Execute next command after delay
setTimeout(() => executeNextCommand(index + 1), delay);
};
// Start execution
executeNextCommand(0);
}
// Check if the solution is correct
function checkSolution() {
const currentProblem = gameState.problems[gameState.level - 1];
if (!currentProblem) return;
const userResult = parseInt(elements.outputDisplay.textContent);
if (userResult === currentProblem.solution) {
// Correct solution
gameState.score += 100;
gameState.progress += 33;
// Show success modal
elements.successMessage.textContent = `Vous avez résolu le problème! La réponse correcte était ${currentProblem.solution}.`;
elements.successModal.classList.remove('hidden');
// Disable next level button if no more levels
if (gameState.level >= gameState.problems.length) {
elements.nextLevelBtn.disabled = true;
elements.nextLevelBtn.textContent = "Niveau Max Atteint";
elements.nextLevelBtn.classList.add('opacity-50', 'cursor-not-allowed');
}
updateGameState();
} else {
// Incorrect solution
addConsoleMessage(`Le résultat ${userResult} est incorrect. Essayez encore!`, "error");
addConsoleMessage(`Indice: ${currentProblem.hint}`, "info");
}
}
// Add a message to the console
function addConsoleMessage(message, type = "info") {
const messageElement = document.createElement('div');
messageElement.className = `mb-1 ${type === 'error' ? 'text-red-400' : type === 'success' ? 'text-green-400' : type === 'command' ? 'text-blue-300' : type === 'output' ? 'text-yellow-300' : 'text-gray-300'}`;
const timestamp = new Date().toLocaleTimeString();
messageElement.innerHTML = `<span class="text-gray-500 text-xs mr-2">[${timestamp}]</span> ${message}`;
elements.consoleOutput.appendChild(messageElement);
elements.consoleOutput.scrollTop = elements.consoleOutput.scrollHeight;
}
// Setup event listeners
function setupEventListeners() {
// Command buttons
elements.commandBtns.forEach(btn => {
btn.addEventListener('click', () => {
addCommand(btn.dataset.command);
});
// Drag and drop functionality
btn.setAttribute('draggable', 'true');
btn.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', btn.dataset.command);
});
});
// Code block drop zone
elements.codeBlock.addEventListener('dragover', (e) => {
e.preventDefault();
elements.codeBlock.classList.add('bg-gray-700');
});
elements.codeBlock.addEventListener('dragleave', () => {
elements.codeBlock.classList.remove('bg-gray-700');
});
elements.codeBlock.addEventListener('drop', (e) => {
e.preventDefault();
elements.codeBlock.classList.remove('bg-gray-700');
const command = e.dataTransfer.getData('text/plain');
if (command) {
addCommand(command);
}
});
// Action buttons
elements.runBtn.addEventListener('click', () => {
if (gameState.program.length === 0) {
addConsoleMessage("Aucune commande à exécuter. Ajoutez des commandes d'abord.", "error");
return;
}
executeProgram();
});
elements.debugBtn.addEventListener('click', () => {
addConsoleMessage("Mode débogage activé (fonctionnalité à venir)", "info");
});
elements.clearBtn.addEventListener('click', () => {
gameState.program = [];
updateCodeDisplay();
addConsoleMessage("Programme effacé", "info");
});
elements.resetBtn.addEventListener('click', () => {
gameState.score = 0;
gameState.progress = 0;
loadLevel(gameState.level);
addConsoleMessage("Jeu réinitialisé", "info");
});
// Help button
elements.helpBtn.addEventListener('click', () => {
elements.helpModal.classList.remove('hidden');
});
// Modal buttons
elements.nextLevelBtn.addEventListener('click', () => {
gameState.level++;
loadLevel(gameState.level);
elements.successModal.classList.add('hidden');
});
elements.closeModalBtn.addEventListener('click', () => {
elements.successModal.classList.add('hidden');
});
// Help modal buttons
elements.closeHelpBtn.addEventListener('click', () => {
elements.helpModal.classList.add('hidden');
});
elements.closeHelpBtn2.addEventListener('click', () => {
elements.helpModal.classList.add('hidden');
});
}
// Initialize the game when DOM is loaded
document.addEventListener('DOMContentLoaded', initGame);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=olinux/robomath" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>