import React, { useState, useEffect, useCallback } from 'react'; import { Dice, Home, Trophy, Users, Bot, Volume2, VolumeX, Undo, HelpCircle } from 'lucide-react'; // Game Constants const GAME_MODES = { LOCAL: 'local', AI: 'ai', ONLINE: 'online' }; const COLORS = { red: { primary: '#FF6B6B', secondary: '#FFE3E3', text: 'white' }, green: { primary: '#51CF66', secondary: '#D8F5A2', text: 'white' }, blue: { primary: '#339AF0', secondary: '#D0EBFF', text: 'white' }, yellow: { primary: '#FCC419', secondary: '#FFF3BF', text: 'black' } }; const START_POSITIONS = { red: 0, green: 13, blue: 26, yellow: 39 }; // Token Component const Token = ({ color, onClick, size = 24, disabled }) => { return (
); }; // Dice Component const DiceComponent = ({ value, isRolling, onRoll, disabled }) => { return (
{isRolling ? ( ) : ( {value || '?'} )}
); }; // Game Board Cell const Cell = ({ position, tokens, isHighlighted, onClick }) => { return (
{tokens.map((token, index) => ( onClick(token)} disabled={!token.canMove} /> ))}
); }; // Player Info Component const PlayerInfo = ({ color, isCurrentPlayer, tokens, onTokenSelect }) => { return (
{color} {tokens.filter(t => t.completed).length} / 4
{tokens.map(token => ( onTokenSelect(token)} disabled={!token.canMove} /> ))}
); }; // Main Game Component const LudoGame = () => { const [gameState, setGameState] = useState({ mode: null, players: [], currentPlayer: null, tokens: {}, diceValue: null, isRolling: false, winner: null, moveHistory: [] }); const [settings, setSettings] = useState({ sound: true, showHelp: false }); // Game initialization const initGame = useCallback((mode, numPlayers) => { const players = Object.keys(COLORS).slice(0, numPlayers); const tokens = {}; players.forEach(color => { tokens[color] = Array(4).fill(null).map((_, id) => ({ id, color, position: 'home', completed: false, canMove: false })); }); setGameState({ mode, players, currentPlayer: players[0], tokens, diceValue: null, isRolling: false, winner: null, moveHistory: [] }); }, []); // Handle dice roll const handleDiceRoll = useCallback(() => { if (gameState.isRolling || gameState.winner) return; setGameState(prev => ({ ...prev, isRolling: true })); setTimeout(() => { const value = Math.floor(Math.random() * 6) + 1; if (settings.sound) { // Play dice sound new Audio('/dice.mp3').play().catch(() => {}); } setGameState(prev => ({ ...prev, diceValue: value, isRolling: false, tokens: updateValidMoves(prev.tokens, prev.currentPlayer, value) })); }, 1000); }, [gameState.isRolling, gameState.winner, settings.sound]); // Handle token movement const handleTokenMove = useCallback((token) => { if (!token.canMove || gameState.winner) return; const newState = moveToken(gameState, token); if (settings.sound) { // Play move sound new Audio('/move.mp3').play().catch(() => {}); } setGameState(newState); }, [gameState, settings.sound]); // AI move handler useEffect(() => { if (gameState.mode === GAME_MODES.AI && gameState.currentPlayer !== gameState.players[0] && !gameState.winner) { const timer = setTimeout(() => { // AI logic here const aiMove = calculateAIMove(gameState); if (aiMove) { handleTokenMove(aiMove); } }, 1000); return () => clearTimeout(timer); } }, [gameState, handleTokenMove]); // Render game setup screen if (!gameState.mode) { return (

Ludo Game

); } return (
{/* Game Board */}
{/* Render board cells */}
{/* Game Controls */}
{/* Game Status */}
{gameState.winner ? (
Winner: {gameState.winner}
) : (
Current Player: {gameState.currentPlayer}
)}
{/* Dice */}
{/* Players */}
{gameState.players.map(color => ( ))}
{/* Controls */}
{/* Help Modal */} {settings.showHelp && (

How to Play

{/* Add rules content */}
)}
); }; export default LudoGame;