체스·장기·쿼리도 소리·움직임, 장기 상차림 시간 무제한
- 체스: 기물이 출발 칸에서 미끄러져 와 내려앉음(내가 끌어다 놓은 수는 제외), 캐슬링은 룩도 같이, 잡힌 기물(앙파상 폰 포함) 사라짐, 체크 칸 빛·말풍선 튀어나옴, 마지막 수 칸 살짝 나타남 - 체스 소리: 나무 기물 톡, 잡기, 캐슬링, 승진, 체크, 체크메이트 순간, 무르기, 기물 집기, 안 되는 칸 (fx.ts 순수 함수 + 테스트) - 장기: 묵직한 기물 미끄러짐·내려앉기, 잡힌 기물 사라짐, 장군 궁 자리 고동, 상차림 마·상 하나씩 튀어나옴 - 장기 소리: 두꺼운 나무 "딱", 잡기, 장군·멍군·빅장, 외통 순간, 한수쉼, 무르기, 상차림 놓기 (fx.ts + 테스트) - 장기 상차림 고르는 시간에 무제한(0) 추가, 방 설정 "자세한 설정"에서 30초·1분·3분·무제한 (기본 1분 그대로), 무제한이면 상차림 시계 숨김, 끊긴 사람만 접속 유예 뒤 자동 선택 - 쿼리도: 말 한 칸은 살짝 튀며, 점프는 높이 뛰어 넘음, 도착 칸 고리, 벽 내려앉기+먼지, 무르기로 빠진 벽 사라짐, 안 되는 벽 흔들림, 목표 도착 띠 깜빡임·금빛 고리 - 쿼리도 소리: 말 톡, 점프, 벽 끼우기, 안 되는 곳, 목표 도착, 무르기 - 상대·컴퓨터 수도 화면 변화로 같은 소리·움직임, 새로 열면 다시 재생 안 함, 숨은 탭 내 차례 소리는 방 화면에 맡김 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,11 +4,13 @@ import type { Cell, QuoridorLegalWall, QuoridorMove, QuoridorOptions, QuoridorSe
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar, ConfirmSheet, Sheet } from '../../components/ui';
|
||||
import { TurnTimer, useServerNow } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { haptic } from '../../lib/feedback';
|
||||
import { toast } from '../../store/toast';
|
||||
import { BOARD_MOTION_CSS, useMoveDiff } from '../board-motion';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
import { JUMP_LAND_MS, qdSound } from './sound';
|
||||
|
||||
type O = 'h' | 'v';
|
||||
interface Pt {
|
||||
@@ -31,9 +33,23 @@ const swapFor = (seat: Seat | null) => seat === 'W' || seat === 'E';
|
||||
|
||||
const CSS = `
|
||||
.qd-pawn { transition: transform 220ms ease-out; }
|
||||
.qd-wall-new { animation: qd-drop 260ms ease-out both; transform-box: fill-box; transform-origin: center; }
|
||||
.qd-pawn.jump { transition: transform ${JUMP_LAND_MS}ms cubic-bezier(.35, .1, .3, 1); }
|
||||
.qd-step, .qd-hop, .qd-wall-dust, .qd-goal-burst { transform-box: fill-box; transform-origin: center; }
|
||||
.qd-step { animation: qd-step 220ms ease-out both; }
|
||||
@keyframes qd-step { 50% { transform: translateY(-0.1px) scale(1.06); } }
|
||||
.qd-hop { animation: qd-hop ${JUMP_LAND_MS + 60}ms cubic-bezier(.3, .6, .4, 1) both; }
|
||||
@keyframes qd-hop { 45% { transform: translateY(-0.5px) scale(1.22); } 82% { transform: translateY(0) scale(.94); } 100% { transform: none; } }
|
||||
.qd-wall-new { animation: qd-drop 300ms cubic-bezier(.3, .8, .4, 1.2) both; transform-box: fill-box; transform-origin: center; }
|
||||
.qd-wall-dust { animation: qd-dust 420ms ease-out 170ms both; pointer-events: none; }
|
||||
@keyframes qd-dust { 0% { opacity: .7; transform: scale(1); } 100% { opacity: 0; transform: scale(var(--sx, 1.2), var(--sy, 1.2)); } }
|
||||
.qd-shake { animation: qd-shake 360ms ease both; }
|
||||
@keyframes qd-shake { 20%, 60% { transform: translateX(-0.08px); } 40%, 80% { transform: translateX(0.08px); } }
|
||||
.qd-goal-burst { animation: qd-goal 0.9s ease-out both; pointer-events: none; }
|
||||
@keyframes qd-goal { 0% { opacity: .95; transform: scale(.6); } 100% { opacity: 0; transform: scale(2.4); } }
|
||||
.qd-band-glow { animation: qd-band 0.45s ease-in-out 3; }
|
||||
@keyframes qd-band { 50% { opacity: .3; } }
|
||||
.qd-turn-ring { animation: qd-pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
|
||||
@keyframes qd-drop { 0% { transform: scale(1.35); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
|
||||
@keyframes qd-drop { 0% { transform: scale(1.3); opacity: 0; } 60% { transform: scale(.97); opacity: 1; } 100% { transform: none; opacity: 1; } }
|
||||
@keyframes qd-pulse { 0%, 100% { opacity: 0.95; } 50% { opacity: 0.35; } }
|
||||
.qd-board * { pointer-events: none; }
|
||||
.qd-board [data-cell], .qd-board [data-anchor] { pointer-events: auto; }
|
||||
@@ -93,6 +109,19 @@ function overlapsAny(walls: Wall[], w: Wall): boolean {
|
||||
return has('v', w.c, w.r - 1) || has('v', w.c, w.r) || has('v', w.c, w.r + 1) || has('h', w.c, w.r);
|
||||
}
|
||||
|
||||
/** The last real action (not an automatic pass) among the moves that just arrived. */
|
||||
function lastAction(added: QuoridorMove[]): Exclude<QuoridorMove, { kind: 'pass' }> | undefined {
|
||||
for (let i = added.length - 1; i >= 0; i--) {
|
||||
const m = added[i]!;
|
||||
if (m.kind !== 'pass') return m;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
const isJump = (m: { from: Cell; to: Cell }) => Math.abs(m.to.c - m.from.c) + Math.abs(m.to.r - m.from.r) > 1;
|
||||
/** The seat finished with this update (it was still playing before). */
|
||||
const reachedGoal = (seat: Seat, before: QuoridorSeatView[], now: QuoridorSeatView[]) =>
|
||||
before.find((x) => x.seat === seat)?.status === 'playing' && now.find((x) => x.seat === seat)?.status === 'finished';
|
||||
|
||||
function wallRect(a: Pt, o: O) {
|
||||
return o === 'h' ? { x: a.x + 0.05, y: a.y + 1 - G / 2, width: 2 - 0.1, height: G } : { x: a.x + 1 - G / 2, y: a.y + 0.05, width: G, height: 2 - 0.1 };
|
||||
}
|
||||
@@ -132,8 +161,15 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
const prevCount = useRef(v.moveCount);
|
||||
const prevWalls = useRef(v.walls.length);
|
||||
const [newWall, setNewWall] = useState<string | null>(null);
|
||||
const [shake, setShake] = useState(0);
|
||||
|
||||
// What changed with the last view update (null on page load, so nothing replays on reconnect).
|
||||
const { before, forward } = useMoveDiff({ walls: v.walls, seats: v.seats, count: v.moveCount }, v.moveCount);
|
||||
const recent = before && forward ? (lastAction(v.moves.slice(before.count)) ?? null) : null;
|
||||
const jumped = recent?.kind === 'move' && isJump(recent);
|
||||
const newWall = recent?.kind === 'wall' ? wallKey(recent.wall) : null;
|
||||
const goalSeat = recent?.kind === 'move' && reachedGoal(recent.seat, before?.seats ?? [], v.seats) ? recent.seat : null;
|
||||
const takenBack = before && !forward ? before.walls.filter((w) => !v.walls.some((x) => wallKey(x) === wallKey(w))) : [];
|
||||
|
||||
const legalCells = useMemo(() => {
|
||||
const m = new Set<string>();
|
||||
@@ -155,19 +191,23 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
prevCount.current = v.moveCount;
|
||||
setMovePreview(null);
|
||||
setWallAt(null);
|
||||
if (v.walls.length > prevWalls.current) setNewWall(wallKey(v.walls[v.walls.length - 1]!));
|
||||
else setNewWall(null);
|
||||
prevWalls.current = v.walls.length;
|
||||
if (v.moveCount < prev) qdSound.undo();
|
||||
if (v.moveCount <= prev) return;
|
||||
const added = v.moves.slice(prev);
|
||||
const texts = added.map((m) => (m.kind === 'pass' ? `${SEAT_KO[m.seat]}은 움직일 곳이 없어 차례를 넘겼어요.` : `${moveText(m, t.swap)}.`));
|
||||
for (const m of added) if (m.kind === 'pass' && m.seat === v.mySeat) toast('움직일 곳도 세울 벽도 없어서 차례를 넘겼어요');
|
||||
setAnnounce(texts.join(' '));
|
||||
if (added.some((m) => m.kind !== 'pass')) sounds.stone();
|
||||
if (v.phase === 'playing' && v.mySeat === v.turn) {
|
||||
haptic(40);
|
||||
if (document.visibilityState === 'hidden') sounds.myTurn();
|
||||
// One sound per update (mine, the opponent's and the computer's moves alike).
|
||||
const last = lastAction(added);
|
||||
if (last?.kind === 'wall') qdSound.wall();
|
||||
else if (last?.kind === 'move') {
|
||||
const jump = isJump(last);
|
||||
if (jump) qdSound.jump();
|
||||
else qdSound.step();
|
||||
if (v.seats.find((x) => x.seat === last.seat)?.status === 'finished') qdSound.goal(jump ? JUMP_LAND_MS : 0);
|
||||
}
|
||||
// The "your turn" chime for a hidden tab is played by the room page.
|
||||
if (v.phase === 'playing' && v.mySeat === v.turn) haptic(40);
|
||||
}, [v.moveCount]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
@@ -192,9 +232,19 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
setMovePreview(null);
|
||||
setHoverCell(null);
|
||||
};
|
||||
/** A refused wall: subtle sound + the red preview shakes. */
|
||||
const refuseWall = () => {
|
||||
qdSound.refuse();
|
||||
setShake((n) => n + 1);
|
||||
};
|
||||
/** Pin the preview at an anchor/direction the player tapped; say no right away when it cannot go there. */
|
||||
const pinWall = (a: Pt, o: O) => {
|
||||
if (judge(a, o).why) refuseWall();
|
||||
};
|
||||
const doWall = (a: Pt) => {
|
||||
const j = judge(a, orient);
|
||||
if (j.why) {
|
||||
refuseWall();
|
||||
haptic([30, 30, 30]);
|
||||
setAnnounce(j.why);
|
||||
toast(j.why);
|
||||
@@ -208,6 +258,7 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
const c = t.screenToCell(p);
|
||||
const occupied = v.seats.some((x) => x.pos && x.pos.c === c.c && x.pos.r === c.r);
|
||||
const msg = occupied ? '말이 있는 칸이에요.' : '그 칸으로는 갈 수 없어요. 밝게 표시된 칸으로 움직일 수 있어요.';
|
||||
qdSound.refuse();
|
||||
haptic([30, 30, 30]);
|
||||
setAnnounce(msg);
|
||||
toast(msg);
|
||||
@@ -229,11 +280,14 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
const tapAnchor = (a: Pt) => {
|
||||
if (!canWall) return;
|
||||
if (wallAt && wallAt.x === a.x && wallAt.y === a.y) {
|
||||
setOrient((o) => (o === 'h' ? 'v' : 'h'));
|
||||
const o = orient === 'h' ? 'v' : 'h';
|
||||
setOrient(o);
|
||||
pinWall(a, o);
|
||||
return;
|
||||
}
|
||||
setWallAt(a);
|
||||
setCursor(a);
|
||||
pinWall(a, orient);
|
||||
};
|
||||
|
||||
const pointer = (e: React.PointerEvent<SVGSVGElement>): { x: number; y: number } | null => {
|
||||
@@ -290,6 +344,7 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
const o = orient === 'h' ? 'v' : 'h';
|
||||
setOrient(o);
|
||||
setWallAt(cursor);
|
||||
pinWall(cursor, o);
|
||||
const j = judge(cursor, o);
|
||||
setAnnounce(`${wallText(j.wall, t.swap)} ${j.why ?? '세울 수 있음'}`);
|
||||
} else if (e.key === 'w' || e.key === 'W') {
|
||||
@@ -330,7 +385,7 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
|
||||
return (
|
||||
<div className="board-wrap stack" style={{ gap: 10, maxWidth: 'min(100%, calc(100vh - 340px))', minWidth: 'min(100%, 300px)' }}>
|
||||
<style>{CSS}</style>
|
||||
<style>{BOARD_MOTION_CSS + CSS}</style>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
className="qd-board"
|
||||
@@ -375,7 +430,8 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
>
|
||||
{goalSides.map((g, k) => {
|
||||
const sameSide = goalSides.filter((x, j) => j < k && x.side === g.side).length;
|
||||
return <rect key={`g${g.seat}`} {...band(g.side, sameSide)} rx={0.06} fill={SEAT_COLOR[g.seat]} opacity={0.9} />;
|
||||
const glow = g.seat === goalSeat;
|
||||
return <rect key={`g${g.seat}${glow ? v.moveCount : ''}`} className={glow ? 'qd-band-glow' : undefined} {...band(g.side, sameSide)} rx={0.06} fill={SEAT_COLOR[g.seat]} opacity={0.9} />;
|
||||
})}
|
||||
{Array.from({ length: N }, (_, i) => {
|
||||
const bottom = t.screenToCell({ x: i, y: N - 1 });
|
||||
@@ -433,33 +489,53 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
{v.walls.map((w) => {
|
||||
const s = t.wallToScreen(w);
|
||||
const k = wallKey(w);
|
||||
const fall = k === newWall;
|
||||
return (
|
||||
<rect
|
||||
key={k}
|
||||
className={k === newWall ? 'qd-wall-new' : undefined}
|
||||
{...wallRect(s.a, s.o)}
|
||||
rx={0.05}
|
||||
fill="#3b2412"
|
||||
stroke={k === lastWall ? 'var(--focus)' : '#f3e2c0'}
|
||||
strokeWidth={k === lastWall ? 0.05 : 0.025}
|
||||
data-wall={`${w.o}:${label(w)}`}
|
||||
/>
|
||||
<g key={fall ? `${k}@${v.moveCount}` : k}>
|
||||
{fall && <rect className="qd-wall-dust" style={{ '--sx': s.o === 'h' ? 1.12 : 2.6, '--sy': s.o === 'h' ? 2.6 : 1.12 } as React.CSSProperties} {...wallRect(s.a, s.o)} rx={0.05} fill="#fff7e6" />}
|
||||
<rect
|
||||
className={fall ? 'qd-wall-new' : undefined}
|
||||
{...wallRect(s.a, s.o)}
|
||||
rx={0.05}
|
||||
fill="#3b2412"
|
||||
stroke={k === lastWall ? 'var(--focus)' : '#f3e2c0'}
|
||||
strokeWidth={k === lastWall ? 0.05 : 0.025}
|
||||
data-wall={`${w.o}:${label(w)}`}
|
||||
/>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{takenBack.map((w) => {
|
||||
const s = t.wallToScreen(w);
|
||||
return <rect key={`u${v.moveCount}-${wallKey(w)}`} className="bm-gone" {...wallRect(s.a, s.o)} rx={0.05} fill="#3b2412" stroke="#f3e2c0" strokeWidth={0.025} />;
|
||||
})}
|
||||
{recent?.kind === 'move' && (() => {
|
||||
const to = t.cellToScreen(recent.to);
|
||||
return <circle key={`ring${v.moveCount}`} className="bm-ring" style={{ animationDelay: jumped ? `${JUMP_LAND_MS}ms` : undefined }} cx={to.x + 0.5} cy={to.y + 0.5} r={0.42} fill="none" stroke="var(--focus)" strokeWidth={0.05} />;
|
||||
})()}
|
||||
{recent?.kind === 'move' && goalSeat && (() => {
|
||||
const to = t.cellToScreen(recent.to);
|
||||
return <circle key={`goal${v.moveCount}`} className="qd-goal-burst" cx={to.x + 0.5} cy={to.y + 0.5} r={0.45} fill={SEAT_COLOR[goalSeat]} opacity={0.6} stroke="#fde68a" strokeWidth={0.06} />;
|
||||
})()}
|
||||
{v.seats.map((x) => {
|
||||
if (!x.pos) return null;
|
||||
const p = t.cellToScreen(x.pos);
|
||||
const turn = v.phase === 'playing' && v.turn === x.seat;
|
||||
const moved = recent?.kind === 'move' && recent.seat === x.seat;
|
||||
return (
|
||||
<g key={x.seat} className="qd-pawn" style={{ transform: `translate(${p.x + 0.5}px, ${p.y + 0.5}px)` }} data-pawn={x.seat} data-at={label(x.pos)}>
|
||||
<g key={x.seat} className={`qd-pawn${moved && jumped ? ' jump' : ''}`} style={{ transform: `translate(${p.x + 0.5}px, ${p.y + 0.5}px)` }} data-pawn={x.seat} data-at={label(x.pos)}>
|
||||
{turn && <circle className="qd-turn-ring" cx={0} cy={0} r={0.45} fill="none" stroke={SEAT_COLOR[x.seat]} strokeWidth={0.06} />}
|
||||
<PawnMark seat={x.seat} cx={0} cy={0} />
|
||||
{x.status === 'finished' && <circle className="bm-win" cx={0} cy={0} r={0.47} fill="none" stroke="#fbbf24" strokeWidth={0.07} />}
|
||||
<g key={`h${v.moveCount}`} className={moved ? (jumped ? 'qd-hop' : 'qd-step') : undefined}>
|
||||
<PawnMark seat={x.seat} cx={0} cy={0} />
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{lastTo && <circle cx={lastTo.x + 0.5 + 0.27} cy={lastTo.y + 0.5 - 0.27} r={0.08} fill="var(--focus)" stroke="#fff" strokeWidth={0.02} />}
|
||||
{ghostCell && me && <PawnMark seat={me.seat} cx={ghostCell.x + 0.5} cy={ghostCell.y + 0.5} ghost />}
|
||||
{preview && previewAnchor && (
|
||||
<g key={`pv${shake}`} className={shake && preview.why ? 'qd-shake' : undefined}>
|
||||
<rect
|
||||
{...wallRect(previewAnchor, orient)}
|
||||
rx={0.05}
|
||||
@@ -469,6 +545,7 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
strokeWidth={0.04}
|
||||
strokeDasharray={wallAt ? undefined : '0.12 0.08'}
|
||||
/>
|
||||
</g>
|
||||
)}
|
||||
{myTurn && mode === 'wall' && (
|
||||
<g aria-hidden>
|
||||
@@ -509,6 +586,7 @@ function QuoridorBoard({ view: v, players, act, pending, tapConfirm }: BoardProp
|
||||
<button type="button" className="btn btn-secondary qd-rotate" onClick={() => {
|
||||
const o = orient === 'h' ? 'v' : 'h';
|
||||
setOrient(o);
|
||||
if (wallAt) pinWall(wallAt, o);
|
||||
}} aria-label={`벽 방향 바꾸기, 지금 ${orient === 'h' ? '가로' : '세로'}`}>
|
||||
↻ {orient === 'h' ? '가로' : '세로'}
|
||||
</button>
|
||||
|
||||
34
apps/web/src/games/quoridor/sound.ts
Normal file
34
apps/web/src/games/quoridor/sound.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/** 쿼리도 소리: 나무 말과 나무 벽. Short and soft; the site volume is applied by feedback.ts. */
|
||||
import { noise, sfx, tone } from '../../lib/feedback';
|
||||
|
||||
/** When the jump sound lands (ms), matching the hop animation in index.tsx. */
|
||||
export const JUMP_LAND_MS = 250;
|
||||
|
||||
/** A soft wooden "tok" (one pawn step). */
|
||||
function tok(delay = 0, gain = 0.14): void {
|
||||
tone(560, 55, 'triangle', gain, delay);
|
||||
noise(26, gain * 0.45, delay, 'bandpass', 1500, 1.6);
|
||||
}
|
||||
|
||||
export const qdSound = {
|
||||
/** Pawn moved one cell. */
|
||||
step: () => tok(),
|
||||
/** Pawn jumped over another: a little hop up, then the tok on landing. */
|
||||
jump: () => {
|
||||
tone(360, 150, 'sine', 0.07, 0, { slideTo: 720 });
|
||||
tok(JUMP_LAND_MS, 0.15);
|
||||
},
|
||||
/** Wall set into the groove: lower and firmer than a pawn, with a short knock as it settles. */
|
||||
wall: () => {
|
||||
noise(45, 0.16, 0, 'bandpass', 850, 1.3);
|
||||
tone(190, 95, 'triangle', 0.17);
|
||||
tone(300, 40, 'square', 0.025, 4);
|
||||
noise(35, 0.07, 75, 'lowpass', 650);
|
||||
},
|
||||
/** A wall that cannot go there (subtle). */
|
||||
refuse: () => tone(175, 120, 'triangle', 0.08, 0, { slideTo: 125 }),
|
||||
/** A pawn reached its goal line: a short rising run (the win/lose jingle is played by the room). */
|
||||
goal: (delay = 0) => [523, 659, 784, 1046].forEach((f, i) => tone(f, 120, 'triangle', 0.08, delay + 60 + i * 65)),
|
||||
/** Moves taken back (무르기). */
|
||||
undo: () => sfx.whoosh(),
|
||||
};
|
||||
Reference in New Issue
Block a user