This commit is contained in:
lubiana 2025-07-12 23:04:15 +02:00
parent 9e0b3096ff
commit 5b822faa72
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
8 changed files with 116 additions and 54 deletions

View file

@ -1,6 +1,7 @@
import React from 'react';
import type { Tier } from '../App';
import type { Upgrades } from './GubbleStore';
import ScratchFieldButton from './ScratchFieldButton';
type CardProps = {
card: {
@ -35,50 +36,17 @@ const Card: React.FC<CardProps> = ({ card, setCard, setMoney, setGubblePoints, u
</div>
<div className="grid grid-cols-3 gap-4 mb-2">
{card.fields.map((field, idx) => (
<button
<ScratchFieldButton
key={idx}
className={`w-16 h-16 flex items-center justify-center rounded-lg border-2 text-2xl font-bold transition
${field.scratched ? (field.won ? 'bg-green-900 border-green-700 text-green-300' : 'bg-gray-700 border-gray-600 text-gray-400') : 'bg-yellow-900 border-yellow-700 text-yellow-300 hover:bg-yellow-800'}`}
disabled={field.scratched}
onMouseMove={() => {
if (field.scratched) return;
// Gubble point gain (with upgrade)
if (Math.random() < (card.tier?.gubblePointChance ?? 0)) {
setGubblePoints((g) => g + (upgrades?.gubbleDouble ? 2 : 1));
return;
}
// Determine win amount
let won = null;
if (card.winningNumbers.includes(field.value)) {
won = 0;
if (idx < 2) won = Math.ceil((card.tier?.buyPrice ?? 0) * 0.5);
else if (idx < 4) won = Math.ceil((card.tier?.buyPrice ?? 0) * 0.8);
else won = Math.ceil((card.tier?.buyPrice ?? 0) * 1.2);
// Apply upgrades
if (upgrades?.allTripple) {
won = won * 2;
}
if (upgrades?.evenDouble && field.value % 2 === 0) {
won = won * 2;
}
if (upgrades?.oddDouble && field.value % 2 === 1) {
won = won * 2;
}
}
setCard((prev) => {
if (!prev) return prev;
const newFields = prev.fields.map((f, i) => i === idx ? { ...f, scratched: true, won } : f);
return { ...prev, fields: newFields };
});
if (won) setMoney((m) => m + won);
}}
>
{field.scratched ? (
<span>{field.value}{field.won ? <span className="block text-xs font-normal text-green-300">+${formatter.format(field.won)}</span> : ''}</span>
) : (
<span className="text-3xl select-none">?</span>
)}
</button>
field={field}
idx={idx}
card={card}
setCard={setCard}
setMoney={setMoney}
setGubblePoints={setGubblePoints}
upgrades={upgrades}
formatter={formatter}
/>
))}
</div>
<div className="text-xs text-gray-400">Scratch each field one at a time. Winnings: 1-2 = 50%, 3-4 = 80%, 5-6 = 120% of card price.</div>