gubble
This commit is contained in:
parent
a4626ada30
commit
db0673b77f
6 changed files with 154 additions and 37 deletions
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import type { Tier } from '../App';
|
||||
import type { Upgrades } from './GubbleStore';
|
||||
|
||||
type CardProps = {
|
||||
card: {
|
||||
|
@ -14,9 +15,10 @@ type CardProps = {
|
|||
} | null>>;
|
||||
setMoney: React.Dispatch<React.SetStateAction<number>>;
|
||||
setGubblePoints: React.Dispatch<React.SetStateAction<number>>;
|
||||
upgrades?: Upgrades;
|
||||
};
|
||||
|
||||
const Card: React.FC<CardProps> = ({ card, setCard, setMoney, setGubblePoints }) => {
|
||||
const Card: React.FC<CardProps> = ({ card, setCard, setMoney, setGubblePoints, upgrades }) => {
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow p-6 flex flex-col items-center mb-6 w-full max-w-md">
|
||||
<div className="mb-2 text-lg font-semibold text-gray-700">{card.tier?.name} Scratch Card</div>
|
||||
|
@ -36,16 +38,28 @@ const Card: React.FC<CardProps> = ({ card, setCard, setMoney, setGubblePoints })
|
|||
disabled={field.scratched}
|
||||
onMouseMove={() => {
|
||||
if (field.scratched) return;
|
||||
// Gubble point gain (with upgrade)
|
||||
if (Math.random() < (card.tier?.gubblePointChance ?? 0)) {
|
||||
setGubblePoints((g) => g + 1);
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue