import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Checkbox } from '@/components/ui/checkbox'; import { Dice1, Dice2, Dice3, Dice4, Dice5, Dice6, RotateCcw, Settings } from 'lucide-react'; import SocialShare from '@/components/SocialShare'; interface CrapsGameProps { showSocialShare?: boolean; } const getDiceIcon = (value: number) => { switch (value) { case 1: return ; case 2: return ; case 3: return ; case 4: return ; case 5: return ; case 6: return ; default: return ; } }; const CrapsGame: React.FC = ({ showSocialShare = false }) => { const [dice1, setDice1] = useState(null); const [dice2, setDice2] = useState(null); const [isRolling, setIsRolling] = useState(false); const [gameResult, setGameResult] = useState<'win' | 'lose' | 'continue' | null>(null); const [rollCount, setRollCount] = useState(0); // Custom rules state const [customWinSums, setCustomWinSums] = useState([7, 11]); const [customLoseSums, setCustomLoseSums] = useState([2, 3, 12]); const [isCustomRules, setIsCustomRules] = useState(false); const [isRulesModalOpen, setIsRulesModalOpen] = useState(false); const rollDice = () => { setIsRolling(true); setGameResult(null); // Simulate rolling animation setTimeout(() => { const newDice1 = Math.floor(Math.random() * 6) + 1; const newDice2 = Math.floor(Math.random() * 6) + 1; const sum = newDice1 + newDice2; setDice1(newDice1); setDice2(newDice2); setRollCount(prev => prev + 1); // Determine game result based on current rules const winSums = isCustomRules ? customWinSums : [7, 11]; const loseSums = isCustomRules ? customLoseSums : [2, 3, 12]; if (loseSums.includes(sum)) { setGameResult('lose'); } else if (winSums.includes(sum)) { setGameResult('win'); } else { setGameResult('continue'); } setIsRolling(false); }, 1000); }; const resetGame = () => { setDice1(null); setDice2(null); setGameResult(null); setRollCount(0); }; const sum = dice1 && dice2 ? dice1 + dice2 : null; const getResultMessage = () => { if (!gameResult) return null; switch (gameResult) { case 'win': return (
🎉 You Win! 🎉

Rolling {sum} on the first throw wins immediately!

); case 'lose': return (
💸 You Lose! 💸

Rolling {sum} on the first throw loses immediately!

); case 'continue': return (
🎲 Game Continues 🎲

Your point is {sum}. Keep playing to win or lose!

); default: return null; } }; return (
Craps: First Throw Roll two dice and see what happens on the opening throw of craps! {/* Rules */} {isCustomRules ? 'Custom Rules' : 'Classic Rules'} Customize Craps Rules Select which dice sums result in immediate wins or losses on the first throw.

Loss Sums

{Array.from({ length: 12 }, (_, i) => i + 1).map((sum) => (
{ if (checked) { setCustomLoseSums([...customLoseSums.filter(s => s !== sum), sum]); setCustomWinSums(customWinSums.filter(s => s !== sum)); } else { setCustomLoseSums(customLoseSums.filter(s => s !== sum)); } }} />
))}

Win Sums

{Array.from({ length: 12 }, (_, i) => i + 1).map((sum) => (
{ if (checked) { setCustomWinSums([...customWinSums.filter(s => s !== sum), sum]); setCustomLoseSums(customLoseSums.filter(s => s !== sum)); } else { setCustomWinSums(customWinSums.filter(s => s !== sum)); } }} />
))}
Immediate Loss

{isCustomRules ? (customLoseSums.length > 0 ? customLoseSums.join(', ') : 'None') : 'Rolling 2, 3, or 12'}

Immediate Win

{isCustomRules ? (customWinSums.length > 0 ? customWinSums.join(', ') : 'None') : 'Rolling 7 or 11'}

Game Continues

All other sums

{/* Dice Display */}
{dice1 ? getDiceIcon(dice1) :
}

Die 1

{dice1 &&

{dice1}

}
+
{dice2 ? getDiceIcon(dice2) :
}

Die 2

{dice2 &&

{dice2}

}
=
{sum ? (
{sum}
) : (
)}

Total

{/* Result */} {getResultMessage()} {/* Statistics */}

Rolls: {rollCount}

{/* Controls */}
{/* Educational Information */} About Craps

Craps is a classic casino dice game that demonstrates interesting probability concepts. The first throw (called the "come out roll") immediately determines the outcome in certain cases:

Losing Numbers (Craps)

  • • 2 (Snake Eyes): 1/36 probability
  • • 3: 2/36 probability
  • • 12 (Boxcars): 1/36 probability
  • Total losing probability: 4/36 = 11.1%

Winning Numbers (Natural)

  • • 7: 6/36 probability
  • • 11: 2/36 probability
  • Total winning probability: 8/36 = 22.2%

If you roll 4, 5, 6, 8, 9, or 10, that becomes your "point" and the game continues with different rules.

{showSocialShare && (
)}
); }; export default CrapsGame;