import { useState, useEffect } from 'react'; export default function WhoSaidItGame() { // Game data - quotes and their sources const quotes = [ { text: "The only thing that I regret is that I can't see my own performance.", source: "Kanye" }, { text: "I am a god.", source: "Kanye" }, { text: "I am the greatest artist that God has ever created.", source: "Kanye" }, { text: "My greatest pain in life is that I will never be able to see myself perform live.", source: "Kanye" }, { text: "I feel like I'm too busy writing history to read it.", source: "Kanye" }, { text: "Believe in your flyness, conquer your shyness.", source: "Kanye" }, { text: "The strong do what they can, the weak accept what they must.", source: "Hitler" }, { text: "If you tell a big enough lie and tell it frequently enough, it will be believed.", source: "Hitler" }, { text: "He alone, who owns the youth, gains the future.", source: "Hitler" }, { text: "Words build bridges into unexplored regions.", source: "Hitler" }, { text: "Great liars are also great magicians.", source: "Hitler" }, { text: "The victor will never be asked if he told the truth.", source: "Hitler" }, ]; // Game state const [gameStarted, setGameStarted] = useState(false); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); const [shuffledQuotes, setShuffledQuotes] = useState([]); const [score, setScore] = useState(0); const [selectedAnswer, setSelectedAnswer] = useState(null); const [showAnswer, setShowAnswer] = useState(false); const [gameOver, setGameOver] = useState(false); // Shuffle quotes when game starts useEffect(() => { if (gameStarted && shuffledQuotes.length === 0) { setShuffledQuotes([...quotes].sort(() => Math.random() - 0.5)); } }, [gameStarted, shuffledQuotes.length, quotes]); // Start the game const startGame = () => { setGameStarted(true); setScore(0); setCurrentQuoteIndex(0); setGameOver(false); setShowAnswer(false); setSelectedAnswer(null); setShuffledQuotes([...quotes].sort(() => Math.random() - 0.5)); }; // Handle player's guess const handleGuess = (guess) => { if (showAnswer) return; setSelectedAnswer(guess); setShowAnswer(true); if (guess === shuffledQuotes[currentQuoteIndex].source) { setScore(score + 1); } // Move to next quote after a delay setTimeout(() => { if (currentQuoteIndex < shuffledQuotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); setSelectedAnswer(null); } else { setGameOver(true); } }, 2000); }; // Reset the game const resetGame = () => { startGame(); }; // Calculate progress percentage const progressPercentage = gameStarted && !gameOver ? ((currentQuoteIndex) / shuffledQuotes.length) * 100 : 0; return (
{!gameStarted ? (

Who Said It?

Can you tell whether these quotes were said by Kanye West or Adolf Hitler?

) : gameOver ? (

Game Over!

Your final score: {score} out of {shuffledQuotes.length}

{score === shuffledQuotes.length ? (

Perfect score! You're an expert at distinguishing between these two... unique individuals.

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

Great job! You know your quotes pretty well.

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

Not bad! It can be surprisingly difficult to tell these quotes apart.

) : (

Better luck next time! These quotes can be trickier than they seem.

)}
) : (
{/* Progress bar */}
{/* Score */}

Score: {score} / {currentQuoteIndex}

{/* Quote card */}

"{shuffledQuotes[currentQuoteIndex]?.text}"

{/* Answer buttons */}
{/* Feedback */} {showAnswer && (

{selectedAnswer === shuffledQuotes[currentQuoteIndex]?.source ? "Correct! " : "Incorrect! "} This was said by {shuffledQuotes[currentQuoteIndex]?.source}.

)}
)}
); }