import { useState, useEffect } from 'react'; import { Check, X, RefreshCw, AlertTriangle } from 'lucide-react'; // Array of quotes with attributions const quotes = [ { text: "I am the greatest artist that God has ever created.", author: "Kanye West", year: "2019" }, { text: "The victor will never be asked if he told the truth.", author: "Adolf Hitler", year: "1925" }, { text: "I am Warhol. I am the No. 1 most impactful artist of our generation. I am Shakespeare in the flesh.", author: "Kanye West", year: "2013" }, { text: "Great liars are also great magicians.", author: "Adolf Hitler", year: "1925" }, { text: "My greatest pain in life is that I will never be able to see myself perform live.", author: "Kanye West", year: "2013" }, { text: "If you tell a big enough lie and tell it frequently enough, it will be believed.", author: "Adolf Hitler", year: "1925" }, { text: "I feel like I'm too busy writing history to read it.", author: "Kanye West", year: "2012" }, { text: "Words build bridges into unexplored regions.", author: "Adolf Hitler", year: "1925" }, { text: "I'm a creative genius and there's no other way to word it.", author: "Kanye West", year: "2013" }, { text: "The very first essential for success is a perpetually constant and regular employment of violence.", author: "Adolf Hitler", year: "1925" } ]; export default function QuoteGuessingGame() { const [gameQuotes, setGameQuotes] = useState([]); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); const [score, setScore] = useState(0); const [showAnswer, setShowAnswer] = useState(false); const [selectedAuthor, setSelectedAuthor] = useState(null); const [gameOver, setGameOver] = useState(false); const [gameStarted, setGameStarted] = useState(false); // Initialize game with shuffled quotes const startGame = () => { const shuffled = [...quotes].sort(() => 0.5 - Math.random()); setGameQuotes(shuffled); setCurrentQuoteIndex(0); setScore(0); setShowAnswer(false); setSelectedAuthor(null); setGameOver(false); setGameStarted(true); }; // Handle user's guess const handleGuess = (author) => { if (showAnswer) return; setSelectedAuthor(author); setShowAnswer(true); if (author === gameQuotes[currentQuoteIndex].author) { setScore(score + 1); } }; // Move to next quote const nextQuote = () => { if (currentQuoteIndex < gameQuotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); setSelectedAuthor(null); } else { setGameOver(true); } }; // Restart the game const restartGame = () => { startGame(); }; // Start game on component mount useEffect(() => { startGame(); }, []); if (!gameStarted) { return (
Can you tell who said it: Adolf Hitler or Kanye West?
Your final score: {score} out of {gameQuotes.length}