import React, { useState, useEffect, useCallback } from 'react'; // Mock movie soundtrack data const MOVIE_SONGS = [ { id: 1, correctAnswer: "Titanic", options: ["Titanic", "The Notebook", "Ghost", "Dirty Dancing"], trivia: "Celine Dion's 'My Heart Will Go On' became one of the best-selling singles of all time." }, { id: 2, correctAnswer: "Star Wars", options: ["Star Trek", "Star Wars", "Battlestar Galactica", "Guardians of the Galaxy"], trivia: "John Williams' iconic score is considered one of the greatest film soundtracks ever composed." }, { id: 3, correctAnswer: "The Lion King", options: ["The Jungle Book", "The Lion King", "Moana", "Frozen"], trivia: "Elton John co-wrote several songs for the film, including 'Can You Feel the Love Tonight'." }, { id: 4, correctAnswer: "Pulp Fiction", options: ["Reservoir Dogs", "Kill Bill", "Pulp Fiction", "Django Unchained"], trivia: "Quentin Tarantino's eclectic soundtrack helped revive several classic songs from the 1960s and 70s." }, { id: 5, correctAnswer: "Top Gun", options: ["Top Gun", "Days of Thunder", "Mission Impossible", "Jerry Maguire"], trivia: "Berlin's 'Take My Breath Away' won the Academy Award for Best Original Song." }, { id: 6, correctAnswer: "Rocky", options: ["Rocky", "The Karate Kid", "Rudy", "Remember the Titans"], trivia: "The theme song 'Gonna Fly Now' became synonymous with training montages and perseverance." }, { id: 7, correctAnswer: "The Bodyguard", options: ["Pretty Woman", "The Bodyguard", "Ghost", "Dirty Dancing"], trivia: "Whitney Houston's 'I Will Always Love You' spent 14 weeks at #1 on the Billboard Hot 100." }, { id: 8, correctAnswer: "Grease", options: ["Mamma Mia!", "Grease", "High School Musical", "La La Land"], trivia: "The soundtrack was the second-best-selling album of 1978 in the United States." } ]; const MovieMusicQuiz = () => { const [gameState, setGameState] = useState('intro'); const [currentQuestion, setCurrentQuestion] = useState(0); const [score, setScore] = useState(0); const [streak, setStreak] = useState(0); const [timeLeft, setTimeLeft] = useState(15); const [selectedAnswer, setSelectedAnswer] = useState(null); const [isCorrect, setIsCorrect] = useState(null); const [questions, setQuestions] = useState([]); const [isPlaying, setIsPlaying] = useState(false); const [waveformBars, setWaveformBars] = useState([]); // Initialize game const initializeGame = useCallback(() => { const shuffled = [...MOVIE_SONGS].sort(() => Math.random() - 0.5).slice(0, 5); setQuestions(shuffled); setCurrentQuestion(0); setScore(0); setStreak(0); setGameState('playing'); setTimeLeft(15); setSelectedAnswer(null); setIsCorrect(null); setIsPlaying(true); // Initialize waveform animation const bars = Array.from({ length: 30 }, () => Math.random() * 100); setWaveformBars(bars); }, []); // Animate waveform bars useEffect(() => { if (isPlaying && gameState === 'playing') { const interval = setInterval(() => { setWaveformBars(prev => prev.map(() => Math.random() * 100)); }, 200); return () => clearInterval(interval); } }, [isPlaying, gameState]); // Timer countdown useEffect(() => { if (gameState === 'playing' && timeLeft > 0 && selectedAnswer === null) { const timer = setTimeout(() => { setTimeLeft(prev => prev - 1); }, 1000); return () => clearTimeout(timer); } else if (timeLeft === 0 && gameState === 'playing' && selectedAnswer === null) { handleTimeout(); } }, [timeLeft, gameState, selectedAnswer]); const handleTimeout = () => { setIsPlaying(false); setGameState('feedback'); setIsCorrect(false); setStreak(0); setTimeout(() => { nextQuestion(); }, 3000); }; const handleAnswerSelect = (answer) => { if (selectedAnswer !== null) return; setSelectedAnswer(answer); setIsPlaying(false); const correct = answer === questions[currentQuestion].correctAnswer; setIsCorrect(correct); if (correct) { const timeBonus = timeLeft * 10; const streakMultiplier = Math.min(streak + 1, 3); const points = (100 + timeBonus) * streakMultiplier; setScore(prev => prev + points); setStreak(prev => prev + 1); } else { setStreak(0); } setGameState('feedback'); setTimeout(() => { nextQuestion(); }, 3000); }; const nextQuestion = () => { if (currentQuestion < questions.length - 1) { setCurrentQuestion(prev => prev + 1); setSelectedAnswer(null); setIsCorrect(null); setTimeLeft(15); setGameState('playing'); setIsPlaying(true); } else { setGameState('gameOver'); setIsPlaying(false); } }; const getButtonStyle = (option) => { if (gameState !== 'feedback') { return selectedAnswer === option ? 'bg-yellow-600 border-yellow-400 transform scale-95' : 'bg-red-900 border-yellow-500 hover:bg-red-800 hover:border-yellow-400 hover:transform hover:scale-105'; } if (option === questions[currentQuestion]?.correctAnswer) { return 'bg-green-600 border-green-400 animate-pulse'; } if (selectedAnswer === option && !isCorrect) { return 'bg-red-600 border-red-400 animate-pulse'; } return 'bg-red-900 border-yellow-500 opacity-50'; }; const getTimerColor = () => { if (timeLeft > 10) return 'text-yellow-400'; if (timeLeft > 5) return 'text-orange-400 animate-pulse'; return 'text-red-400 animate-bounce'; }; const getScoreDisplay = () => { return score.toLocaleString(); }; if (gameState === 'intro') { return (
Test your knowledge of iconic movie soundtracks! Listen to clips and guess which film they're from.