Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState, useEffect } from 'react';
- import { Sparkles, Heart, Zap, Leaf, Droplets, Mountain } from 'lucide-react';
- const MonsterCatcherGame = () => {
- const [currentMonster, setCurrentMonster] = useState(null);
- const [collection, setCollection] = useState([]);
- const [energy, setEnergy] = useState(100);
- const [catchMessage, setCatchMessage] = useState('');
- const [gameStats, setGameStats] = useState({ encountered: 0, caught: 0 });
- const monsters = [
- { id: 1, name: 'Flamewyrm', type: 'Fire', rarity: 'Common', catchRate: 70, icon: '🔥', color: 'bg-red-500' },
- { id: 2, name: 'Aquafin', type: 'Water', rarity: 'Common', catchRate: 75, icon: '🌊', color: 'bg-blue-500' },
- { id: 3, name: 'Leafwhisper', type: 'Nature', rarity: 'Common', catchRate: 80, icon: '🌱', color: 'bg-green-500' },
- { id: 4, name: 'Thunderclaw', type: 'Electric', rarity: 'Uncommon', catchRate: 50, icon: '⚡', color: 'bg-yellow-500' },
- { id: 5, name: 'Crystalwing', type: 'Crystal', rarity: 'Uncommon', catchRate: 45, icon: '💎', color: 'bg-purple-500' },
- { id: 6, name: 'Shadowmist', type: 'Dark', rarity: 'Rare', catchRate: 30, icon: '🌙', color: 'bg-gray-700' },
- { id: 7, name: 'Sunburst', type: 'Light', rarity: 'Rare', catchRate: 25, icon: '☀️', color: 'bg-orange-400' },
- { id: 8, name: 'Voidkeeper', type: 'Void', rarity: 'Legendary', catchRate: 15, icon: '🌌', color: 'bg-black' },
- { id: 9, name: 'Starfall', type: 'Cosmic', rarity: 'Legendary', catchRate: 10, icon: '⭐', color: 'bg-indigo-600' },
- ];
- const getTypeIcon = (type) => {
- const iconMap = {
- Fire: <Zap className="w-4 h-4" />,
- Water: <Droplets className="w-4 h-4" />,
- Nature: <Leaf className="w-4 h-4" />,
- Electric: <Zap className="w-4 h-4" />,
- Crystal: <Mountain className="w-4 h-4" />,
- Dark: <Heart className="w-4 h-4" />,
- Light: <Sparkles className="w-4 h-4" />,
- Void: <Heart className="w-4 h-4" />,
- Cosmic: <Sparkles className="w-4 h-4" />
- };
- return iconMap[type] || <Heart className="w-4 h-4" />;
- };
- const getRarityColor = (rarity) => {
- const colorMap = {
- Common: 'border-gray-400 text-gray-600',
- Uncommon: 'border-green-400 text-green-600',
- Rare: 'border-blue-400 text-blue-600',
- Legendary: 'border-purple-400 text-purple-600'
- };
- return colorMap[rarity] || 'border-gray-400 text-gray-600';
- };
- const searchForMonster = () => {
- if (energy < 10) {
- setCatchMessage("Not enough energy! Wait for it to regenerate.");
- return;
- }
- setEnergy(prev => prev - 10);
- setGameStats(prev => ({ ...prev, encountered: prev.encountered + 1 }));
- // Weighted random selection based on rarity
- const commonChance = 60;
- const uncommonChance = 25;
- const rareChance = 12;
- const legendaryChance = 3;
- const roll = Math.random() * 100;
- let selectedRarity;
- if (roll < legendaryChance) selectedRarity = 'Legendary';
- else if (roll < legendaryChance + rareChance) selectedRarity = 'Rare';
- else if (roll < legendaryChance + rareChance + uncommonChance) selectedRarity = 'Uncommon';
- else selectedRarity = 'Common';
- const availableMonsters = monsters.filter(m => m.rarity === selectedRarity);
- const randomMonster = availableMonsters[Math.floor(Math.random() * availableMonsters.length)];
- setCurrentMonster(randomMonster);
- setCatchMessage(`A wild ${randomMonster.name} appeared!`);
- };
- const attemptCatch = () => {
- if (!currentMonster || energy < 5) {
- setCatchMessage("Not enough energy to attempt catch!");
- return;
- }
- setEnergy(prev => prev - 5);
- const success = Math.random() * 100 < currentMonster.catchRate;
- if (success) {
- const isAlreadyCaught = collection.some(m => m.id === currentMonster.id);
- if (!isAlreadyCaught) {
- setCollection(prev => [...prev, { ...currentMonster, caughtAt: new Date().toLocaleTimeString() }]);
- setGameStats(prev => ({ ...prev, caught: prev.caught + 1 }));
- setCatchMessage(`Success! You caught ${currentMonster.name}! Added to your collection.`);
- } else {
- setCatchMessage(`You caught ${currentMonster.name}, but you already have one in your collection.`);
- }
- } else {
- setCatchMessage(`${currentMonster.name} escaped! Try again or search for another monster.`);
- }
- };
- // Energy regeneration
- useEffect(() => {
- const interval = setInterval(() => {
- setEnergy(prev => Math.min(100, prev + 2));
- }, 1000);
- return () => clearInterval(interval);
- }, []);
- return (
- <div className="min-h-screen bg-gradient-to-br from-purple-900 via-blue-900 to-indigo-900 p-4">
- <div className="max-w-4xl mx-auto">
- <h1 className="text-4xl font-bold text-white text-center mb-8 flex items-center justify-center gap-2">
- <Sparkles className="w-8 h-8" />
- Monster Catcher
- <Sparkles className="w-8 h-8" />
- </h1>
- {/* Game Stats */}
- <div className="bg-white/10 backdrop-blur-sm rounded-lg p-4 mb-6">
- <div className="grid grid-cols-3 gap-4 text-center text-white">
- <div>
- <div className="text-2xl font-bold">{energy}</div>
- <div className="text-sm opacity-80">Energy</div>
- <div className="w-full bg-gray-700 rounded-full h-2 mt-1">
- <div
- className="bg-green-500 h-2 rounded-full transition-all duration-300"
- style={{ width: `${energy}%` }}
- ></div>
- </div>
- </div>
- <div>
- <div className="text-2xl font-bold">{gameStats.encountered}</div>
- <div className="text-sm opacity-80">Encountered</div>
- </div>
- <div>
- <div className="text-2xl font-bold">{collection.length}</div>
- <div className="text-sm opacity-80">Collected</div>
- </div>
- </div>
- </div>
- {/* Current Monster */}
- <div className="bg-white/10 backdrop-blur-sm rounded-lg p-6 mb-6">
- {currentMonster ? (
- <div className="text-center">
- <div className="text-6xl mb-4">{currentMonster.icon}</div>
- <h2 className="text-2xl font-bold text-white mb-2">{currentMonster.name}</h2>
- <div className="flex items-center justify-center gap-2 mb-4">
- {getTypeIcon(currentMonster.type)}
- <span className="text-white">{currentMonster.type}</span>
- <span className={`px-2 py-1 rounded-full text-xs border ${getRarityColor(currentMonster.rarity)}`}>
- {currentMonster.rarity}
- </span>
- </div>
- <div className="text-white mb-4">
- Catch Rate: {currentMonster.catchRate}%
- </div>
- <button
- onClick={attemptCatch}
- disabled={energy < 5}
- className="bg-red-500 hover:bg-red-600 disabled:bg-gray-500 text-white px-6 py-2 rounded-lg font-bold transition-colors"
- >
- Throw Pokeball! (5 Energy)
- </button>
- </div>
- ) : (
- <div className="text-center text-white">
- <div className="text-6xl mb-4">🔍</div>
- <p>Search for monsters to begin your adventure!</p>
- </div>
- )}
- </div>
- {/* Action Buttons */}
- <div className="text-center mb-6">
- <button
- onClick={searchForMonster}
- disabled={energy < 10}
- className="bg-blue-500 hover:bg-blue-600 disabled:bg-gray-500 text-white px-8 py-3 rounded-lg font-bold mr-4 transition-colors"
- >
- Search for Monster (10 Energy)
- </button>
- </div>
- {/* Message */}
- {catchMessage && (
- <div className="bg-white/20 backdrop-blur-sm rounded-lg p-4 mb-6 text-center text-white">
- {catchMessage}
- </div>
- )}
- {/* Collection */}
- <div className="bg-white/10 backdrop-blur-sm rounded-lg p-6">
- <h3 className="text-xl font-bold text-white mb-4">Your Collection ({collection.length}/9)</h3>
- {collection.length > 0 ? (
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
- {collection.map((monster, index) => (
- <div key={index} className="bg-white/20 rounded-lg p-4 text-center">
- <div className="text-3xl mb-2">{monster.icon}</div>
- <div className="text-white font-bold">{monster.name}</div>
- <div className="text-sm text-white/80">{monster.type}</div>
- <div className={`text-xs px-2 py-1 rounded-full border ${getRarityColor(monster.rarity)} mt-2 inline-block`}>
- {monster.rarity}
- </div>
- <div className="text-xs text-white/60 mt-1">
- Caught at {monster.caughtAt}
- </div>
- </div>
- ))}
- </div>
- ) : (
- <div className="text-center text-white/60">
- Your collection is empty. Start catching monsters!
- </div>
- )}
- </div>
- </div>
- </div>
- );
- };
- export default MonsterCatcherGame;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement