Spaces:
Running

File size: 44,880 Bytes
c645da0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Python Adventure - Aprenda Python Jogando</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-editor {
            font-family: 'Courier New', monospace;
            background-color: #1e1e1e;
            color: #d4d4d4;
        }
        .typewriter {
            overflow: hidden;
            border-right: .15em solid #4ade80;
            white-space: nowrap;
            letter-spacing: .15em;
            animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
        }
        @keyframes typing {
            from { width: 0 }
            to { width: 100% }
        }
        @keyframes blink-caret {
            from, to { border-color: transparent }
            50% { border-color: #4ade80 }
        }
        .progress-bar {
            transition: width 0.5s ease-in-out;
        }
        .shake {
            animation: shake 0.5s;
        }
        @keyframes shake {
            0% { transform: translateX(0) }
            25% { transform: translateX(-5px) }
            50% { transform: translateX(5px) }
            75% { transform: translateX(-5px) }
            100% { transform: translateX(0) }
        }
    </style>
</head>
<body class="bg-gray-100 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <header class="flex justify-between items-center mb-8">
            <div class="flex items-center">
                <i class="fab fa-python text-4xl text-blue-600 mr-3"></i>
                <h1 class="text-3xl font-bold text-gray-800">Python Adventure</h1>
            </div>
            <div class="flex items-center space-x-4">
                <div class="flex items-center">
                    <span class="mr-2 text-gray-700"><i class="fas fa-coins text-yellow-500"></i> <span id="points">0</span> XP</span>
                    <div class="w-24 bg-gray-200 rounded-full h-2.5">
                        <div id="progress-bar" class="progress-bar bg-green-500 h-2.5 rounded-full" style="width: 0%"></div>
                    </div>
                </div>
                <button id="sound-btn" class="p-2 rounded-full bg-gray-200 hover:bg-gray-300">
                    <i class="fas fa-volume-up text-gray-700"></i>
                </button>
            </div>
        </header>

        <!-- Main Game Area -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Left Panel - Lessons -->
            <div class="lg:col-span-2 bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="p-6">
                    <div id="lesson-container">
                        <!-- Initial Welcome Screen -->
                        <div id="welcome-screen" class="text-center py-12">
                            <i class="fab fa-python text-8xl text-blue-600 mb-6"></i>
                            <h2 class="text-4xl font-bold text-gray-800 mb-4">Bem-vindo ao Python Adventure!</h2>
                            <p class="text-xl text-gray-600 mb-8">Aprenda Python de forma divertida e interativa. Complete lições, resolva desafios e ganhe XP!</p>
                            <button id="start-btn" class="px-8 py-3 bg-blue-600 hover:bg-blue-700 text-white font-bold rounded-lg text-lg transition duration-300 transform hover:scale-105">
                                Começar a Aventura!
                            </button>
                        </div>

                        <!-- Lesson Content (dynamically loaded) -->
                        <div id="lesson-content" class="hidden">
                            <h2 id="lesson-title" class="text-2xl font-bold text-gray-800 mb-4"></h2>
                            <div id="lesson-text" class="text-gray-700 mb-6"></div>
                            
                            <!-- Code Example -->
                            <div id="code-example" class="mb-6 hidden">
                                <div class="flex justify-between items-center bg-gray-800 text-white px-4 py-2 rounded-t-lg">
                                    <span>Exemplo de Código</span>
                                    <button id="copy-code-btn" class="text-xs bg-gray-700 hover:bg-gray-600 px-2 py-1 rounded">
                                        <i class="far fa-copy mr-1"></i> Copiar
                                    </button>
                                </div>
                                <pre id="code-block" class="code-editor p-4 rounded-b-lg overflow-x-auto"></pre>
                            </div>
                            
                            <!-- Quiz Section -->
                            <div id="quiz-section" class="hidden">
                                <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6">
                                    <h3 class="font-bold text-blue-800 mb-2">Teste seu conhecimento</h3>
                                    <p id="quiz-question" class="text-blue-700"></p>
                                </div>
                                <div id="quiz-options" class="grid grid-cols-1 md:grid-cols-2 gap-3 mb-6"></div>
                                <div id="quiz-feedback" class="hidden p-4 rounded-lg mb-6"></div>
                            </div>
                            
                            <!-- Coding Challenge -->
                            <div id="coding-challenge" class="hidden">
                                <div class="bg-purple-50 border-l-4 border-purple-500 p-4 mb-4">
                                    <h3 class="font-bold text-purple-800 mb-2">Desafio de Programação</h3>
                                    <p id="challenge-text" class="text-purple-700"></p>
                                </div>
                                <div class="flex justify-between items-center bg-gray-800 text-white px-4 py-2 rounded-t-lg">
                                    <span>Editor de Código</span>
                                    <div>
                                        <button id="run-code-btn" class="text-xs bg-green-600 hover:bg-green-700 px-2 py-1 rounded mr-2">
                                            <i class="fas fa-play mr-1"></i> Executar
                                        </button>
                                        <button id="reset-code-btn" class="text-xs bg-gray-700 hover:bg-gray-600 px-2 py-1 rounded">
                                            <i class="fas fa-redo mr-1"></i> Reiniciar
                                        </button>
                                    </div>
                                </div>
                                <textarea id="code-editor" class="code-editor w-full h-48 p-4 rounded-b-lg" spellcheck="false"></textarea>
                                <div id="output-container" class="hidden mt-4">
                                    <div class="bg-gray-800 text-white px-4 py-2 rounded-t-lg">Saída</div>
                                    <div id="code-output" class="code-editor p-4 rounded-b-lg min-h-16"></div>
                                </div>
                                <div id="challenge-feedback" class="hidden mt-4 p-4 rounded-lg"></div>
                            </div>
                            
                            <!-- Navigation Buttons -->
                            <div class="flex justify-between mt-8">
                                <button id="prev-btn" class="px-6 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 font-medium rounded-lg hidden">
                                    <i class="fas fa-arrow-left mr-2"></i> Anterior
                                </button>
                                <button id="next-btn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg ml-auto">
                                    Próximo <i class="fas fa-arrow-right ml-2"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Right Panel - Progress & Achievements -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden h-fit">
                <div class="p-6">
                    <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                        <i class="fas fa-map-marked-alt text-blue-500 mr-2"></i> Seu Progresso
                    </h2>
                    
                    <!-- Chapter Progress -->
                    <div class="mb-6">
                        <h3 class="font-semibold text-gray-700 mb-2">Capítulo 1: Fundamentos</h3>
                        <div class="space-y-3">
                            <div id="lesson-1" class="flex items-center p-2 rounded-lg hover:bg-gray-50 cursor-pointer">
                                <div class="w-6 h-6 rounded-full bg-gray-300 mr-3 flex items-center justify-center">
                                    <span class="text-xs text-gray-600">1</span>
                                </div>
                                <span class="text-gray-600">Introdução ao Python</span>
                            </div>
                            <div id="lesson-2" class="flex items-center p-2 rounded-lg hover:bg-gray-50 cursor-pointer">
                                <div class="w-6 h-6 rounded-full bg-gray-300 mr-3 flex items-center justify-center">
                                    <span class="text-xs text-gray-600">2</span>
                                </div>
                                <span class="text-gray-600">Variáveis e Tipos</span>
                            </div>
                            <div id="lesson-3" class="flex items-center p-2 rounded-lg hover:bg-gray-50 cursor-pointer">
                                <div class="w-6 h-6 rounded-full bg-gray-300 mr-3 flex items-center justify-center">
                                    <span class="text-xs text-gray-600">3</span>
                                </div>
                                <span class="text-gray-600">Operadores</span>
                            </div>
                            <div id="lesson-4" class="flex items-center p-2 rounded-lg hover:bg-gray-50 cursor-pointer">
                                <div class="w-6 h-6 rounded-full bg-gray-300 mr-3 flex items-center justify-center">
                                    <span class="text-xs text-gray-600">4</span>
                                </div>
                                <span class="text-gray-600">Estruturas Condicionais</span>
                            </div>
                            <div id="lesson-5" class="flex items-center p-2 rounded-lg hover:bg-gray-50 cursor-pointer">
                                <div class="w-6 h-6 rounded-full bg-gray-300 mr-3 flex items-center justify-center">
                                    <span class="text-xs text-gray-600">5</span>
                                </div>
                                <span class="text-gray-600">Loops</span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Achievements -->
                    <div>
                        <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-trophy text-yellow-500 mr-2"></i> Conquistas
                        </h2>
                        <div class="grid grid-cols-3 gap-3">
                            <div id="achievement-1" class="bg-gray-100 rounded-lg p-3 text-center opacity-50">
                                <i class="fas fa-star text-gray-400 text-2xl mb-1"></i>
                                <p class="text-xs text-gray-500">Primeiros Passos</p>
                            </div>
                            <div id="achievement-2" class="bg-gray-100 rounded-lg p-3 text-center opacity-50">
                                <i class="fas fa-code text-gray-400 text-2xl mb-1"></i>
                                <p class="text-xs text-gray-500">Primeiro Código</p>
                            </div>
                            <div id="achievement-3" class="bg-gray-100 rounded-lg p-3 text-center opacity-50">
                                <i class="fas fa-check-circle text-gray-400 text-2xl mb-1"></i>
                                <p class="text-xs text-gray-500">Quiz Mestre</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Game State
        const gameState = {
            currentLesson: 0,
            points: 0,
            completedLessons: [],
            soundEnabled: true,
            lessons: [
                {
                    title: "Introdução ao Python",
                    content: "Python é uma linguagem de programação poderosa e fácil de aprender. É usada para desenvolvimento web, ciência de dados, automação e muito mais!<br><br>Python é conhecido por sua sintaxe limpa e legibilidade, o que o torna uma ótima escolha para iniciantes.",
                    codeExample: `# Este é um comentário em Python
print("Olá, Mundo!")  # Esta função imprime texto na tela`,
                    quiz: {
                        question: "Qual é a função usada para imprimir texto em Python?",
                        options: [
                            { text: "echo()", correct: false },
                            { text: "print()", correct: true },
                            { text: "console.log()", correct: false },
                            { text: "output()", correct: false }
                        ],
                        feedback: "Correto! A função print() é usada para exibir texto no console em Python."
                    },
                    challenge: {
                        instruction: "Escreva um programa que imprima 'Python é divertido!' na tela.",
                        solution: `print("Python é divertido!")`,
                        test: (code) => {
                            try {
                                const output = [];
                                const originalConsole = console.log;
                                console.log = (...args) => output.push(args.join(' '));
                                eval(code);
                                console.log = originalConsole;
                                return output.includes("Python é divertido!");
                            } catch (e) {
                                return false;
                            }
                        }
                    }
                },
                {
                    title: "Variáveis e Tipos",
                    content: "Variáveis são como caixas que armazenam dados. Em Python, você pode criar uma variável simplesmente atribuindo um valor a um nome.<br><br>Python tem vários tipos de dados básicos: inteiros (números inteiros), floats (números decimais), strings (texto) e booleanos (True/False).",
                    codeExample: `# Criando variáveis
nome = "Ana"          # String
idade = 25            # Inteiro
altura = 1.75         # Float
programadora = True   # Booleano

print(nome, idade, altura, programadora)`,
                    quiz: {
                        question: "Qual destes é um tipo de dado válido em Python?",
                        options: [
                            { text: "integer", correct: false },
                            { text: "number", correct: false },
                            { text: "string", correct: true },
                            { text: "character", correct: false }
                        ],
                        feedback: "Correto! 'string' é um tipo de dado em Python para representar texto."
                    },
                    challenge: {
                        instruction: "Crie variáveis para armazenar seu nome, idade e se você gosta de Python (True/False). Depois imprima essas variáveis.",
                        solution: `nome = "SeuNome"
idade = 20
gosta_de_python = True

print(nome, idade, gosta_de_python)`,
                        test: (code) => {
                            try {
                                const output = [];
                                const originalConsole = console.log;
                                console.log = (...args) => output.push(args.join(' '));
                                eval(code);
                                console.log = originalConsole;
                                return output.length > 0 && 
                                       code.includes("=") && 
                                       code.includes("print(");
                            } catch (e) {
                                return false;
                            }
                        }
                    }
                },
                {
                    title: "Operadores",
                    content: "Operadores são símbolos especiais que realizam operações em variáveis e valores.<br><br>Python tem operadores aritméticos (+, -, *, /), operadores de comparação (==, !=, >, <) e operadores lógicos (and, or, not).",
                    codeExample: `# Operadores aritméticos
soma = 5 + 3       # 8
subtracao = 10 - 2 # 8
multiplicacao = 4 * 2 # 8
divisao = 16 / 2   # 8.0

# Operadores de comparação
igual = (5 == 5)   # True
diferente = (5 != 3) # True

# Operadores lógicos
e_logico = (5 > 3) and (10 < 20) # True
ou_logico = (5 < 3) or (10 > 5)  # True
negacao = not (5 == 3)            # True`,
                    quiz: {
                        question: "Qual operador é usado para verificar se dois valores são iguais?",
                        options: [
                            { text: "=", correct: false },
                            { text: "==", correct: true },
                            { text: "===", correct: false },
                            { text: "equals", correct: false }
                        ],
                        feedback: "Correto! O operador == verifica igualdade entre dois valores."
                    },
                    challenge: {
                        instruction: "Calcule a área de um retângulo com largura 5 e altura 10. Armazene o resultado em uma variável e imprima.",
                        solution: `largura = 5
altura = 10
area = largura * altura

print(area)`,
                        test: (code) => {
                            try {
                                const output = [];
                                const originalConsole = console.log;
                                console.log = (...args) => output.push(args.join(' '));
                                eval(code);
                                console.log = originalConsole;
                                return output.includes("50");
                            } catch (e) {
                                return false;
                            }
                        }
                    }
                },
                {
                    title: "Estruturas Condicionais",
                    content: "Estruturas condicionais permitem que seu programa tome decisões com base em condições.<br><br>Em Python, usamos if, elif e else para criar lógica condicional. A indentação (espaçamento no início da linha) é crucial em Python para definir blocos de código.",
                    codeExample: `idade = 18

if idade < 12:
    print("Criança")
elif idade < 18:
    print("Adolescente")
else:
    print("Adulto")`,
                    quiz: {
                        question: "Qual palavra-chave é usada para adicionar uma condição alternativa em Python?",
                        options: [
                            { text: "elseif", correct: false },
                            { text: "elif", correct: true },
                            { text: "otherwise", correct: false },
                            { text: "case", correct: false }
                        ],
                        feedback: "Correto! 'elif' é a abreviação de 'else if' em Python."
                    },
                    challenge: {
                        instruction: "Escreva um programa que verifica se um número (armazenado em uma variável) é positivo, negativo ou zero.",
                        solution: `numero = 10

if numero > 0:
    print("Positivo")
elif numero < 0:
    print("Negativo")
else:
    print("Zero")`,
                        test: (code) => {
                            try {
                                // Test with positive number
                                let output = [];
                                let modifiedCode = code.replace(/numero\s*=\s*\d+/g, 'numero = 5');
                                const originalConsole = console.log;
                                console.log = (...args) => output.push(args.join(' '));
                                eval(modifiedCode);
                                
                                // Test with negative number
                                modifiedCode = code.replace(/numero\s*=\s*\d+/g, 'numero = -3');
                                eval(modifiedCode);
                                
                                // Test with zero
                                modifiedCode = code.replace(/numero\s*=\s*\d+/g, 'numero = 0');
                                eval(modifiedCode);
                                
                                console.log = originalConsole;
                                
                                return output.includes("Positivo") && 
                                       output.includes("Negativo") && 
                                       output.includes("Zero");
                            } catch (e) {
                                return false;
                            }
                        }
                    }
                },
                {
                    title: "Loops",
                    content: "Loops permitem executar um bloco de código repetidamente. Python tem dois tipos principais de loops: for e while.<br><br>O loop for é usado para iterar sobre uma sequência (como uma lista ou string). O loop while repete enquanto uma condição for verdadeira.",
                    codeExample: `# Loop for
for i in range(5):  # Repete 5 vezes (0 a 4)
    print(i)

# Loop while
contador = 0
while contador < 5:
    print(contador)
    contador += 1  # Incrementa o contador`,
                    quiz: {
                        question: "Qual comando é usado para sair de um loop antes que ele termine?",
                        options: [
                            { text: "stop", correct: false },
                            { text: "exit", correct: false },
                            { text: "break", correct: true },
                            { text: "return", correct: false }
                        ],
                        feedback: "Correto! O comando 'break' interrompe imediatamente a execução do loop."
                    },
                    challenge: {
                        instruction: "Use um loop for para imprimir os números de 1 a 10, mas pule o número 5 usando 'continue'.",
                        solution: `for numero in range(1, 11):
    if numero == 5:
        continue
    print(numero)`,
                        test: (code) => {
                            try {
                                const output = [];
                                const originalConsole = console.log;
                                console.log = (...args) => output.push(args.join(' '));
                                eval(code);
                                console.log = originalConsole;
                                
                                const numbers = output.map(Number).filter(n => !isNaN(n));
                                return numbers.length === 9 && 
                                       !numbers.includes(5) && 
                                       numbers.includes(1) && 
                                       numbers.includes(10);
                            } catch (e) {
                                return false;
                            }
                        }
                    }
                }
            ]
        };

        // DOM Elements
        const welcomeScreen = document.getElementById('welcome-screen');
        const lessonContent = document.getElementById('lesson-content');
        const lessonTitle = document.getElementById('lesson-title');
        const lessonText = document.getElementById('lesson-text');
        const codeExample = document.getElementById('code-example');
        const codeBlock = document.getElementById('code-block');
        const quizSection = document.getElementById('quiz-section');
        const quizQuestion = document.getElementById('quiz-question');
        const quizOptions = document.getElementById('quiz-options');
        const quizFeedback = document.getElementById('quiz-feedback');
        const codingChallenge = document.getElementById('coding-challenge');
        const challengeText = document.getElementById('challenge-text');
        const codeEditor = document.getElementById('code-editor');
        const outputContainer = document.getElementById('output-container');
        const codeOutput = document.getElementById('code-output');
        const challengeFeedback = document.getElementById('challenge-feedback');
        const nextBtn = document.getElementById('next-btn');
        const prevBtn = document.getElementById('prev-btn');
        const startBtn = document.getElementById('start-btn');
        const pointsDisplay = document.getElementById('points');
        const progressBar = document.getElementById('progress-bar');
        const soundBtn = document.getElementById('sound-btn');
        const copyCodeBtn = document.getElementById('copy-code-btn');
        const runCodeBtn = document.getElementById('run-code-btn');
        const resetCodeBtn = document.getElementById('reset-code-btn');

        // Lesson navigation
        let currentStep = 0; // 0 = lesson, 1 = quiz, 2 = challenge

        // Initialize the game
        function initGame() {
            startBtn.addEventListener('click', startGame);
            nextBtn.addEventListener('click', nextStep);
            prevBtn.addEventListener('click', prevStep);
            soundBtn.addEventListener('click', toggleSound);
            copyCodeBtn.addEventListener('click', copyCode);
            runCodeBtn.addEventListener('click', runCode);
            resetCodeBtn.addEventListener('click', resetCode);
            
            // Set up lesson navigation
            for (let i = 1; i <= 5; i++) {
                document.getElementById(`lesson-${i}`).addEventListener('click', () => {
                    if (gameState.completedLessons.includes(i-1) || i === 1) {
                        loadLesson(i-1);
                    }
                });
            }
        }

        // Start the game
        function startGame() {
            welcomeScreen.classList.add('hidden');
            lessonContent.classList.remove('hidden');
            loadLesson(0);
            playSound('start');
        }

        // Load a lesson
        function loadLesson(lessonIndex) {
            gameState.currentLesson = lessonIndex;
            currentStep = 0;
            
            const lesson = gameState.lessons[lessonIndex];
            
            // Update UI
            lessonTitle.textContent = lesson.title;
            lessonText.innerHTML = lesson.content;
            
            // Show code example if available
            if (lesson.codeExample) {
                codeBlock.textContent = lesson.codeExample;
                codeExample.classList.remove('hidden');
            } else {
                codeExample.classList.add('hidden');
            }
            
            // Hide quiz and challenge sections initially
            quizSection.classList.add('hidden');
            codingChallenge.classList.add('hidden');
            
            // Update navigation buttons
            prevBtn.classList.add('hidden');
            nextBtn.textContent = 'Próximo';
            
            // Update progress
            updateProgress();
            
            // Highlight current lesson in sidebar
            document.querySelectorAll('[id^="lesson-"]').forEach(el => {
                el.classList.remove('bg-blue-50', 'border-l-4', 'border-blue-500');
            });
            document.getElementById(`lesson-${lessonIndex+1}`).classList.add('bg-blue-50', 'border-l-4', 'border-blue-500');
            
            playSound('page');
        }

        // Next step in lesson
        function nextStep() {
            const lesson = gameState.lessons[gameState.currentLesson];
            
            if (currentStep === 0) {
                // Show quiz
                currentStep = 1;
                quizSection.classList.remove('hidden');
                quizQuestion.textContent = lesson.quiz.question;
                
                // Clear previous options
                quizOptions.innerHTML = '';
                
                // Add new options
                lesson.quiz.options.forEach((option, index) => {
                    const optionBtn = document.createElement('button');
                    optionBtn.className = 'p-3 bg-gray-100 hover:bg-gray-200 rounded-lg text-left';
                    optionBtn.textContent = option.text;
                    optionBtn.addEventListener('click', () => checkAnswer(index));
                    quizOptions.appendChild(optionBtn);
                });
                
                quizFeedback.classList.add('hidden');
                prevBtn.classList.remove('hidden');
                nextBtn.textContent = 'Próximo';
                
                if (!gameState.completedLessons.includes(gameState.currentLesson)) {
                    nextBtn.disabled = true;
                }
                
            } else if (currentStep === 1) {
                // Show coding challenge
                currentStep = 2;
                quizSection.classList.add('hidden');
                codingChallenge.classList.remove('hidden');
                challengeText.textContent = lesson.challenge.instruction;
                codeEditor.value = '';
                outputContainer.classList.add('hidden');
                challengeFeedback.classList.add('hidden');
                
                prevBtn.classList.remove('hidden');
                nextBtn.textContent = 'Concluir';
                nextBtn.disabled = true;
                
            } else if (currentStep === 2) {
                // Complete lesson
                if (!gameState.completedLessons.includes(gameState.currentLesson)) {
                    gameState.completedLessons.push(gameState.currentLesson);
                    gameState.points += 50;
                    updateProgress();
                    
                    // Unlock next lesson if available
                    if (gameState.currentLesson < gameState.lessons.length - 1) {
                        document.getElementById(`lesson-${gameState.currentLesson + 2}`).classList.remove('cursor-not-allowed');
                    }
                    
                    // Check achievements
                    checkAchievements();
                }
                
                // Load next lesson or go back to menu
                if (gameState.currentLesson < gameState.lessons.length - 1) {
                    loadLesson(gameState.currentLesson + 1);
                } else {
                    // All lessons completed
                    lessonContent.classList.add('hidden');
                    welcomeScreen.classList.remove('hidden');
                    welcomeScreen.innerHTML = `
                        <div class="text-center py-12">
                            <i class="fas fa-trophy text-8xl text-yellow-500 mb-6"></i>
                            <h2 class="text-4xl font-bold text-gray-800 mb-4">Parabéns!</h2>
                            <p class="text-xl text-gray-600 mb-8">Você completou todos os módulos básicos de Python!</p>
                            <p class="text-lg text-gray-700 mb-8">Você ganhou ${gameState.points} XP!</p>
                            <button id="restart-btn" class="px-8 py-3 bg-blue-600 hover:bg-blue-700 text-white font-bold rounded-lg text-lg transition duration-300 transform hover:scale-105">
                                Jogar Novamente
                            </button>
                        </div>
                    `;
                    document.getElementById('restart-btn').addEventListener('click', () => {
                        location.reload();
                    });
                    playSound('complete');
                }
            }
        }

        // Previous step in lesson
        function prevStep() {
            if (currentStep === 1) {
                // Back to lesson
                currentStep = 0;
                quizSection.classList.add('hidden');
                prevBtn.classList.add('hidden');
                nextBtn.textContent = 'Próximo';
                nextBtn.disabled = false;
                
            } else if (currentStep === 2) {
                // Back to quiz
                currentStep = 1;
                codingChallenge.classList.add('hidden');
                quizSection.classList.remove('hidden');
                nextBtn.textContent = 'Próximo';
                nextBtn.disabled = !gameState.completedLessons.includes(gameState.currentLesson);
            }
        }

        // Check quiz answer
        function checkAnswer(optionIndex) {
            const lesson = gameState.lessons[gameState.currentLesson];
            const isCorrect = lesson.quiz.options[optionIndex].correct;
            
            // Disable all options
            const options = quizOptions.querySelectorAll('button');
            options.forEach(btn => {
                btn.disabled = true;
                if (lesson.quiz.options[btn._index].correct) {
                    btn.classList.add('bg-green-100', 'border', 'border-green-500');
                } else if (btn._index === optionIndex && !isCorrect) {
                    btn.classList.add('bg-red-100', 'border', 'border-red-500', 'shake');
                }
            });
            
            // Show feedback
            quizFeedback.classList.remove('hidden');
            quizFeedback.textContent = isCorrect ? '✅ ' + lesson.quiz.feedback : '❌ Resposta incorreta. Tente novamente!';
            quizFeedback.className = `p-4 rounded-lg mb-6 ${isCorrect ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`;
            
            // Enable next button if correct
            if (isCorrect) {
                nextBtn.disabled = false;
                playSound('correct');
            } else {
                playSound('wrong');
            }
        }

        // Run code in challenge
        function runCode() {
            const lesson = gameState.lessons[gameState.currentLesson];
            const code = codeEditor.value;
            
            try {
                // Capture output
                const output = [];
                const originalConsole = console.log;
                console.log = (...args) => output.push(args.join(' '));
                
                // Execute code
                eval(code);
                
                // Restore console
                console.log = originalConsole;
                
                // Display output
                codeOutput.textContent = output.join('\n');
                outputContainer.classList.remove('hidden');
                
                // Check if challenge is solved
                const isCorrect = lesson.challenge.test(code);
                
                if (isCorrect) {
                    challengeFeedback.classList.remove('hidden');
                    challengeFeedback.textContent = '✅ Desafio concluído com sucesso!';
                    challengeFeedback.className = 'p-4 rounded-lg bg-green-100 text-green-800';
                    nextBtn.disabled = false;
                    playSound('correct');
                } else {
                    challengeFeedback.classList.remove('hidden');
                    challengeFeedback.textContent = '❌ Ainda não está correto. Continue tentando!';
                    challengeFeedback.className = 'p-4 rounded-lg bg-red-100 text-red-800';
                    playSound('wrong');
                }
                
            } catch (error) {
                codeOutput.textContent = `Erro: ${error.message}`;
                outputContainer.classList.remove('hidden');
                challengeFeedback.classList.remove('hidden');
                challengeFeedback.textContent = '❌ Seu código contém erros. Corrija e tente novamente.';
                challengeFeedback.className = 'p-4 rounded-lg bg-red-100 text-red-800';
                playSound('wrong');
            }
        }

        // Reset code editor
        function resetCode() {
            codeEditor.value = '';
            outputContainer.classList.add('hidden');
            challengeFeedback.classList.add('hidden');
            playSound('page');
        }

        // Copy code example
        function copyCode() {
            const lesson = gameState.lessons[gameState.currentLesson];
            navigator.clipboard.writeText(lesson.codeExample);
            
            // Show feedback
            const originalText = copyCodeBtn.innerHTML;
            copyCodeBtn.innerHTML = '<i class="fas fa-check mr-1"></i> Copiado!';
            setTimeout(() => {
                copyCodeBtn.innerHTML = originalText;
            }, 2000);
            
            playSound('click');
        }

        // Toggle sound
        function toggleSound() {
            gameState.soundEnabled = !gameState.soundEnabled;
            soundBtn.innerHTML = gameState.soundEnabled ? 
                '<i class="fas fa-volume-up text-gray-700"></i>' : 
                '<i class="fas fa-volume-mute text-gray-700"></i>';
            playSound('click');
        }

        // Play sound
        function playSound(type) {
            if (!gameState.soundEnabled) return;
            
            const sounds = {
                click: { freq: 800, duration: 0.1, type: 'sine' },
                page: { freq: 500, duration: 0.2, type: 'sine' },
                correct: { freq: 1046.5, duration: 0.3, type: 'square' },
                wrong: { freq: 220, duration: 0.5, type: 'sawtooth' },
                start: { 
                    freq: [523.25, 659.25, 783.99], 
                    duration: [0.2, 0.2, 0.3], 
                    type: 'sine' 
                },
                complete: { 
                    freq: [783.99, 659.25, 523.25], 
                    duration: [0.3, 0.3, 0.5], 
                    type: 'sine' 
                }
            };
            
            const sound = sounds[type];
            const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
            
            if (Array.isArray(sound.freq)) {
                // Play sequence of tones
                sound.freq.forEach((freq, i) => {
                    const oscillator = audioCtx.createOscillator();
                    const gainNode = audioCtx.createGain();
                    
                    oscillator.type = sound.type;
                    oscillator.frequency.value = freq;
                    oscillator.connect(gainNode);
                    gainNode.connect(audioCtx.destination);
                    
                    gainNode.gain.setValueAtTime(1, audioCtx.currentTime);
                    gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + sound.duration[i]);
                    
                    oscillator.start();
                    oscillator.stop(audioCtx.currentTime + sound.duration[i]);
                });
            } else {
                // Play single tone
                const oscillator = audioCtx.createOscillator();
                const gainNode = audioCtx.createGain();
                
                oscillator.type = sound.type;
                oscillator.frequency.value = sound.freq;
                oscillator.connect(gainNode);
                gainNode.connect(audioCtx.destination);
                
                gainNode.gain.setValueAtTime(1, audioCtx.currentTime);
                gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + sound.duration);
                
                oscillator.start();
                oscillator.stop(audioCtx.currentTime + sound.duration);
            }
        }

        // Update progress display
        function updateProgress() {
            pointsDisplay.textContent = gameState.points;
            const progress = (gameState.completedLessons.length / gameState.lessons.length) * 100;
            progressBar.style.width = `${progress}%`;
        }

        // Check and unlock achievements
        function checkAchievements() {
            // First steps
            if (gameState.completedLessons.length === 1) {
                document.getElementById('achievement-1').classList.remove('opacity-50');
                document.getElementById('achievement-1').classList.add('bg-yellow-100');
                document.getElementById('achievement-1').querySelector('i').classList.remove('text-gray-400');
                document.getElementById('achievement-1').querySelector('i').classList.add('text-yellow-500');
                document.getElementById('achievement-1').querySelector('p').classList.remove('text-gray-500');
                document.getElementById('achievement-1').querySelector('p').classList.add('text-yellow-700');
                playSound('correct');
            }
            
            // First code
            if (gameState.completedLessons.length >= 2) {
                document.getElementById('achievement-2').classList.remove('opacity-50');
                document.getElementById('achievement-2').classList.add('bg-yellow-100');
                document.getElementById('achievement-2').querySelector('i').classList.remove('text-gray-400');
                document.getElementById('achievement-2').querySelector('i').classList.add('text-yellow-500');
                document.getElementById('achievement-2').querySelector('p').classList.remove('text-gray-500');
                document.getElementById('achievement-2').querySelector('p').classList.add('text-yellow-700');
            }
            
            // Quiz master
            if (gameState.completedLessons.length === gameState.lessons.length) {
                document.getElementById('achievement-3').classList.remove('opacity-50');
                document.getElementById('achievement-3').classList.add('bg-yellow-100');
                document.getElementById('achievement-3').querySelector('i').classList.remove('text-gray-400');
                document.getElementById('achievement-3').querySelector('i').classList.add('text-yellow-500');
                document.getElementById('achievement-3').querySelector('p').classList.remove('text-gray-500');
                document.getElementById('achievement-3').querySelector('p').classList.add('text-yellow-700');
            }
        }

        // Initialize quiz option indexes
        document.querySelectorAll('#quiz-options button').forEach((btn, index) => {
            btn._index = index;
        });

        // Start the game
        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=Evandrocostasoares/python" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>