solitaire: detect a won board and finish it in one press
A drained, all-face-up board is a guaranteed clear that auto() sweeps home in a single cascade, but the only way to trigger it was double-clicking thirty cards home by hand. Add State.Won(), surface it in the view, and swap the ordinary controls for one pulsing finish button when it's true.
This commit is contained in:
@@ -44,7 +44,10 @@
|
||||
|
||||
var playing = root.querySelector("[data-playing]");
|
||||
var betting = root.querySelector("[data-betting]");
|
||||
var playControls = root.querySelector("[data-play-controls]");
|
||||
var wonControls = root.querySelector("[data-won-controls]");
|
||||
var autoBtn = root.querySelector("[data-auto]");
|
||||
var finishBtn = root.querySelector("[data-finish]");
|
||||
var cashBtn = root.querySelector("[data-cash]");
|
||||
var cashAmountEl = root.querySelector("[data-cash-amount]");
|
||||
var startBtn = root.querySelector("[data-start]");
|
||||
@@ -258,6 +261,11 @@
|
||||
playing.classList.toggle("hidden", !live);
|
||||
betting.classList.toggle("hidden", live);
|
||||
if (!live) return;
|
||||
// A won board has nothing left to decide, so the ordinary controls step aside
|
||||
// for the one button that finishes it.
|
||||
var won = !!v.won;
|
||||
wonControls.classList.toggle("hidden", !won);
|
||||
playControls.classList.toggle("hidden", won);
|
||||
autoBtn.disabled = !v.can_auto;
|
||||
cashAmountEl.textContent = (v.stands || 0).toLocaleString();
|
||||
}
|
||||
@@ -545,6 +553,10 @@
|
||||
|
||||
autoBtn.addEventListener("click", function () { drop(); send({ kind: "auto" }); });
|
||||
|
||||
// The finish button. On a won board a single auto drains every card home in one
|
||||
// cascade, and the board settles cleared on the far end of it.
|
||||
finishBtn.addEventListener("click", function () { drop(); send({ kind: "auto" }); });
|
||||
|
||||
cashBtn.addEventListener("click", function () {
|
||||
drop();
|
||||
send({ kind: "concede" });
|
||||
|
||||
Reference in New Issue
Block a user