import { useState, useEffect, useRef } from 'react'; import { Check, X, RefreshCw, Trophy, Clock, Volume2, VolumeX, Music, List, User, Award } from 'lucide-react'; export default function KanyeOrHitlerGame() { // Game state const [quotes, setQuotes] = useState([ { text: "The only thing that I would like to be a slave to is my creativity.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "I am the voice of a generation.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Humanitarianism is the expression of stupidity and cowardice.", author: "Hitler", answered: false, correct: null, difficulty: "Medium" }, { text: "I liberate minds with my music. That's more important than liberating a few people from apartheid or whatever.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "The receptivity of the masses is very limited, their intelligence is small, but their power of forgetting is enormous.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "Sometimes people write novels and they just be so wordy and so self-absorbed. I am not a fan of books.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Anyone who sees and paints a sky green and fields blue ought to be sterilized.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "I feel like I'm too busy writing history to read it.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "If you win, you need not have to explain. If you lose, you should not be there to explain.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "I'm a creative genius and there's no other way to word it.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "The art of reading consists in remembering the essentials and forgetting non-essentials.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "For me, money is not my definition of success; inspiring people is a definition of success.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "Strength lies not in defense but in attack.", author: "Hitler", answered: false, correct: null, difficulty: "Medium" }, { text: "People always tell you, 'Be humble. Be humble.' When was the last time someone told you to be amazing?", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Words build bridges into unexplored regions.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, ]); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); const [score, setScore] = useState(0); const [gameOver, setGameOver] = useState(false); const [showAnswer, setShowAnswer] = useState(false); const [timeLeft, setTimeLeft] = useState(null); const [timerActive, setTimerActive] = useState(false); const [gameStarted, setGameStarted] = useState(false); const [difficulty, setDifficulty] = useState("normal"); const [username, setUsername] = useState(""); const [usernameError, setUsernameError] = useState(""); const [showLeaderboard, setShowLeaderboard] = useState(false); const [leaderboard, setLeaderboard] = useState([]); const [startTime, setStartTime] = useState(null); const [totalTime, setTotalTime] = useState(0); const [muted, setMuted] = useState(false); const [showWelcome, setShowWelcome] = useState(true); // Audio references const audioRef = useRef(null); // Load leaderboard from localStorage useEffect(() => { const savedLeaderboard = localStorage.getItem('kanyeHitlerLeaderboard'); if (savedLeaderboard) { setLeaderboard(JSON.parse(savedLeaderboard)); } }, []); // Save leaderboard to localStorage when it changes useEffect(() => { if (leaderboard.length > 0) { localStorage.setItem('kanyeHitlerLeaderboard', JSON.stringify(leaderboard)); } }, [leaderboard]); // Shuffle quotes at the beginning useEffect(() => { const shuffledQuotes = [...quotes].sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); }, []); // Timer effect useEffect(() => { let timer; if (timerActive && timeLeft > 0) { timer = setTimeout(() => setTimeLeft(timeLeft - 1), 1000); } else if (timerActive && timeLeft === 0) { handleTimeout(); } return () => clearTimeout(timer); }, [timeLeft, timerActive]); // Calculate total time useEffect(() => { let timeTracker; if (gameStarted && !gameOver && startTime) { timeTracker = setInterval(() => { setTotalTime(Math.floor((Date.now() - startTime) / 1000)); }, 1000); } return () => clearInterval(timeTracker); }, [gameStarted, gameOver, startTime]); // Handle audio setup useEffect(() => { if (gameStarted && audioRef.current) { audioRef.current.volume = 0.3; audioRef.current.loop = true; if (!muted) { audioRef.current.play().catch(e => console.log("Audio play failed:", e)); } } return () => { if (audioRef.current) { audioRef.current.pause(); } }; }, [gameStarted, muted]); const toggleMute = () => { setMuted(!muted); if (audioRef.current) { if (muted) { audioRef.current.play().catch(e => console.log("Audio play failed:", e)); } else { audioRef.current.pause(); } } }; const handleTimeout = () => { const updatedQuotes = [...quotes]; const currentQuote = updatedQuotes[currentQuoteIndex]; currentQuote.answered = true; currentQuote.correct = false; setQuotes(updatedQuotes); setShowAnswer(true); setTimerActive(false); setTimeout(() => { if (currentQuoteIndex < quotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); if (difficulty !== "easy") { setTimeLeft(difficulty === "hard" ? 10 : 15); setTimerActive(true); } } else { setGameOver(true); addScoreToLeaderboard(); } }, 1500); }; const validateUsername = () => { if (!username.trim()) { setUsernameError("Please enter a username"); return false; } if (username.length < 3) { setUsernameError("Username must be at least 3 characters"); return false; } setUsernameError(""); return true; }; const startGame = (selectedDifficulty) => { if (!validateUsername()) return; setDifficulty(selectedDifficulty); setGameStarted(true); setShowWelcome(false); setStartTime(Date.now()); if (selectedDifficulty !== "easy") { setTimeLeft(selectedDifficulty === "hard" ? 10 : 15); setTimerActive(true); } }; const handleGuess = (guess) => { if (showAnswer) return; const updatedQuotes = [...quotes]; const currentQuote = updatedQuotes[currentQuoteIndex]; const isCorrect = guess === currentQuote.author; currentQuote.answered = true; currentQuote.correct = isCorrect; setQuotes(updatedQuotes); setShowAnswer(true); setTimerActive(false); if (isCorrect) { setScore(score + 1); } // Move to next quote after 1.5 seconds setTimeout(() => { if (currentQuoteIndex < quotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); if (difficulty !== "easy") { setTimeLeft(difficulty === "hard" ? 10 : 15); setTimerActive(true); } } else { setGameOver(true); addScoreToLeaderboard(); } }, 1500); }; const addScoreToLeaderboard = () => { const difficultyMultiplier = difficulty === "easy" ? 1 : difficulty === "normal" ? 1.5 : 2; const timeBonus = difficulty !== "easy" ? Math.max(0, 300 - totalTime) : 0; const calculatedScore = Math.round((score / quotes.length) * 1000 * difficultyMultiplier + timeBonus); const newScore = { username, score: calculatedScore, correct: score, total: quotes.length, difficulty, time: totalTime, date: new Date().toISOString() }; const newLeaderboard = [...leaderboard, newScore].sort((a, b) => b.score - a.score).slice(0, 10); setLeaderboard(newLeaderboard); }; const resetGame = () => { const shuffledQuotes = [...quotes].map(quote => ({ ...quote, answered: false, correct: null })).sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); setCurrentQuoteIndex(0); setScore(0); setGameOver(false); setShowAnswer(false); setGameStarted(false); setTimerActive(false); setTimeLeft(null); setShowLeaderboard(false); setTotalTime(0); setStartTime(null); setShowWelcome(true); }; const currentQuote = quotes[currentQuoteIndex]; // Calculate progress percentage const progressPercentage = ((currentQuoteIndex) / (quotes.length - 1)) * 100; // Format time display const formatTime = (seconds) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins}:${secs < 10 ? '0' : ''}${secs}`; }; // Welcome screen if (showWelcome) { return (
CONTROVERSIAL QUOTES

Kanye or Hitler?

The ultimate quote guessing game

setUsername(e.target.value)} placeholder="Your username" className="w-full pl-10 pr-4 py-3 bg-gray-700/70 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent" />
{usernameError && (

{usernameError}

)}

