그림 맞히기·클루: 그리기·차례 시간 무제한(출제자 정답 공개로 넘기기), 소리·움직임, 할리갈리·사과 게임 문서에 무제한
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/** 클루 화면 (docs/games/clue.md §9). */
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
|
||||
import type { ClueOptions, ClueView, SuggestionView } from '@bg/games/clue';
|
||||
import {
|
||||
PASSAGES,
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { haptic, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -55,12 +55,29 @@ const ro = (word: string) => {
|
||||
};
|
||||
const lastOf = <T,>(xs: readonly T[]): T | undefined => xs[xs.length - 1];
|
||||
|
||||
/** Clock length for the timer ring (무제한 has no deadline, so the ring only shows for away players' grace). */
|
||||
function totalMsOf(v: ClueView): number {
|
||||
if (v.phase.kind === 'refute') return 20_000;
|
||||
if ((v.idle[v.current] ?? 0) >= 3) return 10_000;
|
||||
return v.options.turnSeconds * 1000;
|
||||
return (v.options.turnSeconds ?? 60) * 1000;
|
||||
}
|
||||
|
||||
/** Game sounds on top of the shared palette (site volume applies). */
|
||||
const clSound = {
|
||||
/** "그건 바로…!" a suggestion is made: a low questioning motif. */
|
||||
suggest: () => [330, 392, 466].forEach((f, i) => tone(f, 150, 'triangle', 0.1, i * 110)),
|
||||
/** Nobody could show a card: a suspenseful low "dun-dun". */
|
||||
noneShown: () => {
|
||||
tone(196, 260, 'sawtooth', 0.05);
|
||||
tone(185, 420, 'sawtooth', 0.05, 280);
|
||||
},
|
||||
/** Walking a few squares in the hallway. */
|
||||
steps: (n: number) => {
|
||||
for (let i = 0; i < Math.min(4, n); i++) tone(i % 2 ? 520 : 440, 45, 'triangle', 0.09, i * 120);
|
||||
},
|
||||
};
|
||||
const posKey = (p: Pos) => JSON.stringify(p);
|
||||
|
||||
/** The player the game waits on (refuter while a card is being chosen). */
|
||||
const waitingOn = (v: ClueView): string => (v.phase.kind === 'refute' ? v.phase.refuter : v.current);
|
||||
|
||||
@@ -81,7 +98,7 @@ function knownCards(v: ClueView): Map<Item, string> {
|
||||
}
|
||||
|
||||
const CSS = `
|
||||
.cl-board { width: 100%; max-width: 1040px; max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px; }
|
||||
.cl-board { position: relative; width: 100%; max-width: 1040px; max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px; }
|
||||
.cl-top { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; align-items: start; }
|
||||
.cl-map { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(84px, auto));
|
||||
grid-template-areas: "k b c" "d m bi" "d m li" "lo h s"; gap: 6px; background: var(--wood); padding: 8px; border-radius: var(--radius-lg); box-shadow: var(--shadow); }
|
||||
@@ -133,7 +150,15 @@ button.cl-room:disabled { cursor: default; }
|
||||
button.cl-card { cursor: pointer; font: inherit; font-weight: 800; font-size: .8rem; }
|
||||
button.cl-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
|
||||
button.cl-card.can { box-shadow: 0 0 0 3px var(--primary); }
|
||||
.cl-card.new { animation: cl-pop .6s ease-out; }
|
||||
.cl-card.new { animation: cl-pop .6s ease-out; animation-delay: var(--anim-delay, 0ms); animation-fill-mode: both; }
|
||||
.cl-dice span { display: inline-block; }
|
||||
.cl-room.landed { animation: cl-land .7s ease-out; }
|
||||
.cl-banner { position: absolute; left: 50%; top: 30%; translate: -50% 0; z-index: 8; pointer-events: none; border-radius: 18px; padding: 12px 22px; font-weight: 900; font-size: 1.35rem;
|
||||
background: var(--surface); box-shadow: 0 10px 30px rgba(0,0,0,.35); text-align: center; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
|
||||
.cl-banner.ok { border: 4px solid var(--success); color: var(--success); }
|
||||
.cl-banner.bad { border: 4px solid var(--danger); color: var(--danger); }
|
||||
.cl-banner.info { border: 4px solid var(--primary); color: var(--text); }
|
||||
@keyframes cl-land { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--focus) 80%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
|
||||
@keyframes cl-pop { 0% { transform: scale(.6) rotate(-8deg); opacity: .2; } 100% { transform: none; opacity: 1; } }
|
||||
.cl-sec { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.cl-note { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
|
||||
@@ -166,20 +191,20 @@ button.cl-card.can { box-shadow: 0 0 0 3px var(--primary); }
|
||||
.cl-note { grid-template-columns: minmax(0, 1fr); }
|
||||
.cl-card { width: 66px; min-height: 78px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) { .cl-card.new { animation: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .cl-card.new, .cl-room.landed { animation: none; } }
|
||||
`;
|
||||
|
||||
// ---------------------------------------------------------------- small pieces
|
||||
|
||||
function Token({ x, me }: { x: Suspect; me?: boolean }) {
|
||||
function Token({ x, me, pop }: { x: Suspect; me?: boolean; pop?: boolean }) {
|
||||
return (
|
||||
<span className={`cl-tok${x === 'white' ? ' light' : ''}${me ? ' me' : ''}`} style={{ background: SUSPECT_COLOR[x] }} title={SUSPECT_KO[x]} aria-hidden>
|
||||
<span className={`cl-tok${x === 'white' ? ' light' : ''}${me ? ' me' : ''}${pop ? ' anim-pop' : ''}`} style={{ background: SUSPECT_COLOR[x] }} title={SUSPECT_KO[x]} aria-hidden>
|
||||
{SUSPECT_SHORT[x]}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ id, onClick, can, fresh, label }: { id: string; onClick?: () => void; can?: boolean; fresh?: boolean; label?: string }) {
|
||||
function Card({ id, onClick, can, fresh, label, delay }: { id: string; onClick?: () => void; can?: boolean; fresh?: boolean; label?: string; delay?: number }) {
|
||||
const x = itemOf(id);
|
||||
const cat = categoryOf(x);
|
||||
const body = (
|
||||
@@ -199,7 +224,7 @@ function Card({ id, onClick, can, fresh, label }: { id: string; onClick?: () =>
|
||||
</button>
|
||||
);
|
||||
return (
|
||||
<span className={`cl-card${fresh ? ' new' : ''}`} role="img" aria-label={aria}>
|
||||
<span className={`cl-card${fresh ? ' new' : ''}`} role="img" aria-label={aria} style={delay ? ({ '--anim-delay': `${delay}ms` } as CSSProperties) : undefined}>
|
||||
{body}
|
||||
</span>
|
||||
);
|
||||
@@ -214,9 +239,67 @@ function ClueBoard({ view: v, me, players, act, pending }: BoardProps<ClueView>)
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const prevTurn = useRef(`${v.current}|${v.turnNo}`);
|
||||
const prevSg = useRef(JSON.stringify(lastOf(v.suggestions) ?? null));
|
||||
const prevView = useRef(v);
|
||||
const [banner, setBanner] = useState<{ key: string; kind: 'ok' | 'bad' | 'info'; text: string } | null>(null);
|
||||
const [landed, setLanded] = useState<{ room: Room; key: number } | null>(null);
|
||||
|
||||
useEffect(() => setSel(null), [v.phase.kind, v.current, v.turnNo]);
|
||||
|
||||
// Sounds and highlights for what anyone just did: dice, moves, passages, suggestions, answers, accusations.
|
||||
useEffect(() => {
|
||||
const p = prevView.current;
|
||||
prevView.current = v;
|
||||
if (p === v) return;
|
||||
if (v.dice && (!p.dice || p.turnNo !== v.turnNo || p.dice[0] !== v.dice[0] || p.dice[1] !== v.dice[1])) sfx.dice();
|
||||
const mover = v.suspectOf[v.current];
|
||||
let moved = false;
|
||||
for (const x of SUSPECTS) {
|
||||
if (posKey(v.pos[x]) === posKey(p.pos[x])) continue;
|
||||
moved = true;
|
||||
const r = roomAt(v.pos[x]);
|
||||
if (r && x === mover) setLanded({ room: r, key: Date.now() });
|
||||
}
|
||||
const sgNew = v.suggestions.length > p.suggestions.length;
|
||||
if (moved && !sgNew && mover) {
|
||||
const from = roomAt(p.pos[mover]);
|
||||
const to = roomAt(v.pos[mover]);
|
||||
if (from && to && PASSAGES[from] === to && !v.dice) sfx.whoosh();
|
||||
else if (to) sfx.piece();
|
||||
else clSound.steps(v.dice ? v.dice[0] + v.dice[1] : 3);
|
||||
}
|
||||
if (sgNew) clSound.suggest();
|
||||
const lastNow = lastOf(v.suggestions);
|
||||
const lastPrev = lastOf(p.suggestions);
|
||||
if (lastNow && !sgNew && lastPrev && v.suggestions.length === p.suggestions.length && !lastPrev.refuter && lastNow.refuter) {
|
||||
if (lastNow.shown && (lastNow.by === me || lastNow.refuter === me)) sfx.cardFlip();
|
||||
else sfx.cardDeal();
|
||||
}
|
||||
if (lastNow && p.phase.kind === 'refute' && v.phase.kind !== 'refute' && !lastNow.refuter) clSound.noneShown();
|
||||
if (lastNow && sgNew && v.phase.kind === 'afterSuggest' && !lastNow.refuter) clSound.noneShown();
|
||||
if (v.accusations.length > p.accusations.length) {
|
||||
const a = v.accusations[v.accusations.length - 1]!;
|
||||
const who = a.by === me ? '내' : `${nick(players, a.by)}님의`;
|
||||
if (a.correct) {
|
||||
sfx.fanfare();
|
||||
setBanner({ key: `a${v.accusations.length}`, kind: 'ok', text: `⚖️ ${who} 고발이 맞았어요!` });
|
||||
} else {
|
||||
sfx.bad();
|
||||
setBanner({ key: `a${v.accusations.length}`, kind: 'bad', text: `⚖️ ${who} 고발이 틀렸어요 · 탈락` });
|
||||
}
|
||||
}
|
||||
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
if (!banner) return;
|
||||
const t = setTimeout(() => setBanner(null), 1700);
|
||||
return () => clearTimeout(t);
|
||||
}, [banner]);
|
||||
useEffect(() => {
|
||||
if (!landed) return;
|
||||
const t = setTimeout(() => setLanded(null), 800);
|
||||
return () => clearTimeout(t);
|
||||
}, [landed]);
|
||||
|
||||
useEffect(() => {
|
||||
const key = `${v.current}|${v.turnNo}`;
|
||||
if (key !== prevTurn.current && v.phase.kind !== 'finished') {
|
||||
@@ -250,11 +333,16 @@ function ClueBoard({ view: v, me, players, act, pending }: BoardProps<ClueView>)
|
||||
<div className="cl-board" role="region" aria-label="클루 판">
|
||||
<style>{CSS}</style>
|
||||
<div className="cl-top">
|
||||
<Mansion view={v} me={me} myTurn={myTurn && !pending} sel={sel} setSel={setSel} />
|
||||
<Mansion view={v} me={me} myTurn={myTurn && !pending} sel={sel} setSel={setSel} landed={landed?.room ?? null} />
|
||||
<ActionPanel view={v} me={me} players={players} act={act} pending={pending} myTurn={myTurn} sel={sel} setSel={setSel} />
|
||||
</div>
|
||||
{amPlayer && <MyCards view={v} me={me!} />}
|
||||
{amPlayer && <Notebook view={v} me={me!} players={players} />}
|
||||
{banner && (
|
||||
<div key={banner.key} className={`cl-banner anim-banner ${banner.kind}`} aria-hidden>
|
||||
{banner.text}
|
||||
</div>
|
||||
)}
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
@@ -262,7 +350,21 @@ function ClueBoard({ view: v, me, players, act, pending }: BoardProps<ClueView>)
|
||||
);
|
||||
}
|
||||
|
||||
function Mansion({ view: v, me, myTurn, sel, setSel }: { view: ClueView; me: string | null; myTurn: boolean; sel: Room | null; setSel: (r: Room | null) => void }) {
|
||||
function Mansion({
|
||||
view: v,
|
||||
me,
|
||||
myTurn,
|
||||
sel,
|
||||
setSel,
|
||||
landed,
|
||||
}: {
|
||||
view: ClueView;
|
||||
me: string | null;
|
||||
myTurn: boolean;
|
||||
sel: Room | null;
|
||||
setSel: (r: Room | null) => void;
|
||||
landed: Room | null;
|
||||
}) {
|
||||
const mySuspect = me ? v.suspectOf[me] : undefined;
|
||||
const myPos = mySuspect ? v.pos[mySuspect] : null;
|
||||
const here = myPos ? roomAt(myPos) : null;
|
||||
@@ -282,7 +384,7 @@ function Mansion({ view: v, me, myTurn, sel, setSel }: { view: ClueView; me: str
|
||||
const can = picking && r !== here;
|
||||
const reach = can && (free || (d !== undefined && d <= sum));
|
||||
const pass = PASSAGES[r];
|
||||
const cls = ['cl-room', can ? (reach ? 'reach' : 'far') : '', sel === r ? 'sel' : '', r === here ? 'here' : ''].filter(Boolean).join(' ');
|
||||
const cls = ['cl-room', can ? (reach ? 'reach' : 'far') : '', sel === r ? 'sel' : '', r === here ? 'here' : '', landed === r ? 'landed' : ''].filter(Boolean).join(' ');
|
||||
const label = [
|
||||
ROOM_KO[r],
|
||||
r === here ? '내가 있는 방' : '',
|
||||
@@ -302,10 +404,10 @@ function Mansion({ view: v, me, myTurn, sel, setSel }: { view: ClueView; me: str
|
||||
{can && !free && d !== undefined && <span className="cl-dist">{d}칸</span>}
|
||||
<span className="cl-things">
|
||||
{toks.map((x) => (
|
||||
<Token key={x} x={x} me={x === mySuspect} />
|
||||
<Token key={x} x={x} me={x === mySuspect} pop />
|
||||
))}
|
||||
{weaps.map((w) => (
|
||||
<span key={w} className="cl-weap" title={WEAPON_KO[w]} aria-hidden>
|
||||
<span key={w} className="cl-weap anim-pop" title={WEAPON_KO[w]} aria-hidden>
|
||||
{WEAPON_ICON[w]}
|
||||
</span>
|
||||
))}
|
||||
@@ -337,7 +439,7 @@ function Mansion({ view: v, me, myTurn, sel, setSel }: { view: ClueView; me: str
|
||||
const p = owner(x);
|
||||
return (
|
||||
<li key={x} style={p ? undefined : { opacity: 0.6 }} aria-label={`${SUSPECT_KO[x]}${p ? '' : '(맡은 사람 없음)'}: ${hallwayText(v.pos[x])}`}>
|
||||
<Token x={x} me={x === mySuspect} />
|
||||
<Token key={posKey(v.pos[x])} x={x} me={x === mySuspect} pop />
|
||||
<span aria-hidden>{hallwayText(v.pos[x])}</span>
|
||||
</li>
|
||||
);
|
||||
@@ -500,8 +602,8 @@ function ActionPanel({
|
||||
<span>{v.final?.summary}</span>
|
||||
{v.solution && (
|
||||
<div className="cl-cards" aria-label="사건 봉투 속 정답">
|
||||
{[v.solution.suspect, v.solution.weapon, v.solution.room].map((x) => (
|
||||
<Card key={x} id={`card-${x}`} fresh />
|
||||
{[v.solution.suspect, v.solution.weapon, v.solution.room].map((x, i) => (
|
||||
<Card key={x} id={`card-${x}`} fresh delay={i * 250} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
@@ -517,7 +619,7 @@ function ActionPanel({
|
||||
<strong>
|
||||
{nick(players, sg.by)}님이 {ro(triple(sg))} 추리했어요
|
||||
</strong>
|
||||
<span className="small muted">내 카드 중 하나를 골라 {nick(players, sg.by)}님에게만 보여 줘요. 다른 사람은 내가 보여 줬다는 것만 알아요. 20초 안에 안 고르면 자동으로 보여 줘요.</span>
|
||||
<span className="small muted">내 카드 중 하나를 골라 {nick(players, sg.by)}님에게만 보여 줘요. 다른 사람은 내가 보여 줬다는 것만 알아요.{v.options.turnSeconds === null ? '' : ' 20초 안에 안 고르면 자동으로 보여 줘요.'}</span>
|
||||
<div className="cl-cards">
|
||||
{(ph.canShow ?? []).map((c) => (
|
||||
<Card key={c} id={c} can onClick={() => !pending && act({ type: 'show', card: c })} label={`${ITEM_KO[itemOf(c)]} 카드 보여 주기`} />
|
||||
@@ -616,8 +718,12 @@ function ActionPanel({
|
||||
<div className="cl-panel">
|
||||
{v.dice && (
|
||||
<div className="cl-dice" role="img" aria-label={`주사위 ${v.dice[0]}과 ${v.dice[1]}, 합 ${sum}`}>
|
||||
<span aria-hidden>{DICE[v.dice[0]]}</span>
|
||||
<span aria-hidden>{DICE[v.dice[1]]}</span>
|
||||
<span key={`a${v.turnNo}-${v.dice[0]}`} className="anim-roll" aria-hidden>
|
||||
{DICE[v.dice[0]]}
|
||||
</span>
|
||||
<span key={`b${v.turnNo}-${v.dice[1]}`} className="anim-roll" style={{ animationDelay: '80ms' }} aria-hidden>
|
||||
{DICE[v.dice[1]]}
|
||||
</span>
|
||||
<b aria-hidden>= {sum}칸</b>
|
||||
</div>
|
||||
)}
|
||||
@@ -876,7 +982,7 @@ function statusText(v: ClueView, me: string | null, players: Record<string, Publ
|
||||
|
||||
// ---------------------------------------------------------------- options
|
||||
|
||||
function Seg<T extends string | number>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
||||
function Seg<T extends string | number | null>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
||||
return (
|
||||
<div className="segmented" role="group" aria-label={label}>
|
||||
{options.map(([k, l]) => (
|
||||
@@ -914,16 +1020,18 @@ function Options({ value: o, onChange }: OptionsProps<ClueOptions>) {
|
||||
[45, '45초'],
|
||||
[60, '60초'],
|
||||
[90, '90초'],
|
||||
[null, '무제한'],
|
||||
]}
|
||||
onChange={(turnSeconds) => set({ turnSeconds })}
|
||||
/>
|
||||
{o.turnSeconds === null && <span className="small muted">차례와 카드 보여 주기에 시간 제한이 없어요. 연결이 끊긴 채 돌아오지 않는 사람만 자동으로 넘겨요.</span>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function optionsSummary(o: ClueOptions): string {
|
||||
return [o.movement === 'free' ? '빠른 이동' : '주사위 이동', `차례 ${o.turnSeconds}초`].join(' · ');
|
||||
return [o.movement === 'free' ? '빠른 이동' : '주사위 이동', o.turnSeconds === null ? '차례 시간 무제한' : `차례 ${o.turnSeconds}초`].join(' · ');
|
||||
}
|
||||
|
||||
function Rules({ options }: { options?: ClueOptions }) {
|
||||
@@ -956,7 +1064,10 @@ function Rules({ options }: { options?: ClueOptions }) {
|
||||
<strong>추리 노트</strong>: 화면 아래 노트에 내 카드, 공개 카드, 나에게 보여 준 카드가 자동으로 ✗ 표시돼요. 나머지는 직접 눌러 ✗·?·✓를 적어 두세요(이 기기에만 저장돼요).
|
||||
</p>
|
||||
<p className="muted">
|
||||
차례 시간이 지나면 가까운 방으로 움직이고 추리 없이 차례가 넘어가요. 카드를 보여 줄 때는 20초 안에 고르지 않으면 맞는 카드가 자동으로 보여져요. 게임 중에 나간 사람의 카드는 모두에게 공개돼요.
|
||||
{options?.turnSeconds === null
|
||||
? '이 방은 차례 시간이 무제한이에요. 연결이 끊긴 채 돌아오지 않으면 가까운 방으로 움직이고 추리 없이 차례가 넘어가요(카드 보여 주기는 맞는 카드가 자동으로).'
|
||||
: '차례 시간이 지나면 가까운 방으로 움직이고 추리 없이 차례가 넘어가요. 카드를 보여 줄 때는 20초 안에 고르지 않으면 맞는 카드가 자동으로 보여져요.'}{' '}
|
||||
게임 중에 나간 사람의 카드는 모두에게 공개돼요.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user