diff options
Diffstat (limited to '')
| -rw-r--r-- | web/play/src/blackjack.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/web/play/src/blackjack.ts b/web/play/src/blackjack.ts index 3537f45..49d46fa 100644 --- a/web/play/src/blackjack.ts +++ b/web/play/src/blackjack.ts | |||
| @@ -1,6 +1,14 @@ | |||
| 1 | import type { View } from "./types"; | 1 | import type { View } from "./types"; |
| 2 | import { cardFace, clear, money, node } from "./dom"; | 2 | import { cardFace, clear, money, node } from "./dom"; |
| 3 | 3 | ||
| 4 | let lastAction = 0; | ||
| 5 | |||
| 6 | function actionAllowed(): boolean { | ||
| 7 | if (Date.now() - lastAction < 400) return false; | ||
| 8 | lastAction = Date.now(); | ||
| 9 | return true; | ||
| 10 | } | ||
| 11 | |||
| 4 | function cardElement(card: string): HTMLElement { | 12 | function cardElement(card: string): HTMLElement { |
| 5 | if (card === "?") { | 13 | if (card === "?") { |
| 6 | const back = node("div", "card back"); | 14 | const back = node("div", "card back"); |
| @@ -124,6 +132,7 @@ export function renderBlackjack( | |||
| 124 | ? node("button", "btn primary", label) | 132 | ? node("button", "btn primary", label) |
| 125 | : node("button", "btn", label); | 133 | : node("button", "btn", label); |
| 126 | button.addEventListener("click", () => { | 134 | button.addEventListener("click", () => { |
| 135 | if (!actionAllowed()) return; | ||
| 127 | if (action === "hit") send("Hit"); | 136 | if (action === "hit") send("Hit"); |
| 128 | else if (action === "stand") send("Stand"); | 137 | else if (action === "stand") send("Stand"); |
| 129 | else send("Double"); | 138 | else send("Double"); |
| @@ -133,12 +142,15 @@ export function renderBlackjack( | |||
| 133 | actions.append(actionsRow); | 142 | actions.append(actionsRow); |
| 134 | const forfeit = node("button", "btn danger wide", "Forfeit hand"); | 143 | const forfeit = node("button", "btn danger wide", "Forfeit hand"); |
| 135 | forfeit.addEventListener("click", () => { | 144 | forfeit.addEventListener("click", () => { |
| 145 | if (!actionAllowed()) return; | ||
| 136 | if (window.confirm("Forfeit this hand? The reserved bet is lost.")) send("Forfeit"); | 146 | if (window.confirm("Forfeit this hand? The reserved bet is lost.")) send("Forfeit"); |
| 137 | }); | 147 | }); |
| 138 | actions.append(forfeit); | 148 | actions.append(forfeit); |
| 139 | } else if (canDeal) { | 149 | } else if (canDeal) { |
| 140 | const deal = node("button", "btn primary wide big", "DEAL"); | 150 | const deal = node("button", "btn primary wide big", "DEAL"); |
| 141 | deal.addEventListener("click", () => send("Deal")); | 151 | deal.addEventListener("click", () => { |
| 152 | if (actionAllowed()) send("Deal"); | ||
| 153 | }); | ||
| 142 | actions.append(deal); | 154 | actions.append(deal); |
| 143 | } | 155 | } |
| 144 | 156 | ||
