summaryrefslogtreecommitdiffstats
path: root/web/play/src/blackjack.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/play/src/blackjack.ts')
-rw-r--r--web/play/src/blackjack.ts58
1 files changed, 34 insertions, 24 deletions
diff --git a/web/play/src/blackjack.ts b/web/play/src/blackjack.ts
index 49d46fa..3288244 100644
--- a/web/play/src/blackjack.ts
+++ b/web/play/src/blackjack.ts
@@ -24,12 +24,11 @@ function cardElement(card: string): HTMLElement {
24 24
25function handBlock(label: string, cards: string[], total: number): HTMLElement { 25function handBlock(label: string, cards: string[], total: number): HTMLElement {
26 const block = node("div", "hand"); 26 const block = node("div", "hand");
27 block.append(node("div", "label", label)); 27 const head = node("div", "hand-head");
28 head.append(node("span", "label", label), node("strong", "total", String(total)));
28 const row = node("div", "cards"); 29 const row = node("div", "cards");
29 for (const card of cards) row.append(cardElement(card)); 30 for (const card of cards) row.append(cardElement(card));
30 const sum = node("div", "total"); 31 block.append(head, row);
31 sum.append(document.createTextNode("Total "), node("strong", undefined, String(total)));
32 block.append(row, sum);
33 return block; 32 return block;
34} 33}
35 34
@@ -70,36 +69,31 @@ export function renderBlackjack(
70 const done = hand?.phase === "done" || view.status === "done"; 69 const done = hand?.phase === "done" || view.status === "done";
71 const canDeal = !hand || done; 70 const canDeal = !hand || done;
72 71
73 board.append(node("h2", undefined, "Blackjack")); 72 const table = node("div", "bj-table");
74 board.append(
75 node("p", "note", "Six decks. Dealer stands on all 17. Blackjack pays 3:2."),
76 );
77
78 if (hand) { 73 if (hand) {
79 board.append(handBlock("Dealer", hand.dealer ?? [], Number(hand.dealer_total ?? 0))); 74 table.append(handBlock("DEALER", hand.dealer ?? [], Number(hand.dealer_total ?? 0)));
80 board.append(handBlock("You", hand.player ?? [], Number(hand.player_total ?? 0))); 75 table.append(node("div", "bj-divider"));
76 table.append(handBlock("YOU", hand.player ?? [], Number(hand.player_total ?? 0)));
81 } else { 77 } else {
82 const empty = node("div", "outcome"); 78 const empty = node("div", "empty-table", "Place a bet and deal a hand.");
83 empty.textContent = "Press DEAL to start a hand."; 79 table.append(empty);
84 board.append(empty);
85 } 80 }
81 board.append(table);
86 82
87 if (done || (hand && !playerPhase)) { 83 const foot = node("div", "board-foot");
88 const result = node("div", "outcome"); 84 foot.append(
89 result.textContent = outcome(view, hand); 85 node("span", "label", "Hand"),
90 if (String(hand?.result) === "win" || String(hand?.result) === "blackjack" || String(hand?.result) === "push") { 86 node("span", undefined, hand ? outcome(view, hand) : "Waiting"),
91 result.classList.add("win-text"); 87 );
92 } 88 board.append(foot);
93 board.append(result);
94 }
95 89
96 if (view.error) board.append(node("p", "error-text", String(view.error))); 90 if (view.error) board.append(node("p", "error-text", String(view.error)));
97 91
98 // Sidebar 92 // Sidebar
99 side.append(node("div", "label", "Blackjack")); 93 side.append(node("h2", undefined, "Blackjack"));
100 const bet = Number(hand?.bet ?? view.bet ?? 0); 94 const bet = Number(hand?.bet ?? view.bet ?? 0);
101 const balance = view.balance ?? view.hand?.balance; 95 const balance = view.balance ?? view.hand?.balance;
102 side.append(node("p", "note", "Hit, stand or double. Forfeiting loses the reserved bet.")); 96 side.append(node("p", "note", "Get closer to 21 without going over."));
103 97
104 if (canDeal) { 98 if (canDeal) {
105 const betRow = node("div", "row"); 99 const betRow = node("div", "row");
@@ -122,6 +116,22 @@ export function renderBlackjack(
122 side.append(stat); 116 side.append(stat);
123 } 117 }
124 118
119 if (done || (hand && !playerPhase)) {
120 const resultLine = node("p", "note win-text");
121 resultLine.textContent = `${String(hand?.result ?? "").toUpperCase()} ${money(Number(hand?.winnings ?? 0))}`;
122 if (!["win", "blackjack", "push"].includes(String(hand?.result))) {
123 resultLine.className = "note";
124 }
125 side.append(resultLine);
126 } else if (playerPhase) {
127 const actionsText = (hand?.actions ?? []).includes("double")
128 ? "Hit, stand or double."
129 : "Hit or stand.";
130 side.append(node("p", "note", actionsText));
131 } else if (!hand) {
132 side.append(node("p", "note", "Press DEAL to start a hand."));
133 }
134
125 const actions = node("div", "actions"); 135 const actions = node("div", "actions");
126 if (playerPhase) { 136 if (playerPhase) {
127 const actionsRow = node("div", "row wrap"); 137 const actionsRow = node("div", "row wrap");