import React, { useState, useEffect } from 'react'; import { AlertCircle, Axe, Box, Building, Cpu, Factory, Zap } from 'lucide-react'; const Game = () => { const [selectedTool, setSelectedTool] = useState(null); const [grid, setGrid] = useState(() => Array(8).fill().map(() => Array(8).fill({ type: null, color: 'white' })) ); const [resources, setResources] = useState({ energy: 50, minerals: 50, circuits: 0 }); const [tick, setTick] = useState(0); const [researchProgress, setResearchProgress] = useState({ automation: 0, speed: 0 }); const [message, setMessage] = useState(''); const tools = { solarPanel: { cost: { minerals: 10 }, color: 'bg-yellow-200', produces: 'energy', icon: }, mineralExtractor: { cost: { energy: 10 }, color: 'bg-gray-300', produces: 'minerals', icon: }, circuitFactory: { cost: { energy: 15, minerals: 15 }, color: 'bg-green-200', produces: 'circuits', icon: } }; // Game tick for resource production useEffect(() => { const timer = setInterval(() => { setTick(t => t + 1); setResources(prev => { const newResources = { ...prev }; grid.forEach(row => { row.forEach(cell => { if (cell.type && tools[cell.type]) { const produces = tools[cell.type].produces; newResources[produces] = (newResources[produces] || 0) + 1; } }); }); return newResources; }); }, 1000); return () => clearInterval(timer); }, [grid]); const handleCellClick = (rowIndex, colIndex) => { if (!selectedTool) { setMessage('Select a building first!'); return; } const tool = tools[selectedTool]; const canAfford = Object.entries(tool.cost).every( ([resource, cost]) => resources[resource] >= cost ); if (!canAfford) { setMessage('Not enough resources!'); return; } // Deduct costs setResources(prev => { const newResources = { ...prev }; Object.entries(tool.cost).forEach(([resource, cost]) => { newResources[resource] -= cost; }); return newResources; }); // Place building setGrid(prev => { const newGrid = [...prev]; newGrid[rowIndex] = [...prev[rowIndex]]; newGrid[rowIndex][colIndex] = { type: selectedTool, color: tool.color }; return newGrid; }); // Show success message setMessage(`Built ${selectedTool}!`); setTimeout(() => setMessage(''), 2000); }; return (
{/* Resources */}
Energy: {resources.energy}
Minerals: {resources.minerals}
Circuits: {resources.circuits}
{/* Tool Selection */}
{Object.entries(tools).map(([name, data]) => ( ))}
{message && (
{message}
)}
{/* Game Grid */}
{grid.map((row, rowIndex) => ( row.map((cell, colIndex) => ( )) ))}
); }; export default Game;