import { useState, useEffect } from 'react'; import { ArrowRight, Award, RefreshCw } from 'lucide-react'; // Database of quotes with their authors const quoteDatabase = [ { quote: "Be yourself; everyone else is already taken.", author: "Oscar Wilde", options: ["Oscar Wilde", "Mark Twain", "Maya Angelou", "Albert Einstein"] }, { quote: "The greatest glory in living lies not in never falling, but in rising every time we fall.", author: "Nelson Mandela", options: ["Nelson Mandela", "Winston Churchill", "Oprah Winfrey", "Mahatma Gandhi"] }, { quote: "In three words I can sum up everything I've learned about life: it goes on.", author: "Robert Frost", options: ["Robert Frost", "Ernest Hemingway", "Virginia Woolf", "F. Scott Fitzgerald"] }, { quote: "If you want to know what a man's like, take a good look at how he treats his inferiors, not his equals.", author: "J.K. Rowling", options: ["J.K. Rowling", "Stephen King", "George R.R. Martin", "Jane Austen"] }, { quote: "I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.", author: "Martin Luther King Jr.", options: ["Martin Luther King Jr.", "Malcolm X", "Barack Obama", "Rosa Parks"] }, { quote: "The only thing we have to fear is fear itself.", author: "Franklin D. Roosevelt", options: ["Franklin D. Roosevelt", "John F. Kennedy", "Abraham Lincoln", "Theodore Roosevelt"] }, { quote: "Be the change that you wish to see in the world.", author: "Mahatma Gandhi", options: ["Mahatma Gandhi", "Dalai Lama", "Mother Teresa", "Nelson Mandela"] }, { quote: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel.", author: "Maya Angelou", options: ["Maya Angelou", "Oprah Winfrey", "Michelle Obama", "Toni Morrison"] }, { quote: "If you tell the truth, you don't have to remember anything.", author: "Mark Twain", options: ["Mark Twain", "Oscar Wilde", "Ernest Hemingway", "Charles Dickens"] }, { quote: "I have not failed. I've just found 10,000 ways that won't work.", author: "Thomas Edison", options: ["Thomas Edison", "Albert Einstein", "Nikola Tesla", "Steve Jobs"] }, { quote: "The future belongs to those who believe in the beauty of their dreams.", author: "Eleanor Roosevelt", options: ["Eleanor Roosevelt", "Audrey Hepburn", "Princess Diana", "Ruth Bader Ginsburg"] }, { quote: "Success is not final, failure is not fatal: It is the courage to continue that counts.", author: "Winston Churchill", options: ["Winston Churchill", "Franklin D. Roosevelt", "Theodore Roosevelt", "Margaret Thatcher"] } ]; export default function CelebrityQuoteGame() { const [quotes, setQuotes] = useState([]); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); const [score, setScore] = useState(0); const [selectedOption, setSelectedOption] = useState(null); const [gameState, setGameState] = useState('playing'); // playing, answered, finished const [isCorrect, setIsCorrect] = useState(false); const [showAnswer, setShowAnswer] = useState(false); // Initialize or shuffle quotes useEffect(() => { // Shuffle the quotes array const shuffledQuotes = [...quoteDatabase].sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); setCurrentQuoteIndex(0); setScore(0); setGameState('playing'); setSelectedOption(null); setShowAnswer(false); }, []); const currentQuote = quotes[currentQuoteIndex]; const handleOptionSelect = (option) => { if (gameState !== 'playing') return; setSelectedOption(option); setIsCorrect(option === currentQuote.author); setGameState('answered'); if (option === currentQuote.author) { setScore(score + 1); } // Show the correct answer after a short delay setTimeout(() => { setShowAnswer(true); }, 500); }; const handleNextQuote = () => { if (currentQuoteIndex < quotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setSelectedOption(null); setGameState('playing'); setShowAnswer(false); } else { setGameState('finished'); } }; const restartGame = () => { const shuffledQuotes = [...quoteDatabase].sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); setCurrentQuoteIndex(0); setScore(0); setGameState('playing'); setSelectedOption(null); setShowAnswer(false); }; if (!currentQuote) return
Loading...
; return (

Celebrity Quote Game

Score: {score}/{quotes.length}
{gameState !== 'finished' ? ( <>

Quote {currentQuoteIndex + 1} of {quotes.length}

"{currentQuote.quote}"

Who said this?

{currentQuote.options.map((option, index) => ( ))}
{gameState === 'answered' && (

{isCorrect ? "Correct! Well done!" : `Incorrect. The quote was said by ${currentQuote.author}.`}

)} {gameState === 'answered' && ( )} ) : (

Game Complete!

Your final score: {score}/{quotes.length}

{score === quotes.length ? (

Perfect score! You're a quote master!

) : score >= quotes.length * 0.7 ? (

Great job! You know your celebrity quotes!

) : score >= quotes.length * 0.5 ? (

Not bad! You're on your way to becoming a quote expert.

) : (

Keep practicing! You'll get better with time.

)}
)}
); }