import React, { useState, useEffect } from 'react'; import { Trophy, RotateCcw, Star } from 'lucide-react'; const MovieBoxOfficeGame = () => { // Movie data with box office earnings (in millions USD) const movies = [ { title: "Avatar", year: 2009, boxOffice: 2847, genre: "Sci-Fi" }, { title: "Avengers: Endgame", year: 2019, boxOffice: 2798, genre: "Action" }, { title: "Avatar: The Way of Water", year: 2022, boxOffice: 2320, genre: "Sci-Fi" }, { title: "Titanic", year: 1997, boxOffice: 2257, genre: "Romance" }, { title: "Star Wars: The Force Awakens", year: 2015, boxOffice: 2071, genre: "Sci-Fi" }, { title: "Avengers: Infinity War", year: 2018, boxOffice: 2048, genre: "Action" }, { title: "Spider-Man: No Way Home", year: 2021, boxOffice: 1921, genre: "Action" }, { title: "Jurassic World", year: 2015, boxOffice: 1672, genre: "Adventure" }, { title: "The Lion King", year: 2019, boxOffice: 1657, genre: "Animation" }, { title: "The Avengers", year: 2012, boxOffice: 1519, genre: "Action" }, { title: "Furious 7", year: 2015, boxOffice: 1516, genre: "Action" }, { title: "Top Gun: Maverick", year: 2022, boxOffice: 1489, genre: "Action" }, { title: "Frozen II", year: 2019, boxOffice: 1450, genre: "Animation" }, { title: "Avengers: Age of Ultron", year: 2015, boxOffice: 1403, genre: "Action" }, { title: "Black Panther", year: 2018, boxOffice: 1347, genre: "Action" }, { title: "Harry Potter and the Deathly Hallows – Part 2", year: 2011, boxOffice: 1342, genre: "Fantasy" }, { title: "Star Wars: The Last Jedi", year: 2017, boxOffice: 1333, genre: "Sci-Fi" }, { title: "Jurassic World: Fallen Kingdom", year: 2018, boxOffice: 1310, genre: "Adventure" }, { title: "Frozen", year: 2013, boxOffice: 1282, genre: "Animation" }, { title: "Beauty and the Beast", year: 2017, boxOffice: 1264, genre: "Romance" } ]; const [currentMovie, setCurrentMovie] = useState(null); const [nextMovie, setNextMovie] = useState(null); const [score, setScore] = useState(0); const [highScore, setHighScore] = useState(0); const [gameOver, setGameOver] = useState(false); const [showResult, setShowResult] = useState(false); const [usedMovies, setUsedMovies] = useState([]); const [streak, setStreak] = useState(0); // Initialize game useEffect(() => { const savedHighScore = localStorage.getItem('movieGameHighScore'); if (savedHighScore) { setHighScore(parseInt(savedHighScore)); } startNewGame(); }, []); const getRandomMovie = (excludeMovies = []) => { const availableMovies = movies.filter(movie => !excludeMovies.some(used => used.title === movie.title) ); if (availableMovies.length === 0) return null; return availableMovies[Math.floor(Math.random() * availableMovies.length)]; }; const startNewGame = () => { const firstMovie = getRandomMovie(); const secondMovie = getRandomMovie([firstMovie]); setCurrentMovie(firstMovie); setNextMovie(secondMovie); setUsedMovies([firstMovie]); setScore(0); setStreak(0); setGameOver(false); setShowResult(false); }; const makeGuess = (guess) => { if (gameOver || showResult) return; setShowResult(true); const isCorrect = (guess === 'higher' && nextMovie.boxOffice >= currentMovie.boxOffice) || (guess === 'lower' && nextMovie.boxOffice <= currentMovie.boxOffice); setTimeout(() => { if (isCorrect) { const newScore = score + 1; const newStreak = streak + 1; setScore(newScore); setStreak(newStreak); if (newScore > highScore) { setHighScore(newScore); localStorage.setItem('movieGameHighScore', newScore.toString()); } // Continue game const newUsedMovies = [...usedMovies, nextMovie]; const newNextMovie = getRandomMovie(newUsedMovies); if (newNextMovie) { setCurrentMovie(nextMovie); setNextMovie(newNextMovie); setUsedMovies(newUsedMovies); setShowResult(false); } else { // No more movies available setGameOver(true); } } else { setGameOver(true); } }, 2000); }; const formatBoxOffice = (amount) => { if (amount >= 1000) { return `$${(amount / 1000).toFixed(1)}B`; } return `$${amount}M`; }; const getScoreMessage = () => { if (score === 0) return "Better luck next time!"; if (score < 3) return "Not bad for a start!"; if (score < 5) return "Getting warmer!"; if (score < 8) return "Movie buff in training!"; if (score < 12) return "Impressive knowledge!"; if (score < 15) return "Box office expert!"; return "Hollywood insider!"; }; if (!currentMovie || !nextMovie) { return (
Loading...
); } return (
{/* Header */}

Box Office Battle

Score
{score}
Best
{highScore}
{/* Game Area */}
{!gameOver ? (
{/* Current Movie */}
{currentMovie.genre} • {currentMovie.year}

{currentMovie.title}

Box Office Earnings
{formatBoxOffice(currentMovie.boxOffice)}
{/* Next Movie */}
{nextMovie.genre} • {nextMovie.year}

{nextMovie.title}

{showResult ? (
Box Office Earnings
{formatBoxOffice(nextMovie.boxOffice)}
) : (

Did {nextMovie.title} earn higher or lower than {currentMovie.title}?

)}
) : ( /* Game Over Screen */

Game Over!

{getScoreMessage()}

{score}

{score === 1 ? "1 correct guess" : `${score} correct guesses`}

{score > 0 && (

Final Answer:

{currentMovie.title}
{formatBoxOffice(currentMovie.boxOffice)}
{nextMovie.title}
{formatBoxOffice(nextMovie.boxOffice)}
)}
)}
{/* Instructions */} {!gameOver && (

How to Play

Compare box office earnings between two movies. Guess whether the second movie earned higher or lower than the first. Keep guessing correctly to build your streak!

)}
); }; export default MovieBoxOfficeGame;