diff --git a/src/App.tsx b/src/App.tsx index f9c8c26..4f68cc8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,31 +1,36 @@ import { useState } from 'react' import React from 'react'; // Added for useEffect +import Card from './components/Card'; // --- Scratch Card Game Types and State --- -type Tier = { +export type Tier = { name: string; unlockPrice: number; buyPrice: number; + gubblePointChance: number; }; const TIERS: Tier[] = [ - { name: 'Start', unlockPrice: 0, buyPrice: 1 }, - { name: 'Bronze', unlockPrice: 2, buyPrice: 3 }, - { name: 'Silver', unlockPrice: 5, buyPrice: 7 }, - { name: 'Gold', unlockPrice: 10, buyPrice: 15 }, - { name: 'Platinum', unlockPrice: 20, buyPrice: 30 }, - { name: 'Diamond', unlockPrice: 50, buyPrice: 75 }, - { name: 'Master', unlockPrice: 100, buyPrice: 150 }, - { name: 'Legend', unlockPrice: 200, buyPrice: 300 }, - { name: 'Ultimate', unlockPrice: 500, buyPrice: 750 }, - { name: 'Champion', unlockPrice: 1000, buyPrice: 1500 }, - { name: 'Supreme', unlockPrice: 2000, buyPrice: 3000 }, + { name: 'Start', unlockPrice: 0, buyPrice: 1, gubblePointChance: 0.0 }, + { name: 'Bronze', unlockPrice: 2, buyPrice: 3, gubblePointChance: 0.0 }, + { name: 'Silver', unlockPrice: 5, buyPrice: 7, gubblePointChance: 0.0 }, + { name: 'Gold', unlockPrice: 10, buyPrice: 15, gubblePointChance: 0.1 }, + { name: 'Platinum', unlockPrice: 20, buyPrice: 30, gubblePointChance: 0.1 }, + { name: 'Diamond', unlockPrice: 50, buyPrice: 75, gubblePointChance: 0.2 }, + { name: 'Master', unlockPrice: 100, buyPrice: 150, gubblePointChance: 0.2 }, + { name: 'Legend', unlockPrice: 200, buyPrice: 300, gubblePointChance: 0.3 }, + { name: 'Ultimate', unlockPrice: 500, buyPrice: 750, gubblePointChance: 0.3 }, + { name: 'Champion', unlockPrice: 1000, buyPrice: 1500, gubblePointChance: 0.4 }, + { name: 'Supreme', unlockPrice: 2000, buyPrice: 3000, gubblePointChance: 0.4 }, ]; +// --- Card Component --- + function App() { // --- Game State --- const [money, setMoney] = useState(20); // User starts with $20 const [unlockedTiers, setUnlockedTiers] = useState([]); // Unlocked tier names + const [gubblePoints, setGubblePoints] = useState(0); // Remove selectedTier state // --- Card State --- @@ -95,21 +100,13 @@ function App() { } }, [card]); - // --- Card Disappear After All Scratched --- - React.useEffect(() => { - if (!card) return; - const allScratched = card.fields.every(f => f.scratched); - if (allScratched) { - const timeout = setTimeout(() => setCard(null), 1500); - return () => clearTimeout(timeout); - } - }, [card]); // --- UI --- return (

Scratch Card Game

Money: ${money}
+
Gubble Points: {gubblePoints}
{TIERS.map((tier) => { const unlocked = unlockedTiers.includes(tier.name); @@ -142,56 +139,13 @@ function App() { {/* Tier Info and Card Summary */} {/* Remove all selectedTier-dependent UI (selected tier info, buy button outside tier cards, etc.) */} {card && ( -
- Winnings this card: - ${card.fields.reduce((sum, f) => sum + (f.won || 0), 0)} -
- )} - {/* Card UI */} - {card && ( -
-
{card.tier?.name} Scratch Card
-
- {card.winningNumbers.map((num, i) => ( -
- {num} -
- ))} + <> +
+ Winnings this card: + ${card.fields.reduce((sum, f) => sum + (f.won || 0), 0)}
-
- {card.fields.map((field, idx) => ( - - ))} -
-
Scratch each field one at a time. Winnings: 1-2 = 50%, 3-4 = 80%, 5-6 = 120% of card price.
-
+ + )} {/* Play History */} {history.length > 0 && ( diff --git a/src/components/Card.tsx b/src/components/Card.tsx new file mode 100644 index 0000000..c927ae6 --- /dev/null +++ b/src/components/Card.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import type { Tier } from '../App'; + +type CardProps = { + card: { + winningNumbers: number[]; + fields: { value: number; scratched: boolean; won: number | null }[]; + tier: Tier | null; + }; + setCard: React.Dispatch>; + setMoney: React.Dispatch>; + setGubblePoints: React.Dispatch>; +}; + +const Card: React.FC = ({ card, setCard, setMoney, setGubblePoints }) => { + return ( +
+
{card.tier?.name} Scratch Card
+
+ {card.winningNumbers.map((num, i) => ( +
+ {num} +
+ ))} +
+
+ {card.fields.map((field, idx) => ( + + ))} +
+
Scratch each field one at a time. Winnings: 1-2 = 50%, 3-4 = 80%, 5-6 = 120% of card price.
+
+ ); +}; + +export type { CardProps }; +export default Card; \ No newline at end of file