그림 맞히기·클루: 그리기·차례 시간 무제한(출제자 정답 공개로 넘기기), 소리·움직임, 할리갈리·사과 게임 문서에 무제한

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:01:42 +09:00
parent bafbf95d98
commit b8966db2a6
15 changed files with 413 additions and 84 deletions

View File

@@ -57,3 +57,13 @@ test('그림 맞히기: 공개 / 끝', () => {
s.final = { ranking: [], turns: [], summary: '호랑이님 우승!' };
expect(helpNow(view(s, null), null, users)).toContain('호랑이님 우승!');
});
test('그림 맞히기: 그리기 무제한이면 출제자에게 정답 공개 안내', async () => {
const { setupGame, usersOf } = await import('../help-kit.test-util');
const { GAMES } = await import('@bg/games');
const users = usersOf(['A', 'B', 'C']);
const { state } = setupGame('catchmind', 3, { drawSeconds: null, wordChoice: false });
const d: string = state.turn.drawer;
const t = helpNow(GAMES.catchmind!.view(state, d) as never, d, users);
expect(t).toContain('[정답 공개하고 넘기기]');
});

View File

@@ -32,7 +32,7 @@ export function helpNow(v: CatchmindView, me: string | null, players: Record<str
}
const word = v.word ? `그릴 단어는 "${v.word}"예요(나와 맞힌 사람만 보여요). ` : '';
const report = v.options.letterReport ? ' 글자를 쓰면 신고를 받아 0점이 될 수 있어요.' : '';
return `${word}그림판에 손가락이나 마우스로 그려요. 아래 버튼으로 색, 굵기, 지우개(🧽), 되돌리기(↶), 전체 지우기(🗑)를 쓸 수 있어요.\n글자나 숫자는 쓰지 말고 그림으로만 설명해요.${report}\n그리는 동안 채팅은 못 하고 [거의 다 왔어요]·[비슷해요]·[아니에요] 반응 버튼만 보낼 수 있어요.`;
return `${word}그림판에 손가락이나 마우스로 그려요. 아래 버튼으로 색, 굵기, 지우개(🧽), 되돌리기(↶), 전체 지우기(🗑)를 쓸 수 있어요.\n글자나 숫자는 쓰지 말고 그림으로만 설명해요.${report}\n그리는 동안 채팅은 못 하고 [거의 다 왔어요]·[비슷해요]·[아니에요] 반응 버튼만 보낼 수 있어요.${v.endsAt === null ? '\n그리기 시간은 무제한이에요. 아무도 못 맞히면 [정답 공개하고 넘기기]를 두 번 눌러 넘겨요.' : ''}`;
}
// guesser / solver
if (v.phase === 'choosing') return `${turn} · ${drawer}이 그릴 단어를 고르고 있어요. 그림이 시작되면 보고 정답을 입력해요.${v.canChat ? ' 지금은 채팅만 할 수 있어요.' : ''}${away}`;

View File

