import React, { useState, useEffect } from 'react'; import { Volume2 } from 'lucide-react'; const BrainLearningGame = () => { const [page, setPage] = useState('intro'); const [points, setPoints] = useState(0); const [dots, setDots] = useState([]); const [simon, setSimon] = useState({ pattern: [], userPattern: [], level: 1, playing: false, started: false }); const [memory, setMemory] = useState({ cards: [], flipped: [], matched: [], started: false, checking: false }); const [jumps, setJumps] = useState(0); const [emojis, setEmojis] = useState([]); const [certColor, setCertColor] = useState(0); const [agreedPowers, setAgreedPowers] = useState([]); useEffect(() => { if (page === 'final') { const interval = setInterval(() => { setCertColor(prev => (prev + 1) % 6); }, 1000); return () => clearInterval(interval); } }, [page]); const beep = () => { const audio = new AudioContext(); const osc = audio.createOscillator(); osc.connect(audio.destination); osc.frequency.value = 400; osc.start(); osc.stop(audio.currentTime + 0.1); }; const tadaSound = () => { const audio = new AudioContext(); const osc = audio.createOscillator(); const gainNode = audio.createGain(); osc.connect(gainNode); gainNode.connect(audio.destination); osc.frequency.setValueAtTime(523, audio.currentTime); osc.frequency.setValueAtTime(659, audio.currentTime + 0.1); osc.frequency.setValueAtTime(784, audio.currentTime + 0.2); osc.frequency.setValueAtTime(1047, audio.currentTime + 0.3); gainNode.gain.setValueAtTime(0.3, audio.currentTime); gainNode.gain.exponentialRampToValueAtTime(0.01, audio.currentTime + 0.5); osc.start(); osc.stop(audio.currentTime + 0.5); }; const buzzerSound = () => { const audio = new AudioContext(); const osc = audio.createOscillator(); const gainNode = audio.createGain(); osc.connect(gainNode); gainNode.connect(audio.destination); osc.type = 'sawtooth'; osc.frequency.setValueAtTime(200, audio.currentTime); osc.frequency.setValueAtTime(100, audio.currentTime + 0.3); gainNode.gain.setValueAtTime(0.3, audio.currentTime); gainNode.gain.exponentialRampToValueAtTime(0.01, audio.currentTime + 0.3); osc.start(); osc.stop(audio.currentTime + 0.3); }; const addDot = (e) => { if (dots.length >= 12) return; const rect = e.currentTarget.getBoundingClientRect(); const x = ((e.clientX - rect.left) / rect.width) * 100; const y = ((e.clientY - rect.top) / rect.height) * 100; const newDot = { id: Date.now(), x, y }; setDots([...dots, newDot]); setPoints(points + 5); beep(); }; const startSimon = () => { const pattern = [Math.floor(Math.random() * 9) + 1, Math.floor(Math.random() * 9) + 1]; setSimon({ pattern, userPattern: [], level: 1, playing: true, started: true }); setTimeout(() => showPattern(pattern), 500); }; const showPattern = async (pattern) => { setSimon(prev => ({ ...prev, playing: true, userPattern: [] })); for (let num of pattern) { await new Promise(r => setTimeout(r, 200)); beep(); const btn = document.getElementById(`btn-${num}`); if (btn) { btn.style.cssText = 'background-color: #FCD34D !important; transform: scale(1.2); transition: all 0.2s;'; await new Promise(r => setTimeout(r, 400)); btn.style.cssText = 'background-color: white !important; transform: scale(1); transition: all 0.2s;'; } await new Promise(r => setTimeout(r, 200)); } setSimon(prev => ({ ...prev, playing: false })); }; const clickNumber = (num) => { if (simon.playing) return; beep(); const btn = document.getElementById(`btn-${num}`); if (btn) { btn.style.cssText = 'background-color: #FCD34D !important; transform: scale(1.2); transition: all 0.2s;'; setTimeout(() => { btn.style.cssText = 'background-color: white !important; transform: scale(1); transition: all 0.2s;'; }, 300); } const newPattern = [...simon.userPattern, num]; if (newPattern[newPattern.length - 1] !== simon.pattern[newPattern.length - 1]) { buzzerSound(); setTimeout(() => { alert('Oops! Try again! ๐Ÿ”„'); showPattern(simon.pattern); }, 500); return; } if (newPattern.length === simon.pattern.length) { setTimeout(() => { tadaSound(); setPoints(points + 10); }, 400); const nextLevel = simon.level + 1; if (nextLevel <= 5) { setTimeout(() => { const newPat = Array.from({ length: nextLevel + 1 }, () => Math.floor(Math.random() * 9) + 1); setSimon({ pattern: newPat, userPattern: [], level: nextLevel, playing: true, started: true }); showPattern(newPat); }, 1500); } else { setTimeout(() => { alert('๐ŸŽ‰ You won! Amazing brain!'); setSimon({ pattern: [], userPattern: [], level: 1, playing: false, started: false }); }, 1500); } } else { setSimon(prev => ({ ...prev, userPattern: newPattern })); } }; const startMemory = () => { const icons = ['๐ŸŒŸ', '๐ŸŽจ', '๐Ÿฆ‹', '๐ŸŒˆ', '๐ŸŽต', '๐ŸŒธ']; const cards = [...icons, ...icons].sort(() => Math.random() - 0.5).map((e, i) => ({ id: i, icon: e })); setMemory({ cards, flipped: [], matched: [], started: true, checking: false }); }; const flipCard = (id) => { if (memory.checking || memory.matched.includes(id) || memory.flipped.includes(id) || memory.flipped.length >= 2) return; beep(); const newFlipped = [...memory.flipped, id]; if (newFlipped.length === 2) { setMemory(prev => ({ ...prev, flipped: newFlipped, checking: true })); const c1 = memory.cards.find(c => c.id === newFlipped[0]); const c2 = memory.cards.find(c => c.id === newFlipped[1]); if (c1.icon === c2.icon) { setTimeout(() => { setMemory(prev => ({ ...prev, matched: [...prev.matched, newFlipped[0], newFlipped[1]], flipped: [], checking: false })); setPoints(points + 10); }, 600); } else { setTimeout(() => { setMemory(prev => ({ ...prev, flipped: [], checking: false })); }, 1000); } } else { setMemory(prev => ({ ...prev, flipped: newFlipped })); } }; const doJump = () => { const newJumps = jumps + 1; setJumps(newJumps); beep(); if (newJumps === 10) { setPoints(points + 15); for (let i = 0; i < 15; i++) { setTimeout(() => { const e = { id: Date.now() + Math.random(), x: Math.random() * 90 }; setEmojis(prev => [...prev, e]); setTimeout(() => setEmojis(prev => prev.filter(em => em.id !== e.id)), 2000); }, i * 100); } setTimeout(() => alert('๐ŸŽ‰ Great job! Your brain is super charged! ๐Ÿง โšก'), 1500); } }; return (

๐Ÿง  Brain Learning Adventure! โœจ

Brain Power: {points} โญ

{page === 'intro' && (
๐Ÿง 

Your Amazing Brain!

Your brain is like a super computer! ๐Ÿ–ฅ๏ธ๐Ÿ’ซ

It helps you learn and remember AMAZING things! ๐ŸŽ‰

)} {page === 'neurons' && (

Brain Buddies! ๐Ÿง ๐Ÿ’™

Your brain has tiny helpers called NEURONS! ๐ŸŒŸ

They connect and talk to each other! ๐Ÿ’ฌโœจ

{dots.length < 12 ? 'Click anywhere to add neurons! They connect automatically! ๐ŸŽฏ' : '๐Ÿ’ช Strong Connection! ๐Ÿ’ช'}

Neurons: {dots.length}/12 | Connections: {dots.length > 1 ? (dots.length * (dots.length - 1)) / 2 : 0}

{dots.map((d, i) => dots.slice(i + 1).map((d2) => ( )) )} {dots.map(d => (
))} {dots.length >= 12 && (

๐Ÿ’ช Strong Connection! ๐Ÿ’ช

)}
)} {page === 'simon' && (

Practice Makes Perfect! ๐ŸŽฏ

When you practice AGAIN and AGAIN... ๐Ÿ”„

Your brain gets SUPER STRONG! ๐Ÿ’ช๐ŸŒŸ

{!simon.started ? (

Memory Challenge! ๐Ÿง 

Watch the numbers light up, then repeat!

) : (

{simon.playing ? '๐Ÿ‘€ Watch carefully!' : '๐ŸŽฏ Now you try!'}

Level {simon.level} | Remember {simon.level + 1} numbers!

{[1, 2, 3, 4, 5, 6, 7, 8, 9].map(n => ( ))}
)}
)} {page === 'memory' && (

Memory Match! ๐ŸŽฎ

Your brain LOVES games! ๐ŸŽ‰

Find matching pairs! ๐ŸŒŸ

{!memory.started ? (
) : (
{memory.cards.map(card => { const show = memory.flipped.includes(card.id) || memory.matched.includes(card.id); return ( ); })}
{memory.matched.length === memory.cards.length && (

๐ŸŽ‰ Amazing! ๐Ÿง โœจ

)}
)}
)} {page === 'sleep' && (

Sleep is Super Important! ๐Ÿ˜ด๐Ÿ’ค

When you sleep, your brain does MAGIC! โœจ๐ŸŒ™

It saves everything you learned today! ๐Ÿ’พ

Sleep helps your brain grow strong and healthy! ๐ŸŒฑ๐Ÿ’ช

๐Ÿ˜ด

9-11 Hours

of sleep every night!

Here are some examples:

๐Ÿ˜ด Bed at 8:00 PM โ†’ โ˜€๏ธ Wake at 7:00 AM = 11 hours! โœ…

๐Ÿ˜ด Bed at 8:30 PM โ†’ โ˜€๏ธ Wake at 6:30 AM = 10 hours! โœ…

๐Ÿ˜ด Bed at 9:00 PM โ†’ โ˜€๏ธ Wake at 6:00 AM = 9 hours! โœ…

๐Ÿ˜ด Bed at 10:00 PM โ†’ โ˜€๏ธ Wake at 6:00 AM = 8 hours โŒ Too little!

Pick a bedtime that gives you 9-11 hours! ๐Ÿง โœจ

๐Ÿ’ก Brain Tips:

๐Ÿ“š Read before bed to remember stories better!

๐Ÿ›๏ธ Go to bed at the same time every night!

๐ŸŒ™ Keep your room dark and quiet!

)} {page === 'jump' && (
{emojis.map(e => (
๐Ÿ™†โ€โ™€๏ธ
))}

Move Your Body! ๐Ÿƒโ€โ™€๏ธ

When you MOVE, your brain gets oxygen! ๐Ÿซ๐Ÿ’จ

This helps you learn faster! ๐Ÿง โšก

๐Ÿ™†โ€โ™€๏ธ

Do 10 jumping jacks for magic! ๐Ÿš€

Jumping Jacks: {jumps} ๐ŸŽฏ

{jumps >= 10 &&

โœจ Brain fully charged! Keep going! โœจ

}
)} {page === 'final' && (

๐ŸŽ‰๐Ÿง โœจ

You're a Super Learner!

๐Ÿ† SUPER LEARNER ๐Ÿ†

CERTIFICATE OF ACHIEVEMENT

This certifies that

YOU

have completed the

Amazing Brain Learning Adventure!

Brain Power: {points} โญ

Click each superpower to agree! ๐ŸŒŸ

{agreedPowers.length === 5 && (

๐ŸŽ‰ You agreed to all 5 superpowers! ๐ŸŽ‰

)}

๐ŸŽŠ You learned all the secrets to a super smart brain! ๐ŸŽŠ

Use these powers every day to keep learning and growing! ๐ŸŒฑ๐Ÿ’ช

)}
); }; export default BrainLearningGame;