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 => (
))}
{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;