import React, { useState, useEffect } from 'react'; import { Button } from '../components/ui/Button'; import { ArrowLeft, Play, RefreshCw, Trophy, Sparkles, Hexagon, Volume2, VolumeX } from 'lucide-react'; import { StorageService } from '../services/storageService'; interface GameProps { onExit: () => void; } export const MandalaMind: React.FC = ({ onExit }) => { const [isPlaying, setIsPlaying] = useState(false); const [gameOver, setGameOver] = useState(false); const [score, setScore] = useState(0); const [highScore, setHighScore] = useState(0); const [sequence, setSequence] = useState([]); const [userSequence, setUserSequence] = useState([]); const [isShowingSequence, setIsShowingSequence] = useState(false); const [activeSegment, setActiveSegment] = useState(null); const [message, setMessage] = useState("Watch & Remember"); const [audioEnabled, setAudioEnabled] = useState(true); const colors = [ { id: 0, baseColor: 'bg-red-600', glowColor: 'shadow-[0_0_60px_rgba(239,68,68,0.9)] ring-4 ring-red-400/50', activeColor: 'bg-red-400', shape: 'rounded-tl-[100px] rounded-br-[20px] rounded-tr-[20px] rounded-bl-[20px]', note: 261.63 }, { id: 1, baseColor: 'bg-blue-600', glowColor: 'shadow-[0_0_60px_rgba(59,130,246,0.9)] ring-4 ring-blue-400/50', activeColor: 'bg-blue-400', shape: 'rounded-tr-[100px] rounded-bl-[20px] rounded-tl-[20px] rounded-br-[20px]', note: 329.63 }, { id: 2, baseColor: 'bg-green-600', glowColor: 'shadow-[0_0_60px_rgba(34,197,94,0.9)] ring-4 ring-green-400/50', activeColor: 'bg-green-400', shape: 'rounded-bl-[100px] rounded-tr-[20px] rounded-tl-[20px] rounded-br-[20px]', note: 392.00 }, { id: 3, baseColor: 'bg-yellow-500', glowColor: 'shadow-[0_0_60px_rgba(234,179,8,0.9)] ring-4 ring-yellow-400/50', activeColor: 'bg-yellow-300', shape: 'rounded-br-[100px] rounded-tl-[20px] rounded-tr-[20px] rounded-bl-[20px]', note: 523.25 }, ]; useEffect(() => { const loadHighScore = async () => { const profile = await StorageService.getProfile(); if (profile?.highScores?.mandala) { setHighScore(profile.highScores.mandala); } }; loadHighScore(); }, []); const playTone = (freq: number) => { if (!audioEnabled) return; try { const AudioContext = window.AudioContext || (window as any).webkitAudioContext; if (!AudioContext) return; const ctx = new AudioContext(); const osc = ctx.createOscillator(); const gain = ctx.createGain(); osc.type = 'sine'; osc.frequency.setValueAtTime(freq, ctx.currentTime); gain.gain.setValueAtTime(0.1, ctx.currentTime); gain.gain.exponentialRampToValueAtTime(0.00001, ctx.currentTime + 0.5); osc.connect(gain); gain.connect(ctx.destination); osc.start(); osc.stop(ctx.currentTime + 0.5); } catch (e) { console.error("Audio error", e); } }; const startGame = () => { setIsPlaying(true); setGameOver(false); setScore(0); setSequence([]); setUserSequence([]); setMessage("Watch closely..."); addToSequence([]); }; const addToSequence = (currentSeq: number[]) => { const nextColor = Math.floor(Math.random() * 4); const newSeq = [...currentSeq, nextColor]; setSequence(newSeq); setUserSequence([]); setIsShowingSequence(true); const baseSpeed = 800; const speed = Math.max(300, baseSpeed - (newSeq.length * 40)); setTimeout(() => playSequence(newSeq, speed), 1000); }; const playSequence = async (seq: number[], speed: number) => { for (let i = 0; i < seq.length; i++) { setActiveSegment(seq[i]); playTone(colors[seq[i]].note); await new Promise(r => setTimeout(r, speed * 0.6)); setActiveSegment(null); await new Promise(r => setTimeout(r, speed * 0.4)); } setIsShowingSequence(false); setMessage("Repeat the pattern!"); }; const handleSegmentClick = (id: number) => { if (!isPlaying || isShowingSequence || gameOver) return; setActiveSegment(id); playTone(colors[id].note); setTimeout(() => setActiveSegment(null), 200); const newUserSeq = [...userSequence, id]; setUserSequence(newUserSeq); if (newUserSeq[newUserSeq.length - 1] !== sequence[newUserSeq.length - 1]) { playTone(150); setGameOver(true); setIsPlaying(false); if (score > highScore) { setHighScore(score); } StorageService.saveHighScore('mandala', score); StorageService.addPoints(Math.floor(score / 2), score * 2, 'game_reward', 'Mandala Mind Synchronization'); return; } if (newUserSeq.length === sequence.length) { const newScore = score + 1; setScore(newScore); setMessage("Correct!"); setIsShowingSequence(true); setTimeout(() => { addToSequence(sequence); }, 1000); } }; return (
{/* Dynamic Background */}
{/* Top Controls */}

MANDALA

Memory Synchronization

{/* Rotating Rings */}
{/* The Flower Grid */}
{colors.map((c) => ( ))}
{/* Center Hub */}
{isPlaying &&
} {isPlaying ? (

Score

{score}

) : (
)}
{!isPlaying && !gameOver && ( )} {isPlaying && (

{message}

{[0,1,2].map(i => ( ))}
)} {gameOver && (

GAME OVER

Final Score {score}
)}
{!isPlaying && !gameOver && (
Personal Best {highScore}
)}
); };