Choose difficulty level:

Can you tell who said what? Test your knowledge of controversial quotes!

{/* Leaderboard Modal */} {showLeaderboard && (

Leaderboard

{leaderboard.length === 0 ? (

No scores yet. Be the first to play!

) : (
{leaderboard.map((entry, index) => (
{index === 0 ? (
🥇
) : index === 1 ? (
🥈
) : index === 2 ? (
🥉
) : (
{index + 1}
)}
{entry.username}
{entry.correct}/{entry.total} correct • {entry.difficulty} • {formatTime(entry.time)}
{entry.score}
))}
)}
)}
); } return (
{/* Audio element */}
); } // Add this to your CSS const styles = ` @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .animate-fadeIn { animation: fadeIn 0.5s ease-in-out; } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } } .animate-pulse { animation: import { useState, useEffect, useRef } from 'react'; import { Check, X, RefreshCw, Trophy, Clock, Volume2, VolumeX, Music, List, User, Award } from 'lucide-react'; export default function KanyeOrHitlerGame() { // Game state const [quotes, setQuotes] = useState([ { text: "The only thing that I would like to be a slave to is my creativity.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "I am the voice of a generation.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Humanitarianism is the expression of stupidity and cowardice.", author: "Hitler", answered: false, correct: null, difficulty: "Medium" }, { text: "I liberate minds with my music. That's more important than liberating a few people from apartheid or whatever.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "The receptivity of the masses is very limited, their intelligence is small, but their power of forgetting is enormous.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "Sometimes people write novels and they just be so wordy and so self-absorbed. I am not a fan of books.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Anyone who sees and paints a sky green and fields blue ought to be sterilized.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "I feel like I'm too busy writing history to read it.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "If you win, you need not have to explain. If you lose, you should not be there to explain.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "I'm a creative genius and there's no other way to word it.", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "The art of reading consists in remembering the essentials and forgetting non-essentials.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, { text: "For me, money is not my definition of success; inspiring people is a definition of success.", author: "Kanye", answered: false, correct: null, difficulty: "Hard" }, { text: "Strength lies not in defense but in attack.", author: "Hitler", answered: false, correct: null, difficulty: "Medium" }, { text: "People always tell you, 'Be humble. Be humble.' When was the last time someone told you to be amazing?", author: "Kanye", answered: false, correct: null, difficulty: "Medium" }, { text: "Words build bridges into unexplored regions.", author: "Hitler", answered: false, correct: null, difficulty: "Hard" }, ]); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); const [score, setScore] = useState(0); const [gameOver, setGameOver] = useState(false); const [showAnswer, setShowAnswer] = useState(false); const [timeLeft, setTimeLeft] = useState(null); const [timerActive, setTimerActive] = useState(false); const [gameStarted, setGameStarted] = useState(false); const [difficulty, setDifficulty] = useState("normal"); const [username, setUsername] = useState(""); const [usernameError, setUsernameError] = useState(""); const [showLeaderboard, setShowLeaderboard] = useState(false); const [leaderboard, setLeaderboard] = useState([]); const [startTime, setStartTime] = useState(null); const [totalTime, setTotalTime] = useState(0); const [muted, setMuted] = useState(false); const [showWelcome, setShowWelcome] = useState(true); // Audio references const audioRef = useRef(null); // Load leaderboard from localStorage useEffect(() => { const savedLeaderboard = localStorage.getItem('kanyeHitlerLeaderboard'); if (savedLeaderboard) { setLeaderboard(JSON.parse(savedLeaderboard)); } }, []); // Save leaderboard to localStorage when it changes useEffect(() => { if (leaderboard.length > 0) { localStorage.setItem('kanyeHitlerLeaderboard', JSON.stringify(leaderboard)); } }, [leaderboard]); // Shuffle quotes at the beginning useEffect(() => { const shuffledQuotes = [...quotes].sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); }, []); // Timer effect useEffect(() => { let timer; if (timerActive && timeLeft > 0) { timer = setTimeout(() => setTimeLeft(timeLeft - 1), 1000); } else if (timerActive && timeLeft === 0) { handleTimeout(); } return () => clearTimeout(timer); }, [timeLeft, timerActive]); // Calculate total time useEffect(() => { let timeTracker; if (gameStarted && !gameOver && startTime) { timeTracker = setInterval(() => { setTotalTime(Math.floor((Date.now() - startTime) / 1000)); }, 1000); } return () => clearInterval(timeTracker); }, [gameStarted, gameOver, startTime]); // Handle audio setup useEffect(() => { if (gameStarted && audioRef.current) { audioRef.current.volume = 0.3; audioRef.current.loop = true; if (!muted) { audioRef.current.play().catch(e => console.log("Audio play failed:", e)); } } return () => { if (audioRef.current) { audioRef.current.pause(); } }; }, [gameStarted, muted]); const toggleMute = () => { setMuted(!muted); if (audioRef.current) { if (muted) { audioRef.current.play().catch(e => console.log("Audio play failed:", e)); } else { audioRef.current.pause(); } } }; const handleTimeout = () => { const updatedQuotes = [...quotes]; const currentQuote = updatedQuotes[currentQuoteIndex]; currentQuote.answered = true; currentQuote.correct = false; setQuotes(updatedQuotes); setShowAnswer(true); setTimerActive(false); setTimeout(() => { if (currentQuoteIndex < quotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); if (difficulty !== "easy") { setTimeLeft(difficulty === "hard" ? 10 : 15); setTimerActive(true); } } else { setGameOver(true); addScoreToLeaderboard(); } }, 1500); }; const validateUsername = () => { if (!username.trim()) { setUsernameError("Please enter a username"); return false; } if (username.length < 3) { setUsernameError("Username must be at least 3 characters"); return false; } setUsernameError(""); return true; }; const startGame = (selectedDifficulty) => { if (!validateUsername()) return; setDifficulty(selectedDifficulty); setGameStarted(true); setShowWelcome(false); setStartTime(Date.now()); if (selectedDifficulty !== "easy") { setTimeLeft(selectedDifficulty === "hard" ? 10 : 15); setTimerActive(true); } }; const handleGuess = (guess) => { if (showAnswer) return; const updatedQuotes = [...quotes]; const currentQuote = updatedQuotes[currentQuoteIndex]; const isCorrect = guess === currentQuote.author; currentQuote.answered = true; currentQuote.correct = isCorrect; setQuotes(updatedQuotes); setShowAnswer(true); setTimerActive(false); if (isCorrect) { setScore(score + 1); } // Move to next quote after 1.5 seconds setTimeout(() => { if (currentQuoteIndex < quotes.length - 1) { setCurrentQuoteIndex(currentQuoteIndex + 1); setShowAnswer(false); if (difficulty !== "easy") { setTimeLeft(difficulty === "hard" ? 10 : 15); setTimerActive(true); } } else { setGameOver(true); addScoreToLeaderboard(); } }, 1500); }; const addScoreToLeaderboard = () => { const difficultyMultiplier = difficulty === "easy" ? 1 : difficulty === "normal" ? 1.5 : 2; const timeBonus = difficulty !== "easy" ? Math.max(0, 300 - totalTime) : 0; const calculatedScore = Math.round((score / quotes.length) * 1000 * difficultyMultiplier + timeBonus); const newScore = { username, score: calculatedScore, correct: score, total: quotes.length, difficulty, time: totalTime, date: new Date().toISOString() }; const newLeaderboard = [...leaderboard, newScore].sort((a, b) => b.score - a.score).slice(0, 10); setLeaderboard(newLeaderboard); }; const resetGame = () => { const shuffledQuotes = [...quotes].map(quote => ({ ...quote, answered: false, correct: null })).sort(() => Math.random() - 0.5); setQuotes(shuffledQuotes); setCurrentQuoteIndex(0); setScore(0); setGameOver(false); setShowAnswer(false); setGameStarted(false); setTimerActive(false); setTimeLeft(null); setShowLeaderboard(false); setTotalTime(0); setStartTime(null); setShowWelcome(true); }; const currentQuote = quotes[currentQuoteIndex]; // Calculate progress percentage const progressPercentage = ((currentQuoteIndex) / (quotes.length - 1)) * 100; // Format time display const formatTime = (seconds) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins}:${secs < 10 ? '0' : ''}${secs}`; }; // Welcome screen if (showWelcome) { return (
CONTROVERSIAL QUOTES

Kanye or Hitler?

The ultimate quote guessing game

setUsername(e.target.value)} placeholder="Your username" className="w-full pl-10 pr-4 py-3 bg-gray-700/70 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent" />
{usernameError && (

{usernameError}

)}

Choose difficulty level:

Can you tell who said what? Test your knowledge of controversial quotes!

{/* Leaderboard Modal */} {showLeaderboard && (

Leaderboard

{leaderboard.length === 0 ? (

No scores yet. Be the first to play!

) : (
{leaderboard.map((entry, index) => (
{index === 0 ? (
🥇
) : index === 1 ? (
🥈
) : index === 2 ? (
🥉
) : (
{index + 1}
)}
{entry.username}
{entry.correct}/{entry.total} correct • {entry.difficulty} • {formatTime(entry.time)}
{entry.score}
))}
)}
)}
); } return (
{/* Audio element */}
); } // Add this to your CSS const styles = ` @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .animate-fadeIn { animation: fadeIn 0.5s ease-in-out; } `; // Add the styles to the document const styleElement = document.createElement('style'); styleElement.innerHTML = styles; document.head.appendChild(styleElement);