@@ -5,7 +5,7 @@ import type { PublicUser, ServerMessage } from '@bg/shared/lite';
import { nameHue } from '../../components/ChatMessage';
import { Avatar } from '../../components/ui';
import { useServerNow } from '../../components/TurnTimer';
import { haptic, sounds } from '../../lib/feedback';
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
import { useWide } from '../../lib/media';
import { socket } from '../../net/socket';
import type { BoardProps, GameUI, OptionsProps } from '../types';
@@ -70,6 +70,23 @@ const CHAT_MAX = 100;
const nick = (players: Record<string, PublicUser>, id: string) => players[id]?.nickname ?? '나간 사람';
const userOf = (players: Record<string, PublicUser>, id: string): PublicUser => players[id] ?? { id, nickname: '나간 사람', avatar: null, kind: 'guest' };
/** Game sounds on top of the shared palette (site volume applies). */
const cmSound = {
/** Pencil touching the paper (drawer's own strokes only). */
scribble: () => noise(50, 0.05, 0, 'highpass', 4500),
/** A hint letter turned over. */
hint: () => {
tone(880, 70, 'triangle', 0.1);
tone(1320, 110, 'triangle', 0.08, 60);
},
/** Somebody else got it. */
otherCorrect: () => tone(1175, 120, 'triangle', 0.1),
/** "아까워요!" (only the sender sees it). */
close: () => tone(700, 90, 'triangle', 0.1, 0, { slideTo: 600 }),
/** The drawer's reaction button (heard by the guessers). */
react: () => tone(990, 60, 'sine', 0.08),
};
const CSS = `
.cm { width: 100%; max-width: 1100px; display: flex; flex-direction: column; gap: 8px; align-self: center; }
.cm-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: space-between; font-weight: 700; }
@@ -139,6 +156,12 @@ const CSS = `
.cm-form { display: flex; gap: 6px; }
.cm-form .input { flex: 1; min-height: 48px; font-size: 1.05rem; }
.cm-close { color: var(--warning); font-weight: 900; font-size: .95rem; animation: cm-shake .4s ease; }
.cm-over { animation: fade .25s ease both; }
.cm-over .word { animation: cm-word .5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: .1s; }
.cm-hint .ch.flip { animation: anim-flip .42s ease both; }
.cm-strip .p .sc, .cm-score strong { display: inline-block; }
.cm-unl { font-weight: 800; color: var(--text-sub); font-size: .92rem; }
@keyframes cm-word { from { transform: scale(.3) rotate(-6deg); opacity: 0; } }
.cm-away { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; background: var(--warning-soft); color: var(--text); border-radius: 12px; padding: 8px 12px; }
@keyframes cm-pop { 0% { transform: translate(-50%, -50%) scale(.5); opacity: 0; } 70% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); } }
@keyframes cm-shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@@ -156,7 +179,7 @@ const CSS = `
.cm-hint .ch { min-width: 34px; height: 40px; font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) {
.cm-pop, .cm-close { animation: none; }
.cm-pop, .cm-close, .cm-over, .cm-over .word, .cm-hint .ch.flip { animation: none; }
.cm-bar i { transition: none; }
}
`;
@@ -507,6 +530,7 @@ function Paper({ v, me, act, players }: { v: CatchmindView; me: string | null; a
sender.begin(t.c, t.w, ex, x, y);
drawing.apply({ k: 'b', s: sender.stroke, c: t.c, w: t.w, e: ex });
drawing.addPoint(x, y);
cmSound.scribble();
};
const onMove = (e: React.PointerEvent<HTMLCanvasElement>) => {
if (active.current !== e.pointerId) return;
@@ -606,6 +630,7 @@ function Paper({ v, me, act, players }: { v: CatchmindView; me: string | null; a
</button>
))}
</div>
{v.options.drawSeconds === null && <GiveUp act={act} />}
{!wide && <span className="small muted">그리는 동안에는 채팅 대신 반응 버튼만 쓸 수 있어요.</span>}
</div>
)}
@@ -613,6 +638,29 @@ function Paper({ v, me, act, players }: { v: CatchmindView; me: string | null; a
);
}
/** 무제한 drawings: the drawer may open the answer (press twice). */
function GiveUp({ act }: { act: (a: unknown) => void }) {
const [ask, setAsk] = useState(false);
useEffect(() => {
if (!ask) return;
const t = setTimeout(() => setAsk(false), 3000);
return () => clearTimeout(t);
}, [ask]);
return (
<button
type="button"
className={`btn ${ask ? 'btn-primary' : 'btn-ghost'} btn-sm`}
onClick={() => {
if (!ask) return setAsk(true);
setAsk(false);
act({ type: 'giveUp' });
}}
>
{ask ? '한 번 더 누르면 정답을 공개해요' : '🏳 정답 공개하고 넘기기'}
</button>
);
}
const END_TEXT: Record<TurnEndReason, string> = {
time: '시간이 다 됐어요',
allSolved: '모두 맞혔어요!',
@@ -620,6 +668,7 @@ const END_TEXT: Record<TurnEndReason, string> = {
report: '글자를 썼다는 신고로 끝났어요(출제자 0점)',
drawerAway: '출제자의 연결이 끊겼어요',
drawerLeft: '출제자가 나갔어요',
giveUp: '출제자가 정답을 공개했어요',
};
function Overlay({ v, me, act, players, onSave }: { v: CatchmindView; me: string | null; act: (a: unknown) => void; players: Record<string, PublicUser>; onSave: () => void }) {
@@ -663,7 +712,12 @@ function OverlayMain({ v, act, players, onSave }: { v: CatchmindView; act: (a: u
<h2>그릴 단어를 골라 주세요</h2>
<div className="cm-choices">
{v.choices.map((c, i) => (
<button key={c.word} type="button" className="btn btn-primary" onClick={() => act({ type: 'chooseWord', index: i })} aria-label={`${c.word} (${CATEGORY_KO[c.category]})`}>
<button
key={c.word}
type="button"
className="btn btn-primary anim-deal"
style={{ '--anim-delay': `${i * 90}ms` } as CSSProperties}
onClick={() => act({ type: 'chooseWord', index: i })} aria-label={`${c.word} (${CATEGORY_KO[c.category]})`}>
<span className="ic" aria-hidden>
{CATEGORY_ICON[c.category]}
</span>
@@ -721,7 +775,7 @@ function HintRow({ v }: { v: CatchmindView }) {
{hint ? (
<span role="text" aria-label={`힌트: ${hint.filter((c) => c !== ' ').length}글자, ${hint.map((c) => (c === '○' ? '빈칸' : c === ' ' ? '띄어쓰기' : c)).join(' ')}`} style={{ display: 'inline-flex', gap: 6, flexWrap: 'wrap', justifyContent: 'center' }}>
{hint.map((c, i) => (
<span key={i} className={`ch${c === ' ' ? ' sp' : ''}${c !== '○' && c !== ' ' && !/^[ㄱ-ㅎ]$/.test(c) ? ' open' : ''}`} aria-hidden>
<span key={`${i}-${c}`} className={`ch${c === ' ' ? ' sp' : ''}${c !== '○' && c !== ' ' && !/^[ㄱ-ㅎ]$/.test(c) ? ' open' : ''}${c !== '○' && c !== ' ' && v.phase === 'drawing' ? ' flip' : ''}`} aria-hidden>
{c === ' ' ? '' : c}
</span>
))}
@@ -736,7 +790,21 @@ function HintRow({ v }: { v: CatchmindView }) {
function TimeBar({ v }: { v: CatchmindView }) {
const now = useServerNow(250);
// Ticks in the last 10 seconds of the drawing.
const lastSec = v.phase === 'drawing' && v.endsAt !== null ? Math.ceil(Math.max(0, v.endsAt - now) / 1000) : 0;
const ticked = useRef(0);
useEffect(() => {
if (lastSec > 0 && lastSec <= 10 && lastSec !== ticked.current) sfx.tick();
ticked.current = lastSec;
}, [lastSec]);
if (v.phase === 'ended') return null;
if (v.endsAt === null || v.phaseMs === null) {
return (
<div className="cm-unl" role="status">
⏱ 그리기 시간 무제한 · {v.options.guessMode === 'multi' ? '모두 맞히거나' : '누가 맞히거나'} 출제자가 정답을 공개할 때까지
</div>
);
}
const left = Math.max(0, v.endsAt - now);
const frac = Math.min(1, left / Math.max(1, v.phaseMs));
const sec = Math.ceil(left / 1000);
@@ -777,7 +845,7 @@ function ScoreStrip({ v, me, players }: { v: CatchmindView; me: string | null; p
<span className="nm" aria-hidden style={{ fontWeight: id === me ? 900 : 700 }}>
{nick(players, id)}
</span>
<span className="sc" aria-hidden>
<span key={v.scores[id] ?? 0} className={`sc${v.scores[id] ? ' anim-bump' : ''}`} aria-hidden>
{v.scores[id] ?? 0}점
</span>
</div>
@@ -807,7 +875,7 @@ function ScoreList({ v, me, players }: { v: CatchmindView; me: string | null; pl
✓ 맞힘
</span>
)}
<strong style={{ fontVariantNumeric: 'tabular-nums' }} aria-hidden>
<strong key={v.scores[id] ?? 0} className={v.scores[id] ? 'anim-bump' : undefined} style={{ fontVariantNumeric: 'tabular-nums' }} aria-hidden>
{v.scores[id] ?? 0}점
</strong>
</li>
@@ -917,7 +985,7 @@ function GuessPanel({ v, me, players, act, pending }: { v: CatchmindView; me: st
{v.chat.map((m) => {
const { cls, body } = chatLine(m, me, players, v.drawer);
return (
<li key={m.id} className={`cm-line ${cls}${m.from === me ? ' mine' : ''}`} style={{ '--name-h': nameHue(m.from) } as CSSProperties}>
<li key={m.id} className={`cm-line ${cls}${m.from === me ? ' mine' : ''} anim-slide-up`} style={{ '--name-h': nameHue(m.from) } as CSSProperties}>
{body}
</li>
);
@@ -983,8 +1051,40 @@ function AwayBanner({ v, me, act }: { v: CatchmindView; me: string | null; act:
);
}
/** Sounds for what happens on the table (my own "정답!" is played by the overlay). */
function useTableSounds(v: CatchmindView, me: string | null): void {
const prev = useRef(v);
useEffect(() => {
const p = prev.current;
prev.current = v;
if (p === v) return;
const turnChanged = p.turnNo !== v.turnNo;
if (turnChanged && v.phase === 'choosing') {
if (v.drawer === me) {
sounds.myTurn();
sfx.deal(v.choices?.length ?? 1);
} else sfx.whoosh();
}
if (v.phase === 'drawing' && (p.phase !== 'drawing' || turnChanged)) sfx.whoosh();
if (!turnChanged && v.phase === 'drawing' && v.hintStage > p.hintStage) cmSound.hint();
// New chat lines: someone else got it, the drawer reacted, my "아까워요".
const seen = p.chat.at(-1)?.id ?? 0;
const fresh = v.chat.filter((m) => m.id > seen);
if (fresh.some((m) => m.kind === 'correct' && m.from !== me)) cmSound.otherCorrect();
if (v.role !== 'drawer' && fresh.some((m) => m.kind === 'reaction')) cmSound.react();
if (fresh.some((m) => m.kind === 'close' && m.from === me)) cmSound.close();
if (!turnChanged && p.phase === 'drawing' && v.phase === 'reveal') {
if (v.endReason === 'report') sfx.alarm();
else if (v.endReason === 'allSolved') sfx.fanfare();
else if (v.solvers.length === 0) sfx.bad();
else sfx.cardFlip();
}
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
}
function CatchmindBoard({ view: v, me, players, act, pending }: BoardProps<CatchmindView>) {
const wide = useWide();
useTableSounds(v, me);
return (
<div className="cm">
<style>{CSS}</style>
@@ -1068,7 +1168,7 @@ function statusText(v: CatchmindView, me: string | null, players: Record<string,
// ---------------------------------------------------------------- options
function Seg<T extends string | number | boolean>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
function Seg<T extends string | number | boolean | 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]) => (
@@ -1137,9 +1237,11 @@ function Options({ value: o, onChange }: OptionsProps<CatchmindOptions>) {
[80, '80초'],
[100, '100초'],
[120, '120초'],
[null, '무제한'],
]}
onChange={(drawSeconds) => set({ drawSeconds })}
/>
{o.drawSeconds === null && <span className="small muted">맞힐 때까지 그려요. 아무도 못 맞히면 출제자가 [정답 공개하고 넘기기]로 넘겨요. 힌트는 80초 기준으로 나와요.</span>}
</Field>
<Field label="단어 난이도">
<Seg
@@ -1212,7 +1314,7 @@ function Options({ value: o, onChange }: OptionsProps<CatchmindOptions>) {
function optionsSummary(o: CatchmindOptions): string {
const hint = o.hints === 'full' ? '힌트 많이' : o.hints === 'basic' ? '글자 수 힌트' : '힌트 없음';
const diff = o.difficulty === 'easy' ? '쉬운 단어' : o.difficulty === 'normal' ? '보통 단어' : '';
return [o.guessMode === 'multi' ? '여러 명 맞히기' : '첫 정답자만', `${o.rounds}라운드`, `${o.drawSeconds}초`, hint, diff, o.customOnly ? '추가 단어만' : ''].filter(Boolean).join(' · ');
return [o.guessMode === 'multi' ? '여러 명 맞히기' : '첫 정답자만', `${o.rounds}라운드`, o.drawSeconds === null ? '그리기 무제한' : `${o.drawSeconds}초`, hint, diff, o.customOnly ? '추가 단어만' : ''].filter(Boolean).join(' · ');
}
// ---------------------------------------------------------------- rules
@@ -1223,7 +1325,7 @@ function Rules({ options }: { options?: CatchmindOptions }) {
<div className="stack">
<p>
한 사람(출제자)이 제시어를 <strong>그림으로</strong> 그리고, 나머지는 그림을 보며 <strong>채팅으로 정답</strong>을 맞혀요. 차례대로 돌아가며 모두 한 번씩 그리면 1라운드예요
{o ? `(이 방은 ${o.rounds}라운드, 그리기 ${o.drawSeconds}초)` : ''}.
{o ? `(이 방은 ${o.rounds}라운드, 그리기 ${o.drawSeconds === null ? '시간 무제한' : `${o.drawSeconds}초`})` : ''}.
</p>
<p>
출제자는 단어 3개 중 하나를 10초 안에 골라요. 그리는 동안에는 글자를 쓰면 안 되고, 채팅 대신 "거의 다 왔어요" 같은 반응 버튼만 쓸 수 있어요. 글자를 쓰면 맞히는 사람들이 신고할 수 있어요.
@@ -1234,7 +1336,10 @@ function Rules({ options }: { options?: CatchmindOptions }) {
: '먼저 맞힐수록 점수가 커요: 10점, 8점, 6점, 그다음부터 4점. 출제자는 맞힌 사람 1명마다 2점(최대 12점)을 받아요.'}{' '}
띄어쓰기·문장부호는 무시하고, "사과요"처럼 끝에 붙인 말도 정답으로 봐요. 거의 맞히면 나에게만 "아까워요!"가 떠요.
</p>
<p>시간이 지나면 힌트가 나와요: 처음엔 글자 수, 절반이 지나면 초성, 3/4이 지나면 한 글자. 점수가 같으면 많이 맞힌 사람이 앞서요.</p>
<p>
시간이 지나면 힌트가 나와요: 처음엔 글자 수, 절반이 지나면 초성, 3/4이 지나면 한 글자.{' '}
{o?.drawSeconds === null ? '그리기 시간이 무제한이면 40초에 초성, 60초에 한 글자가 나오고, 아무도 못 맞히면 출제자가 정답을 공개하고 넘길 수 있어요. ' : ''}점수가 같으면 많이 맞힌 사람이 앞서요.
</p>
</div>
);
}

View File

@@ -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>
);