From d3b31c86a164cc3f7eac3f5735b564373910454f Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 8 Mar 2026 12:03:10 -0400 Subject: [PATCH] anagrams: Display words and letters being claimed by another player This allows other players to be a part of the action, (and even try to predict what the final word will be while a claim is happening). --- anagrams/anagrams.css | 14 +++++----- anagrams/anagrams.jsx | 59 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/anagrams/anagrams.css b/anagrams/anagrams.css index fb7f2da..5ab18cc 100644 --- a/anagrams/anagrams.css +++ b/anagrams/anagrams.css @@ -329,12 +329,10 @@ color: #555; } -/* Notification for claim activity */ -.claim-notification { - background: #fff3cd; - border: 1px solid #ffc107; - border-radius: 4px; - padding: 0.5em 1em; - margin-bottom: 1em; - font-size: 0.95em; + +.claim-items-display { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 2px; } diff --git a/anagrams/anagrams.jsx b/anagrams/anagrams.jsx index 13e3fb3..8fac388 100644 --- a/anagrams/anagrams.jsx +++ b/anagrams/anagrams.jsx @@ -115,6 +115,8 @@ class Game extends React.Component { claim_player: null, /* name of the current claimer */ claim_rack: [], /* tiles I've claimed (in my order) */ claimed_words: [], /* word objects I've stolen */ + other_claim_letters: [], /* letters claimed by another player */ + other_claim_words: [], /* words stolen by another player */ claim_error: null, claim_warning: false, claim_remaining_ms: 0, @@ -256,6 +258,8 @@ class Game extends React.Component { claiming: is_me, claim_rack: is_me ? [] : this.state.claim_rack, claimed_words: is_me ? [] : this.state.claimed_words, + other_claim_letters: is_me ? [] : (data.claimed_letters || []), + other_claim_words: is_me ? [] : (data.claimed_words || []), claim_error: null, claim_warning: false, claim_remaining_ms: data.timeout_ms @@ -285,6 +289,8 @@ class Game extends React.Component { claiming: false, claim_rack: [], claimed_words: [], + other_claim_letters: [], + other_claim_words: [], claim_error: null, claim_warning: false, claim_remaining_ms: 0 @@ -293,14 +299,15 @@ class Game extends React.Component { } receive_letter_claimed(data) { - /* Remove from center. */ this.setState(prev => ({ - center: prev.center.filter(t => t.id !== data.tile.id) + center: prev.center.filter(t => t.id !== data.tile.id), + other_claim_letters: prev.claim_active + ? prev.other_claim_letters + : [...prev.other_claim_letters, data.tile] })); } receive_letter_returned(data) { - /* Add back to center. */ this.setState(prev => { const positions = { ...prev.tile_positions }; if (!positions[data.tile.id]) { @@ -308,17 +315,31 @@ class Game extends React.Component { } return { center: [...prev.center, data.tile], - tile_positions: positions + tile_positions: positions, + other_claim_letters: prev.other_claim_letters.filter( + t => t.id !== data.tile.id) }; }); } receive_word_stolen(data) { /* Player words update will come via player-words event. */ + if (!this.state.claim_active) { + this.setState(prev => ({ + other_claim_words: [...prev.other_claim_words, + { word: data.word, word_id: data.word_id }] + })); + } } receive_word_returned(data) { /* Player words update will come via player-words event. */ + if (!this.state.claim_active) { + this.setState(prev => ({ + other_claim_words: prev.other_claim_words.filter( + w => w.word_id !== data.word_id) + })); + } } receive_word_accepted(data) { @@ -812,8 +833,34 @@ class Game extends React.Component { state.joined ? this.render_controls() : null, state.claim_player && !state.claim_active ? ( -
- {state.claim_player} is forming a word... +
+

{state.claim_player} is forming a word:

+ {state.other_claim_words.length > 0 + || state.other_claim_letters.length > 0 ? ( +
+ {state.other_claim_words + .slice().sort((a, b) => b.word.length - a.word.length) + .map((cw, i) => [ + i > 0 ? + : null, + + {cw.word.split("").map((ch, j) => ( + + ))} + + ])} + {state.other_claim_letters + .slice().sort((a, b) => a.letter.localeCompare(b.letter)) + .map((tile, i) => [ + (i > 0 || state.other_claim_words.length > 0) + ? + : null, + + + + ])} +
+ ) : null}
) : null, -- 2.45.2