olinux commited on
Commit
28ad2a0
·
verified ·
1 Parent(s): 428a6be

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +773 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Robomath
3
- emoji: 🏢
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: robomath
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,773 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="fr">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>RoboMath - Apprendre la programmation et les maths</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .code-block {
11
+ font-family: 'Courier New', monospace;
12
+ background-color: #2d3748;
13
+ color: #f7fafc;
14
+ border-radius: 0.5rem;
15
+ padding: 1rem;
16
+ min-height: 150px;
17
+ }
18
+ .robot {
19
+ transition: all 0.5s ease;
20
+ position: absolute;
21
+ bottom: 1rem;
22
+ left: 1rem;
23
+ }
24
+ .command-btn {
25
+ transition: all 0.2s ease;
26
+ }
27
+ .command-btn:hover {
28
+ transform: translateY(-2px);
29
+ }
30
+ .droppable {
31
+ min-height: 50px;
32
+ background-color: #4a5568;
33
+ border: 2px dashed #718096;
34
+ border-radius: 0.5rem;
35
+ }
36
+ .draggable {
37
+ cursor: move;
38
+ user-select: none;
39
+ }
40
+ .progress-track {
41
+ 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);
42
+ background-size: 1rem 1rem;
43
+ }
44
+ .modal {
45
+ transition: opacity 0.3s ease;
46
+ }
47
+ </style>
48
+ </head>
49
+ <body class="bg-gray-900 text-gray-100 min-h-screen">
50
+ <div class="container mx-auto px-4 py-8">
51
+ <!-- Header -->
52
+ <header class="flex flex-col md:flex-row justify-between items-center mb-8">
53
+ <div class="flex items-center mb-4 md:mb-0">
54
+ <i class="fas fa-robot text-4xl text-blue-400 mr-3"></i>
55
+ <h1 class="text-3xl font-bold bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">RoboMath</h1>
56
+ </div>
57
+ <div class="flex items-center space-x-4">
58
+ <button id="help-btn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-medium transition">
59
+ <i class="fas fa-question-circle mr-1"></i> Aide
60
+ </button>
61
+ <div class="flex items-center">
62
+ <span class="mr-2 text-yellow-300"><i class="fas fa-star"></i></span>
63
+ <span id="score" class="font-bold">0</span>
64
+ </div>
65
+ <div class="relative">
66
+ <div class="h-3 w-32 bg-gray-700 rounded-full overflow-hidden">
67
+ <div id="progress-bar" class="h-full bg-gradient-to-r from-green-400 to-blue-500 rounded-full" style="width: 0%"></div>
68
+ </div>
69
+ <span id="level" class="absolute -top-6 left-0 text-xs font-bold">Niveau 1</span>
70
+ </div>
71
+ <button id="reset-btn" class="px-3 py-1 bg-red-600 hover:bg-red-700 rounded-md text-sm font-medium transition">
72
+ <i class="fas fa-redo mr-1"></i> Réinitialiser
73
+ </button>
74
+ </div>
75
+ </header>
76
+
77
+ <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
78
+ <!-- Left Panel - Game Area -->
79
+ <div class="lg:col-span-2 space-y-6">
80
+ <!-- Problem Statement -->
81
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
82
+ <h2 class="text-xl font-bold mb-4 text-blue-300 flex items-center">
83
+ <i class="fas fa-question-circle mr-2"></i> Problème Mathématique
84
+ </h2>
85
+ <div id="problem-statement" class="text-lg">
86
+ Programmez le robot pour qu'il calcule la somme des nombres de 1 à 5 et affiche le résultat.
87
+ </div>
88
+ <div id="math-expression" class="mt-4 p-3 bg-gray-700 rounded-md text-center text-xl font-mono">
89
+ 1 + 2 + 3 + 4 + 5 = ?
90
+ </div>
91
+ </div>
92
+
93
+ <!-- Robot Visualization -->
94
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
95
+ <h2 class="text-xl font-bold mb-4 text-purple-300 flex items-center">
96
+ <i class="fas fa-robot mr-2"></i> Zone du Robot
97
+ </h2>
98
+ <div class="flex flex-col items-center">
99
+ <div id="robot-container" class="relative w-full h-48 bg-gray-700 rounded-lg mb-4 overflow-hidden">
100
+ <div id="robot" class="robot w-16 h-24 bg-blue-500 rounded-t-lg flex flex-col items-center">
101
+ <div class="w-12 h-8 bg-blue-400 rounded-t-full mt-1 flex justify-center items-center">
102
+ <div class="w-2 h-2 bg-yellow-300 rounded-full mx-1"></div>
103
+ <div class="w-2 h-2 bg-yellow-300 rounded-full mx-1"></div>
104
+ </div>
105
+ <div class="w-14 h-12 bg-blue-400 rounded-b-lg mt-1 flex justify-center items-center text-white font-bold">
106
+ R-1
107
+ </div>
108
+ </div>
109
+ <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">
110
+ ?
111
+ </div>
112
+ </div>
113
+ <div class="w-full bg-gray-700 h-2 rounded-full overflow-hidden">
114
+ <div id="progress-track" class="progress-track h-full bg-gradient-to-r from-blue-500 to-purple-500" style="width: 0%"></div>
115
+ </div>
116
+ </div>
117
+ </div>
118
+ </div>
119
+
120
+ <!-- Right Panel - Programming Area -->
121
+ <div class="space-y-6">
122
+ <!-- Command Palette -->
123
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
124
+ <h2 class="text-xl font-bold mb-4 text-green-300 flex items-center">
125
+ <i class="fas fa-code mr-2"></i> Commandes Disponibles
126
+ </h2>
127
+ <div class="grid grid-cols-2 gap-2">
128
+ <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">
129
+ <i class="fas fa-arrow-right mr-2"></i> Avancer
130
+ </button>
131
+ <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">
132
+ <i class="fas fa-undo mr-2"></i> Tourner Gauche
133
+ </button>
134
+ <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">
135
+ <i class="fas fa-redo mr-2"></i> Tourner Droite
136
+ </button>
137
+ <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">
138
+ <i class="fas fa-memory mr-2"></i> Définir Variable
139
+ </button>
140
+ <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">
141
+ <i class="fas fa-plus-circle mr-2"></i> Incrémenter
142
+ </button>
143
+ <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">
144
+ <i class="fas fa-plus mr-2"></i> Ajouter à
145
+ </button>
146
+ <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">
147
+ <i class="fas fa-print mr-2"></i> Afficher
148
+ </button>
149
+ <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">
150
+ <i class="fas fa-repeat mr-2"></i> Boucle
151
+ </button>
152
+ </div>
153
+ </div>
154
+
155
+ <!-- Code Editor -->
156
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
157
+ <div class="flex justify-between items-center mb-4">
158
+ <h2 class="text-xl font-bold text-yellow-300 flex items-center">
159
+ <i class="fas fa-laptop-code mr-2"></i> Votre Programme
160
+ </h2>
161
+ <button id="clear-btn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-md text-sm font-medium transition">
162
+ <i class="fas fa-trash-alt mr-1"></i> Effacer
163
+ </button>
164
+ </div>
165
+ <div id="code-block" class="code-block droppable">
166
+ <div id="code-placeholder" class="text-gray-400 italic">Glissez les commandes ici ou cliquez pour les ajouter</div>
167
+ </div>
168
+ <div class="mt-4 flex justify-between">
169
+ <button id="run-btn" class="px-4 py-2 bg-green-600 hover:bg-green-700 rounded-md font-medium flex items-center transition">
170
+ <i class="fas fa-play mr-2"></i> Exécuter
171
+ </button>
172
+ <button id="debug-btn" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium flex items-center transition">
173
+ <i class="fas fa-bug mr-2"></i> Déboguer
174
+ </button>
175
+ </div>
176
+ </div>
177
+
178
+ <!-- Variables Panel -->
179
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
180
+ <h2 class="text-xl font-bold mb-4 text-pink-300 flex items-center">
181
+ <i class="fas fa-memory mr-2"></i> Variables
182
+ </h2>
183
+ <div id="variables-panel" class="grid grid-cols-2 gap-2">
184
+ <div class="bg-gray-700 p-2 rounded">
185
+ <div class="text-xs text-gray-400">x</div>
186
+ <div id="var-x" class="font-mono">0</div>
187
+ </div>
188
+ <div class="bg-gray-700 p-2 rounded">
189
+ <div class="text-xs text-gray-400">y</div>
190
+ <div id="var-y" class="font-mono">0</div>
191
+ </div>
192
+ <div class="bg-gray-700 p-2 rounded">
193
+ <div class="text-xs text-gray-400">z</div>
194
+ <div id="var-z" class="font-mono">0</div>
195
+ </div>
196
+ <div class="bg-gray-700 p-2 rounded">
197
+ <div class="text-xs text-gray-400">result</div>
198
+ <div id="var-result" class="font-mono">0</div>
199
+ </div>
200
+ </div>
201
+ </div>
202
+ </div>
203
+ </div>
204
+
205
+ <!-- Console Output -->
206
+ <div class="mt-6 bg-gray-800 rounded-xl p-6 shadow-lg">
207
+ <h2 class="text-xl font-bold mb-4 text-red-300 flex items-center">
208
+ <i class="fas fa-terminal mr-2"></i> Console
209
+ </h2>
210
+ <div id="console-output" class="code-block h-24 overflow-y-auto">
211
+ <div class="text-gray-400">Bienvenue dans RoboMath! Commencez à programmer votre robot.</div>
212
+ </div>
213
+ </div>
214
+ </div>
215
+
216
+ <!-- Success Modal -->
217
+ <div id="success-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
218
+ <div class="bg-gray-800 rounded-xl p-8 max-w-md w-full mx-4 text-center">
219
+ <div class="text-6xl text-yellow-400 mb-4">
220
+ <i class="fas fa-trophy"></i>
221
+ </div>
222
+ <h2 class="text-2xl font-bold text-green-400 mb-2">Félicitations!</h2>
223
+ <p id="success-message" class="mb-6">Vous avez résolu le problème avec succès!</p>
224
+ <div class="flex justify-center space-x-4">
225
+ <button id="next-level-btn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium">
226
+ Niveau Suivant
227
+ </button>
228
+ <button id="close-modal-btn" class="px-6 py-2 bg-gray-600 hover:bg-gray-700 rounded-md font-medium">
229
+ Fermer
230
+ </button>
231
+ </div>
232
+ </div>
233
+ </div>
234
+
235
+ <!-- Help Modal -->
236
+ <div id="help-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
237
+ <div class="bg-gray-800 rounded-xl p-8 max-w-2xl w-full mx-4 max-h-[80vh] overflow-y-auto">
238
+ <div class="flex justify-between items-center mb-6">
239
+ <h2 class="text-2xl font-bold text-blue-400 flex items-center">
240
+ <i class="fas fa-question-circle mr-3"></i> Aide RoboMath
241
+ </h2>
242
+ <button id="close-help-btn" class="text-gray-400 hover:text-white">
243
+ <i class="fas fa-times text-2xl"></i>
244
+ </button>
245
+ </div>
246
+
247
+ <div class="space-y-6">
248
+ <div>
249
+ <h3 class="text-xl font-bold text-purple-300 mb-3">Comment jouer</h3>
250
+ <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>
251
+
252
+ <div class="bg-gray-700 p-4 rounded-lg mb-4">
253
+ <h4 class="font-bold text-yellow-300 mb-2">Étapes pour réussir :</h4>
254
+ <ol class="list-decimal pl-5 space-y-2">
255
+ <li>Lisez attentivement le problème mathématique affiché</li>
256
+ <li>Construisez un programme en glissant-déposant les commandes disponibles</li>
257
+ <li>Exécutez votre programme avec le bouton "Exécuter"</li>
258
+ <li>Observez le résultat affiché par le robot</li>
259
+ <li>Si le résultat est correct, passez au niveau suivant!</li>
260
+ </ol>
261
+ </div>
262
+ </div>
263
+
264
+ <div>
265
+ <h3 class="text-xl font-bold text-green-300 mb-3">Commandes disponibles</h3>
266
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
267
+ <div class="bg-gray-700 p-3 rounded-lg">
268
+ <h4 class="font-bold flex items-center"><i class="fas fa-arrow-right mr-2"></i> Avancer</h4>
269
+ <p class="text-sm mt-1">Fait avancer le robot dans la direction actuelle</p>
270
+ </div>
271
+ <div class="bg-gray-700 p-3 rounded-lg">
272
+ <h4 class="font-bold flex items-center"><i class="fas fa-undo mr-2"></i> Tourner Gauche</h4>
273
+ <p class="text-sm mt-1">Tourne le robot de 90° vers la gauche</p>
274
+ </div>
275
+ <div class="bg-gray-700 p-3 rounded-lg">
276
+ <h4 class="font-bold flex items-center"><i class="fas fa-redo mr-2"></i> Tourner Droite</h4>
277
+ <p class="text-sm mt-1">Tourne le robot de 90° vers la droite</p>
278
+ </div>
279
+ <div class="bg-gray-700 p-3 rounded-lg">
280
+ <h4 class="font-bold flex items-center"><i class="fas fa-memory mr-2"></i> Définir Variable</h4>
281
+ <p class="text-sm mt-1">Initialise une variable avec une valeur</p>
282
+ </div>
283
+ <div class="bg-gray-700 p-3 rounded-lg">
284
+ <h4 class="font-bold flex items-center"><i class="fas fa-plus-circle mr-2"></i> Incrémenter</h4>
285
+ <p class="text-sm mt-1">Augmente la valeur d'une variable de 1</p>
286
+ </div>
287
+ <div class="bg-gray-700 p-3 rounded-lg">
288
+ <h4 class="font-bold flex items-center"><i class="fas fa-plus mr-2"></i> Ajouter à</h4>
289
+ <p class="text-sm mt-1">Ajoute une valeur spécifique à une variable</p>
290
+ </div>
291
+ <div class="bg-gray-700 p-3 rounded-lg">
292
+ <h4 class="font-bold flex items-center"><i class="fas fa-print mr-2"></i> Afficher</h4>
293
+ <p class="text-sm mt-1">Affiche la valeur d'une variable</p>
294
+ </div>
295
+ <div class="bg-gray-700 p-3 rounded-lg">
296
+ <h4 class="font-bold flex items-center"><i class="fas fa-repeat mr-2"></i> Boucle</h4>
297
+ <p class="text-sm mt-1">Répète un bloc d'instructions plusieurs fois</p>
298
+ </div>
299
+ </div>
300
+ </div>
301
+
302
+ <div>
303
+ <h3 class="text-xl font-bold text-red-300 mb-3">Conseils pour réussir</h3>
304
+ <div class="bg-gray-700 p-4 rounded-lg">
305
+ <ul class="list-disc pl-5 space-y-2">
306
+ <li>Commencez par analyser le problème mathématique</li>
307
+ <li>Décomposez le problème en étapes simples</li>
308
+ <li>Utilisez des variables pour stocker des résultats intermédiaires</li>
309
+ <li>Les boucles sont utiles pour répéter des opérations similaires</li>
310
+ <li>Testez souvent votre programme avec des valeurs simples</li>
311
+ <li>Consultez la console pour voir l'exécution pas à pas</li>
312
+ </ul>
313
+ </div>
314
+ </div>
315
+
316
+ <div class="text-center pt-4">
317
+ <button id="close-help-btn-2" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-md font-medium">
318
+ J'ai compris!
319
+ </button>
320
+ </div>
321
+ </div>
322
+ </div>
323
+ </div>
324
+
325
+ <script>
326
+ // Game state
327
+ const gameState = {
328
+ level: 1,
329
+ score: 0,
330
+ progress: 0,
331
+ variables: {
332
+ x: 0,
333
+ y: 0,
334
+ z: 0,
335
+ result: 0
336
+ },
337
+ program: [],
338
+ problems: [
339
+ {
340
+ statement: "Programmez le robot pour qu'il calcule la somme des nombres de 1 à 5 et affiche le résultat.",
341
+ expression: "1 + 2 + 3 + 4 + 5 = ?",
342
+ solution: 15,
343
+ hint: "Utilisez une boucle et une variable pour accumuler la somme."
344
+ },
345
+ {
346
+ statement: "Calculez le produit des nombres de 1 à 4 (factorielle de 4) et affichez le résultat.",
347
+ expression: "1 × 2 × 3 × 4 = ?",
348
+ solution: 24,
349
+ hint: "Initialisez une variable à 1, puis multipliez-la par chaque nombre dans une boucle."
350
+ },
351
+ {
352
+ statement: "Trouvez la somme des nombres pairs entre 2 et 10 et affichez le résultat.",
353
+ expression: "2 + 4 + 6 + 8 + 10 = ?",
354
+ solution: 30,
355
+ hint: "Utilisez une condition dans votre boucle pour n'ajouter que les nombres pairs."
356
+ }
357
+ ]
358
+ };
359
+
360
+ // DOM elements
361
+ const elements = {
362
+ level: document.getElementById('level'),
363
+ score: document.getElementById('score'),
364
+ progressBar: document.getElementById('progress-bar'),
365
+ problemStatement: document.getElementById('problem-statement'),
366
+ mathExpression: document.getElementById('math-expression'),
367
+ robot: document.getElementById('robot'),
368
+ robotContainer: document.getElementById('robot-container'),
369
+ outputDisplay: document.getElementById('output-display'),
370
+ progressTrack: document.getElementById('progress-track'),
371
+ codeBlock: document.getElementById('code-block'),
372
+ codePlaceholder: document.getElementById('code-placeholder'),
373
+ consoleOutput: document.getElementById('console-output'),
374
+ varX: document.getElementById('var-x'),
375
+ varY: document.getElementById('var-y'),
376
+ varZ: document.getElementById('var-z'),
377
+ varResult: document.getElementById('var-result'),
378
+ runBtn: document.getElementById('run-btn'),
379
+ debugBtn: document.getElementById('debug-btn'),
380
+ clearBtn: document.getElementById('clear-btn'),
381
+ resetBtn: document.getElementById('reset-btn'),
382
+ helpBtn: document.getElementById('help-btn'),
383
+ commandBtns: document.querySelectorAll('.command-btn'),
384
+ successModal: document.getElementById('success-modal'),
385
+ successMessage: document.getElementById('success-message'),
386
+ nextLevelBtn: document.getElementById('next-level-btn'),
387
+ closeModalBtn: document.getElementById('close-modal-btn'),
388
+ helpModal: document.getElementById('help-modal'),
389
+ closeHelpBtn: document.getElementById('close-help-btn'),
390
+ closeHelpBtn2: document.getElementById('close-help-btn-2')
391
+ };
392
+
393
+ // Initialize the game
394
+ function initGame() {
395
+ updateGameState();
396
+ setupEventListeners();
397
+ loadLevel(gameState.level);
398
+ }
399
+
400
+ // Update UI based on game state
401
+ function updateGameState() {
402
+ elements.level.textContent = `Niveau ${gameState.level}`;
403
+ elements.score.textContent = gameState.score;
404
+ elements.progressBar.style.width = `${gameState.progress}%`;
405
+
406
+ // Update variables display
407
+ elements.varX.textContent = gameState.variables.x;
408
+ elements.varY.textContent = gameState.variables.y;
409
+ elements.varZ.textContent = gameState.variables.z;
410
+ elements.varResult.textContent = gameState.variables.result;
411
+ }
412
+
413
+ // Load a specific level
414
+ function loadLevel(level) {
415
+ const problem = gameState.problems[level - 1];
416
+ if (!problem) {
417
+ // No more levels
418
+ elements.problemStatement.textContent = "Vous avez terminé tous les niveaux!";
419
+ elements.mathExpression.textContent = "Bravo!";
420
+ return;
421
+ }
422
+
423
+ elements.problemStatement.textContent = problem.statement;
424
+ elements.mathExpression.textContent = problem.expression;
425
+
426
+ // Reset variables and program
427
+ gameState.variables = {
428
+ x: 0,
429
+ y: 0,
430
+ z: 0,
431
+ result: 0
432
+ };
433
+ gameState.program = [];
434
+ updateCodeDisplay();
435
+
436
+ // Reset robot position
437
+ elements.robot.style.left = '1rem';
438
+ elements.robot.style.bottom = '1rem';
439
+ elements.robot.style.transform = 'rotate(0deg)';
440
+ elements.outputDisplay.textContent = '?';
441
+ elements.progressTrack.style.width = '0%';
442
+
443
+ // Clear console
444
+ elements.consoleOutput.innerHTML = '<div class="text-gray-400">Bienvenue dans RoboMath! Commencez à programmer votre robot.</div>';
445
+
446
+ updateGameState();
447
+ }
448
+
449
+ // Update the code display area
450
+ function updateCodeDisplay() {
451
+ if (gameState.program.length === 0) {
452
+ elements.codePlaceholder.classList.remove('hidden');
453
+ elements.codeBlock.innerHTML = '<div id="code-placeholder" class="text-gray-400 italic">Glissez les commandes ici ou cliquez pour les ajouter</div>';
454
+ return;
455
+ }
456
+
457
+ elements.codePlaceholder.classList.add('hidden');
458
+ elements.codeBlock.innerHTML = '';
459
+
460
+ gameState.program.forEach((cmd, index) => {
461
+ const cmdElement = document.createElement('div');
462
+ cmdElement.className = 'flex items-center mb-1 draggable';
463
+ cmdElement.dataset.index = index;
464
+
465
+ const cmdText = document.createElement('span');
466
+ cmdText.className = 'font-mono text-sm bg-gray-700 px-2 py-1 rounded mr-2';
467
+ cmdText.textContent = cmd;
468
+
469
+ const deleteBtn = document.createElement('button');
470
+ deleteBtn.className = 'text-red-400 hover:text-red-300';
471
+ deleteBtn.innerHTML = '<i class="fas fa-times"></i>';
472
+ deleteBtn.onclick = () => removeCommand(index);
473
+
474
+ cmdElement.appendChild(cmdText);
475
+ cmdElement.appendChild(deleteBtn);
476
+ elements.codeBlock.appendChild(cmdElement);
477
+ });
478
+ }
479
+
480
+ // Add a command to the program
481
+ function addCommand(command) {
482
+ gameState.program.push(command);
483
+ updateCodeDisplay();
484
+ }
485
+
486
+ // Remove a command from the program
487
+ function removeCommand(index) {
488
+ gameState.program.splice(index, 1);
489
+ updateCodeDisplay();
490
+ }
491
+
492
+ // Execute the program
493
+ function executeProgram() {
494
+ // Reset variables
495
+ gameState.variables = {
496
+ x: 0,
497
+ y: 0,
498
+ z: 0,
499
+ result: 0
500
+ };
501
+
502
+ // Reset robot position
503
+ elements.robot.style.left = '1rem';
504
+ elements.robot.style.bottom = '1rem';
505
+ elements.robot.style.transform = 'rotate(0deg)';
506
+ elements.outputDisplay.textContent = '?';
507
+ elements.progressTrack.style.width = '0%';
508
+
509
+ // Clear console
510
+ elements.consoleOutput.innerHTML = '';
511
+
512
+ // Add execution started message
513
+ addConsoleMessage("Début de l'exécution du programme...", "info");
514
+
515
+ // Execute each command with a delay for visualization
516
+ let position = { x: 16, y: 0 };
517
+ let rotation = 0;
518
+ let loopStack = [];
519
+ let loopCounters = {};
520
+ let currentLoop = null;
521
+
522
+ const executeNextCommand = (index) => {
523
+ if (index >= gameState.program.length) {
524
+ // Program finished
525
+ addConsoleMessage("Programme terminé.", "success");
526
+ checkSolution();
527
+ return;
528
+ }
529
+
530
+ const command = gameState.program[index];
531
+ let delay = 500; // Default delay between commands
532
+
533
+ // Parse and execute command
534
+ if (command.startsWith("moveForward()")) {
535
+ // Calculate new position based on rotation
536
+ const moveAmount = 40;
537
+
538
+ if (rotation === 0) {
539
+ position.x += moveAmount;
540
+ } else if (rotation === 90) {
541
+ position.y -= moveAmount;
542
+ } else if (rotation === 180) {
543
+ position.x -= moveAmount;
544
+ } else if (rotation === 270) {
545
+ position.y += moveAmount;
546
+ }
547
+
548
+ // Limit movement to container
549
+ const containerWidth = elements.robotContainer.offsetWidth;
550
+ const containerHeight = elements.robotContainer.offsetHeight;
551
+ const robotWidth = 64;
552
+ const robotHeight = 96;
553
+
554
+ position.x = Math.max(16, Math.min(position.x, containerWidth - robotWidth - 16));
555
+ position.y = Math.max(-containerHeight + robotHeight + 16, Math.min(position.y, 0));
556
+
557
+ elements.robot.style.left = `${position.x}px`;
558
+ elements.robot.style.bottom = `${-position.y}px`;
559
+ addConsoleMessage(`Robot avance (direction: ${rotation}°)`, "command");
560
+ }
561
+ else if (command.startsWith("turnLeft()")) {
562
+ rotation = (rotation - 90 + 360) % 360;
563
+ elements.robot.style.transform = `rotate(${rotation}deg)`;
564
+ addConsoleMessage("Robot tourne à gauche", "command");
565
+ }
566
+ else if (command.startsWith("turnRight()")) {
567
+ rotation = (rotation + 90) % 360;
568
+ elements.robot.style.transform = `rotate(${rotation}deg)`;
569
+ addConsoleMessage("Robot tourne à droite", "command");
570
+ }
571
+ else if (command.startsWith("setVariable(")) {
572
+ const matches = command.match(/setVariable\('(\w+)', (\d+)\)/);
573
+ if (matches) {
574
+ const varName = matches[1];
575
+ const value = parseInt(matches[2]);
576
+ gameState.variables[varName] = value;
577
+ updateGameState();
578
+ addConsoleMessage(`Variable ${varName} définie à ${value}`, "command");
579
+ }
580
+ }
581
+ else if (command.startsWith("increment(")) {
582
+ const varName = command.match(/increment\('(\w+)'\)/)[1];
583
+ gameState.variables[varName]++;
584
+ updateGameState();
585
+ addConsoleMessage(`Variable ${varName} incrémentée à ${gameState.variables[varName]}`, "command");
586
+ }
587
+ else if (command.startsWith("addTo(")) {
588
+ const matches = command.match(/addTo\('(\w+)', (\d+)\)/);
589
+ if (matches) {
590
+ const varName = matches[1];
591
+ const value = parseInt(matches[2]);
592
+ gameState.variables[varName] += value;
593
+ updateGameState();
594
+ addConsoleMessage(`Ajouté ${value} à ${varName} (nouvelle valeur: ${gameState.variables[varName]})`, "command");
595
+ }
596
+ }
597
+ else if (command.startsWith("print(")) {
598
+ const varName = command.match(/print\('(\w+)'\)/)[1];
599
+ const value = gameState.variables[varName];
600
+ elements.outputDisplay.textContent = value;
601
+ addConsoleMessage(`Affichage: ${varName} = ${value}`, "output");
602
+ }
603
+ else if (command.startsWith("loop(")) {
604
+ const loopCount = parseInt(command.match(/loop\((\d+)\)/)[1]);
605
+ loopStack.push({
606
+ startIndex: index,
607
+ count: loopCount,
608
+ current: 0
609
+ });
610
+ addConsoleMessage(`Début de boucle (${loopCount} itérations)`, "command");
611
+ delay = 0; // No delay for loop start
612
+ }
613
+ else if (command === "endLoop") {
614
+ const currentLoop = loopStack[loopStack.length - 1];
615
+ currentLoop.current++;
616
+
617
+ if (currentLoop.current < currentLoop.count) {
618
+ // Next iteration
619
+ index = currentLoop.startIndex;
620
+ addConsoleMessage(`Itération ${currentLoop.current + 1} de ${currentLoop.count}`, "command");
621
+ delay = 0; // No delay for loop iteration
622
+ } else {
623
+ // Loop finished
624
+ loopStack.pop();
625
+ addConsoleMessage("Fin de boucle", "command");
626
+ }
627
+ }
628
+
629
+ // Update progress track
630
+ const progress = (index + 1) / gameState.program.length * 100;
631
+ elements.progressTrack.style.width = `${progress}%`;
632
+
633
+ // Execute next command after delay
634
+ setTimeout(() => executeNextCommand(index + 1), delay);
635
+ };
636
+
637
+ // Start execution
638
+ executeNextCommand(0);
639
+ }
640
+
641
+ // Check if the solution is correct
642
+ function checkSolution() {
643
+ const currentProblem = gameState.problems[gameState.level - 1];
644
+ if (!currentProblem) return;
645
+
646
+ const userResult = parseInt(elements.outputDisplay.textContent);
647
+ if (userResult === currentProblem.solution) {
648
+ // Correct solution
649
+ gameState.score += 100;
650
+ gameState.progress += 33;
651
+
652
+ // Show success modal
653
+ elements.successMessage.textContent = `Vous avez résolu le problème! La réponse correcte était ${currentProblem.solution}.`;
654
+ elements.successModal.classList.remove('hidden');
655
+
656
+ // Disable next level button if no more levels
657
+ if (gameState.level >= gameState.problems.length) {
658
+ elements.nextLevelBtn.disabled = true;
659
+ elements.nextLevelBtn.textContent = "Niveau Max Atteint";
660
+ elements.nextLevelBtn.classList.add('opacity-50', 'cursor-not-allowed');
661
+ }
662
+
663
+ updateGameState();
664
+ } else {
665
+ // Incorrect solution
666
+ addConsoleMessage(`Le résultat ${userResult} est incorrect. Essayez encore!`, "error");
667
+ addConsoleMessage(`Indice: ${currentProblem.hint}`, "info");
668
+ }
669
+ }
670
+
671
+ // Add a message to the console
672
+ function addConsoleMessage(message, type = "info") {
673
+ const messageElement = document.createElement('div');
674
+ 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'}`;
675
+
676
+ const timestamp = new Date().toLocaleTimeString();
677
+ messageElement.innerHTML = `<span class="text-gray-500 text-xs mr-2">[${timestamp}]</span> ${message}`;
678
+
679
+ elements.consoleOutput.appendChild(messageElement);
680
+ elements.consoleOutput.scrollTop = elements.consoleOutput.scrollHeight;
681
+ }
682
+
683
+ // Setup event listeners
684
+ function setupEventListeners() {
685
+ // Command buttons
686
+ elements.commandBtns.forEach(btn => {
687
+ btn.addEventListener('click', () => {
688
+ addCommand(btn.dataset.command);
689
+ });
690
+
691
+ // Drag and drop functionality
692
+ btn.setAttribute('draggable', 'true');
693
+ btn.addEventListener('dragstart', (e) => {
694
+ e.dataTransfer.setData('text/plain', btn.dataset.command);
695
+ });
696
+ });
697
+
698
+ // Code block drop zone
699
+ elements.codeBlock.addEventListener('dragover', (e) => {
700
+ e.preventDefault();
701
+ elements.codeBlock.classList.add('bg-gray-700');
702
+ });
703
+
704
+ elements.codeBlock.addEventListener('dragleave', () => {
705
+ elements.codeBlock.classList.remove('bg-gray-700');
706
+ });
707
+
708
+ elements.codeBlock.addEventListener('drop', (e) => {
709
+ e.preventDefault();
710
+ elements.codeBlock.classList.remove('bg-gray-700');
711
+ const command = e.dataTransfer.getData('text/plain');
712
+ if (command) {
713
+ addCommand(command);
714
+ }
715
+ });
716
+
717
+ // Action buttons
718
+ elements.runBtn.addEventListener('click', () => {
719
+ if (gameState.program.length === 0) {
720
+ addConsoleMessage("Aucune commande à exécuter. Ajoutez des commandes d'abord.", "error");
721
+ return;
722
+ }
723
+ executeProgram();
724
+ });
725
+
726
+ elements.debugBtn.addEventListener('click', () => {
727
+ addConsoleMessage("Mode débogage activé (fonctionnalité à venir)", "info");
728
+ });
729
+
730
+ elements.clearBtn.addEventListener('click', () => {
731
+ gameState.program = [];
732
+ updateCodeDisplay();
733
+ addConsoleMessage("Programme effacé", "info");
734
+ });
735
+
736
+ elements.resetBtn.addEventListener('click', () => {
737
+ gameState.score = 0;
738
+ gameState.progress = 0;
739
+ loadLevel(gameState.level);
740
+ addConsoleMessage("Jeu réinitialisé", "info");
741
+ });
742
+
743
+ // Help button
744
+ elements.helpBtn.addEventListener('click', () => {
745
+ elements.helpModal.classList.remove('hidden');
746
+ });
747
+
748
+ // Modal buttons
749
+ elements.nextLevelBtn.addEventListener('click', () => {
750
+ gameState.level++;
751
+ loadLevel(gameState.level);
752
+ elements.successModal.classList.add('hidden');
753
+ });
754
+
755
+ elements.closeModalBtn.addEventListener('click', () => {
756
+ elements.successModal.classList.add('hidden');
757
+ });
758
+
759
+ // Help modal buttons
760
+ elements.closeHelpBtn.addEventListener('click', () => {
761
+ elements.helpModal.classList.add('hidden');
762
+ });
763
+
764
+ elements.closeHelpBtn2.addEventListener('click', () => {
765
+ elements.helpModal.classList.add('hidden');
766
+ });
767
+ }
768
+
769
+ // Initialize the game when DOM is loaded
770
+ document.addEventListener('DOMContentLoaded', initGame);
771
+ </script>
772
+ <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>
773
+ </html>