오목·사목·오델로·바둑 소리·움직임, 바둑 사석 확인 무제한
- 공통(보드게임 8종용) board-motion: 직전 판 비교(useMoveDiff), 끝난 잔상 치우기(useAnimOver), 내려앉기·미끄러지기·사라지기·고리·반짝임 클래스 - 오목: 돌 내려앉기, 마지막 수 고리, 무르기 돌 사라짐, 승리 줄 차례로 반짝임, 금수 누르면 작은 소리, 돌 그림자 - 사목: 바닥에 닿아 한 번 튀기, 닿는 순간에 맞춘 "탁" 소리, 마지막 수 점은 닿은 뒤, 이긴 줄 차례로 깜빡임 - 오델로: 놓은 돌 먼저 내려앉고 뒤집기(들리며 뒤집힘), 뒤집힐 때마다 딸깍, 패스·무르기 소리, 마지막 수 고리 - 바둑: 돌 내려앉기, 따낸 돌 한 알씩 사라짐+딸깍, 패스 소리, 무르기 되돌림, 사석 표시 바뀜 소리 - 바둑 사석 확인 제한 시간에 무제한(0) 추가(기본 3분 그대로), 테스트·문서 - 숨은 탭 내 차례 소리는 방 화면이 이미 내므로 게임 쪽 중복 제거 - games E2E에 오목 기본 계획 추가 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,8 @@ import type { BadukOptions, BadukView, Pt, ScoreBreakdown } from '@bg/games/badu
|
||||
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, noise, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import { BOARD_MOTION_CSS, useAnimOver, useMoveDiff } from '../board-motion';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -35,9 +36,18 @@ function fmtScore(n: number, method: 'territory' | 'area'): string {
|
||||
return half ? (whole === 0 ? '반' : `${whole}.5`) : String(whole);
|
||||
}
|
||||
|
||||
/** Stones taken off the board: a few small clicks as they are picked up into the lid. */
|
||||
function captureSound(count: number) {
|
||||
for (let k = 0; k < Math.min(count, 6); k++) {
|
||||
tone(2100 + (k % 3) * 260, 28, 'triangle', 0.06, 150 + k * 55);
|
||||
noise(25, 0.05, 150 + k * 55, 'highpass', 4500);
|
||||
}
|
||||
}
|
||||
|
||||
function Stone({ color, cx, cy, r, ghost }: { color: Color; cx: number; cy: number; r: number; ghost?: boolean }) {
|
||||
return (
|
||||
<g opacity={ghost ? 0.5 : 1}>
|
||||
{!ghost && <ellipse cx={cx + r * 0.1} cy={cy + r * 0.16} rx={r} ry={r * 0.96} fill="#000" opacity={0.22} />}
|
||||
<circle cx={cx} cy={cy} r={r} fill={color === 'black' ? '#151515' : '#fbfbf8'} stroke={color === 'black' ? '#000' : '#666'} strokeWidth={0.05} />
|
||||
{color === 'black' ? (
|
||||
<circle cx={cx - r * 0.3} cy={cy - r * 0.3} r={r * 0.28} fill="#fff" opacity={0.15} />
|
||||
@@ -76,21 +86,33 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
return out;
|
||||
}, [v.scoring, v.result, v.board, n]);
|
||||
const seki = useMemo(() => new Set((v.scoring?.seki ?? []).map((p) => p.y * n + p.x)), [v.scoring?.seki, n]);
|
||||
// Board before the last move: the new stone sets down and captures fade only for moves seen live;
|
||||
// 무르기 lifts the taken-back stone and puts captured stones back.
|
||||
const { before, forward } = useMoveDiff(v.board, v.moveCount);
|
||||
const fresh = !!before && forward;
|
||||
const undone = before && !forward ? before.flatMap((c, i) => (c !== 0 && v.board[i] === 0 ? [{ i, color: (c === 1 ? 'black' : 'white') as Color }] : [])) : [];
|
||||
const [goneOver, goneEnd] = useAnimOver(v.moveCount);
|
||||
const restored = new Set(before && !forward ? v.board.flatMap((c, i) => (c !== 0 && before[i] === 0 ? [i] : [])) : []);
|
||||
|
||||
// Move sounds and announcements.
|
||||
// Move sounds and announcements (mine, the opponent's and the computer's).
|
||||
useEffect(() => {
|
||||
if (v.moveCount > prevCount.current) {
|
||||
const m = v.moves[v.moves.length - 1]!;
|
||||
if (m.pt) {
|
||||
sounds.stone();
|
||||
if (m.captured > 0) haptic(30);
|
||||
sfx.stone();
|
||||
if (m.captured > 0) {
|
||||
captureSound(m.captured);
|
||||
haptic(30);
|
||||
}
|
||||
setAnnounce(`${COLOR_KO[m.color]}이 ${label(n, m.pt)}에 두었어요.${m.captured ? ` 돌 ${m.captured}개를 따냈어요.` : ''}`);
|
||||
} else setAnnounce(`${COLOR_KO[m.color]}이 패스했어요.`);
|
||||
if (myTurn) {
|
||||
haptic(40);
|
||||
if (document.visibilityState === 'hidden') sounds.myTurn();
|
||||
} else {
|
||||
// 패스: a soft knock on the board edge.
|
||||
tone(330, 90, 'sine', 0.1);
|
||||
noise(50, 0.05, 0, 'lowpass', 700);
|
||||
setAnnounce(`${COLOR_KO[m.color]}이 패스했어요.`);
|
||||
}
|
||||
}
|
||||
if (myTurn) haptic(40);
|
||||
} else if (v.moveCount < prevCount.current) sfx.whoosh();
|
||||
prevCount.current = v.moveCount;
|
||||
setPreview(null);
|
||||
setBubble(null);
|
||||
@@ -109,6 +131,7 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
for (const i of dead) if (!before.has(i)) diff.add(i);
|
||||
for (const i of before) if (!dead.has(i)) diff.add(i);
|
||||
if (diff.size === 0) return;
|
||||
sfx.click();
|
||||
setChanged(diff);
|
||||
const t = setTimeout(() => setChanged(new Set()), 2500);
|
||||
return () => clearTimeout(t);
|
||||
@@ -142,6 +165,7 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
const why = illegal.get(p.y * n + p.x);
|
||||
if (why) {
|
||||
haptic([30, 30, 30]);
|
||||
sfx.bad();
|
||||
setBubble({ p, text: ILLEGAL_KO[why] });
|
||||
setAnnounce(ILLEGAL_KO[why]);
|
||||
return;
|
||||
@@ -186,6 +210,7 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
const pad = 0.95;
|
||||
return (
|
||||
<div className="board-wrap stack" style={{ gap: 10 }}>
|
||||
<style>{BOARD_MOTION_CSS}</style>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
viewBox={`${-pad} ${-pad} ${n - 1 + 2 * pad} ${n - 1 + 2 * pad}`}
|
||||
@@ -242,20 +267,35 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
const x = i % n;
|
||||
const y = Math.floor(i / n);
|
||||
const isDead = dead.has(i);
|
||||
const isLast = fresh && v.lastMove !== null && i === v.lastMove.y * n + v.lastMove.x;
|
||||
return (
|
||||
<g key={i} opacity={isDead ? 0.45 : 1}>
|
||||
<Stone color={color} cx={x} cy={y} r={0.47} />
|
||||
<g key={isLast ? `m${v.moveCount}` : i} opacity={isDead ? 0.45 : 1} style={{ transition: 'opacity 0.25s' }}>
|
||||
<g className={isLast ? 'bm-place' : restored.has(i) ? 'anim-pop' : undefined}>
|
||||
<Stone color={color} cx={x} cy={y} r={0.47} />
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{/* Stones just captured fade out. */}
|
||||
{v.phase === 'playing' &&
|
||||
v.lastCaptured.map((p) => (
|
||||
<g key={`cap${v.moveCount}-${p.x}-${p.y}`} opacity={0}>
|
||||
<animate attributeName="opacity" from={0.7} to={0} dur="0.6s" fill="freeze" />
|
||||
{/* Stones just captured are lifted off one by one; a stone taken back by 무르기 fades. */}
|
||||
{fresh &&
|
||||
!goneOver &&
|
||||
v.phase === 'playing' &&
|
||||
v.lastCaptured.map((p, k, all) => (
|
||||
<g
|
||||
key={`cap${v.moveCount}-${p.x}-${p.y}`}
|
||||
className="bm-gone"
|
||||
style={{ animationDelay: `${150 + Math.min(k, 6) * 55}ms` }}
|
||||
onAnimationEnd={k === all.length - 1 ? goneEnd : undefined}
|
||||
>
|
||||
<Stone color={lastColor ? other(lastColor) : 'white'} cx={p.x} cy={p.y} r={0.47} />
|
||||
</g>
|
||||
))}
|
||||
{!goneOver &&
|
||||
undone.map(({ i, color }) => (
|
||||
<g key={`u${v.moveCount}-${i}`} className="bm-gone" onAnimationEnd={goneEnd}>
|
||||
<Stone color={color} cx={i % n} cy={Math.floor(i / n)} r={0.47} />
|
||||
</g>
|
||||
))}
|
||||
{/* Territory / area marks (small squares) and seki marks. */}
|
||||
{score &&
|
||||
score.ownership.map((o, i) => {
|
||||
@@ -277,7 +317,10 @@ function BadukBoard({ view: v, act, pending, tapConfirm }: BoardProps<BadukView>
|
||||
</circle>
|
||||
))}
|
||||
{v.lastMove && lastColor && (
|
||||
<circle cx={v.lastMove.x} cy={v.lastMove.y} r={0.2} fill="none" stroke={lastColor === 'black' ? '#fff' : '#111'} strokeWidth={0.08} />
|
||||
<g key={`lm${v.moveCount}`}>
|
||||
{fresh && <circle className="bm-ring" cx={v.lastMove.x} cy={v.lastMove.y} r={0.5} fill="none" stroke={lastColor === 'black' ? '#111' : '#fafafa'} strokeWidth={0.06} />}
|
||||
<circle cx={v.lastMove.x} cy={v.lastMove.y} r={0.2} fill="none" stroke={lastColor === 'black' ? '#fff' : '#111'} strokeWidth={0.08} />
|
||||
</g>
|
||||
)}
|
||||
{myTurn &&
|
||||
v.atariWarnings.map((p) => (
|
||||
@@ -787,7 +830,7 @@ function Options({ value: o, onChange }: OptionsProps<BadukOptions>) {
|
||||
</div>
|
||||
<div className="stack" style={{ gap: 6 }}>
|
||||
<strong>사석 확인 제한 시간</strong>
|
||||
<Seg value={o.scoringDeadlineSec} options={[[120, '2분'], [180, '3분'], [300, '5분']]} onChange={(scoringDeadlineSec) => set({ scoringDeadlineSec })} />
|
||||
<Seg value={o.scoringDeadlineSec} options={[[120, '2분'], [180, '3분'], [300, '5분'], [0, '무제한']]} onChange={(scoringDeadlineSec) => set({ scoringDeadlineSec })} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
62
apps/web/src/games/board-motion.ts
Normal file
62
apps/web/src/games/board-motion.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Shared movement for the two-player board games (오목·사목·오델로·체스·장기·바둑·쿼리도·윷놀이).
|
||||
* Everything reacts to the view changing, so the opponent's (and the computer's) moves get the same sound
|
||||
* and animation as mine. Animations are short and never take pointer events, so clicks are not slowed.
|
||||
* prefers-reduced-motion is handled by the global rule in styles/global.css.
|
||||
*/
|
||||
import { useRef, useState } from 'react';
|
||||
|
||||
/**
|
||||
* The snapshot from before the move counter last changed, and whether that change was a step forward.
|
||||
* `before` is null until the counter changes while the board is on screen, so a page load / reconnect shows
|
||||
* the position without replaying the last move. Computed during render (no extra frame without the piece).
|
||||
*/
|
||||
export function useMoveDiff<T>(snapshot: T, count: number): { before: T | null; forward: boolean } {
|
||||
const r = useRef<{ count: number; cur: T; before: T | null; forward: boolean }>({ count, cur: snapshot, before: null, forward: false });
|
||||
const s = r.current;
|
||||
if (count !== s.count) {
|
||||
s.before = s.cur;
|
||||
s.forward = count > s.count;
|
||||
s.count = count;
|
||||
}
|
||||
s.cur = snapshot;
|
||||
return { before: s.before, forward: s.forward };
|
||||
}
|
||||
|
||||
/**
|
||||
* For things shown only while they animate (captured / taken-back stones): `[over, end]`. Render them while
|
||||
* `over` is false and pass `end` to the last one's onAnimationEnd, so finished ghosts leave the DOM (and do not
|
||||
* count as pieces for tests or screen readers). A new `key` (move number) shows them again.
|
||||
*/
|
||||
export function useAnimOver(key: unknown): [boolean, () => void] {
|
||||
const [ended, setEnded] = useState<unknown>(undefined);
|
||||
return [ended === key, () => setEnded(key)];
|
||||
}
|
||||
|
||||
/**
|
||||
* SVG-friendly classes (scale around the element's own centre). Wrap the moving thing in its own `<g>` without a
|
||||
* `transform` attribute, because a CSS transform replaces the attribute while it runs.
|
||||
* - `bm-place`: a stone / piece set down (lands from a little above, slightly bigger, with a tiny settle).
|
||||
* - `bm-slide`: slides in from `--bm-dx/--bm-dy` (board units, e.g. `-2px` = two cells left) over `--bm-dur`.
|
||||
* - `bm-gone`: a captured piece shrinking and fading (key it by the move number; remove it with useAnimOver).
|
||||
* - `bm-ring`: one ripple ring around the last move.
|
||||
* - `bm-win`: winning line pulsing, staggered with `--bm-delay`.
|
||||
* - `bm-flash`: a quick bright flash (check / 장군).
|
||||
*/
|
||||
export const BOARD_MOTION_CSS = `
|
||||
.bm-place, .bm-gone, .bm-ring, .bm-win, .bm-flash { transform-box: fill-box; transform-origin: center; }
|
||||
.bm-place { animation: bm-place .26s cubic-bezier(.25, .9, .35, 1.25) both; pointer-events: none; }
|
||||
@keyframes bm-place { 0% { transform: translateY(-18%) scale(1.3); opacity: .15; } 70% { transform: translateY(0) scale(.97); opacity: 1; } 100% { transform: none; } }
|
||||
.bm-slide { animation: bm-slide var(--bm-dur, .24s) cubic-bezier(.3, .75, .35, 1) both; }
|
||||
@keyframes bm-slide { from { transform: translate(var(--bm-dx, 0px), var(--bm-dy, 0px)); } }
|
||||
.bm-gone { animation: bm-gone .42s ease-in forwards; pointer-events: none; }
|
||||
@keyframes bm-gone { 0% { opacity: 1; transform: scale(1); } 35% { opacity: .9; transform: scale(1.08); } 100% { opacity: 0; transform: scale(.35); } }
|
||||
.bm-ring { animation: bm-ring .55s ease-out .1s both; pointer-events: none; }
|
||||
@keyframes bm-ring { from { opacity: .85; transform: scale(.5); } to { opacity: 0; transform: scale(1.6); } }
|
||||
.bm-win { animation: bm-win 1.1s ease-in-out infinite; animation-delay: var(--bm-delay, 0ms); pointer-events: none; }
|
||||
@keyframes bm-win { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(1.12); } }
|
||||
.bm-flash { animation: bm-flash .7s ease-out both; pointer-events: none; }
|
||||
@keyframes bm-flash { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: .55; } }
|
||||
/* The global reduced-motion rule makes animations 0.01ms long; an endless pulse would then flicker. */
|
||||
@media (prefers-reduced-motion: reduce) { .bm-win { animation: none; } }
|
||||
`;
|
||||
@@ -4,7 +4,7 @@ import type { Color, ConnectFourOptions, ConnectFourView } from '@bg/games/conne
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar, ConfirmSheet } from '../../components/ui';
|
||||
import { TurnTimer, useServerNow } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { haptic, noise, sfx, tone } from '../../lib/feedback';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -15,11 +15,20 @@ const SIZE_KO: Record<ConnectFourOptions['boardSize'], string> = { '7x6': '7×6'
|
||||
/** Row counted from the bottom, 1-based (what people say: "아래에서 두 번째 줄"). */
|
||||
const rowFromBottom = (v: ConnectFourView, y: number) => v.rows - y;
|
||||
|
||||
/** Falls with gravity, hits the bottom at LAND (fraction of the animation), bounces once a little and settles. */
|
||||
const LAND = 0.78;
|
||||
/** Fall time for a disc that lands in row `y` (0 = top). */
|
||||
const fallSec = (y: number) => (0.16 + 0.06 * (y + 1)) / LAND;
|
||||
const CSS = `
|
||||
@keyframes c4drop { from { transform: translateY(var(--c4-from)); } to { transform: translateY(0); } }
|
||||
.c4-drop { animation: c4drop var(--c4-dur) cubic-bezier(.5, 0, 1, 1) both; }
|
||||
@keyframes c4drop {
|
||||
0% { transform: translateY(var(--c4-from)); animation-timing-function: cubic-bezier(.5, 0, 1, 1); }
|
||||
${LAND * 100}% { transform: translateY(0); animation-timing-function: ease-out; }
|
||||
89% { transform: translateY(-0.13px); animation-timing-function: ease-in; }
|
||||
100% { transform: translateY(0); }
|
||||
}
|
||||
.c4-drop { animation: c4drop var(--c4-dur) linear both; }
|
||||
@keyframes c4glow { 50% { opacity: .35; } }
|
||||
.c4-win { animation: c4glow 1.1s ease-in-out infinite; }
|
||||
.c4-win { animation: c4glow 1.1s ease-in-out infinite; animation-delay: var(--c4-delay, 0ms); }
|
||||
.c4-svg { --c4-frame: #1d4ed8; --c4-frame-edge: #1e3a8a; }
|
||||
:root[data-theme='dark'] .c4-svg { --c4-frame: #1e40af; --c4-frame-edge: #172554; }
|
||||
@media (prefers-color-scheme: dark) { :root[data-theme='auto'] .c4-svg { --c4-frame: #1e40af; --c4-frame-edge: #172554; } }
|
||||
@@ -55,14 +64,16 @@ function C4Board({ view: v, act, pending, tapConfirm }: BoardProps<ConnectFourVi
|
||||
|
||||
useEffect(() => {
|
||||
if (v.moveCount > prevCount.current && v.lastMove) {
|
||||
sounds.stone();
|
||||
// A light rattle as it leaves the hand, then the plastic clack when it hits the bottom (and a small second tap).
|
||||
const land = fallSec(v.lastMove.y) * LAND * 1000;
|
||||
noise(Math.min(160, land), 0.04, 0, 'bandpass', 1800, 0.7);
|
||||
tone(620, 70, 'triangle', 0.2, land);
|
||||
noise(45, 0.12, land, 'lowpass', 1400);
|
||||
tone(760, 40, 'triangle', 0.07, land + 110);
|
||||
const m = v.moves[v.moves.length - 1]!;
|
||||
setAnnounce(`${COLOR_KO[m.color]}이 ${m.x + 1}열에 넣었어요. 아래에서 ${rowFromBottom(v, m.y)}번째 칸이에요.${m.auto ? ' (시간이 다 돼서 자동으로)' : ''}`);
|
||||
}
|
||||
if (v.phase === 'playing' && myTurn && prevTurn.current !== v.turn && v.moveCount !== prevCount.current) {
|
||||
haptic(40);
|
||||
if (document.visibilityState === 'hidden') sounds.myTurn();
|
||||
}
|
||||
if (v.phase === 'playing' && myTurn && prevTurn.current !== v.turn && v.moveCount !== prevCount.current) haptic(40);
|
||||
prevCount.current = v.moveCount;
|
||||
prevTurn.current = v.turn;
|
||||
setPreview(null);
|
||||
@@ -87,6 +98,7 @@ function C4Board({ view: v, act, pending, tapConfirm }: BoardProps<ConnectFourVi
|
||||
if (!myTurn) return;
|
||||
if (!open(c)) {
|
||||
haptic([30, 30, 30]);
|
||||
sfx.bad();
|
||||
setAnnounce(`${c + 1}열은 꽉 찼어요. 다른 열을 골라 주세요.`);
|
||||
return;
|
||||
}
|
||||
@@ -157,16 +169,38 @@ function C4Board({ view: v, act, pending, tapConfirm }: BoardProps<ConnectFourVi
|
||||
<g
|
||||
key={i}
|
||||
className={anim ? 'c4-drop' : undefined}
|
||||
style={anim ? ({ '--c4-from': `${-(y + 1.5)}px`, '--c4-dur': `${0.16 + 0.06 * (y + 1)}s` } as React.CSSProperties) : undefined}
|
||||
style={anim ? ({ '--c4-from': `${-(y + 1.5)}px`, '--c4-dur': `${fallSec(y)}s` } as React.CSSProperties) : undefined}
|
||||
>
|
||||
<Disc color={c === 1 ? 'red' : 'yellow'} cx={x + 0.5} cy={y + 0.5} r={0.41} />
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
<rect x={-pad} y={-pad} width={cols + 2 * pad} height={rows + 2 * pad} rx={0.3} fill="var(--c4-frame)" stroke="var(--c4-frame-edge)" strokeWidth={0.05} mask={`url(#${maskId})`} />
|
||||
{last >= 0 && !winSet.size && <circle cx={(last % cols) + 0.5} cy={Math.floor(last / cols) + 0.5} r={0.09} fill="#fff" opacity={0.85} />}
|
||||
{[...winSet].map((i) => (
|
||||
<circle key={`w${i}`} className="c4-win" cx={(i % cols) + 0.5} cy={Math.floor(i / cols) + 0.5} r={0.36} fill="none" stroke="#fff" strokeWidth={0.1} />
|
||||
{last >= 0 && !winSet.size && (
|
||||
// Shown once the falling disc has landed.
|
||||
<circle
|
||||
key={`lm${v.moveCount}`}
|
||||
className={falling.current === v.moveCount ? 'anim-pop' : undefined}
|
||||
style={{ '--anim-delay': `${fallSec(Math.floor(last / cols)) * 1000}ms`, transformBox: 'fill-box', transformOrigin: 'center' } as React.CSSProperties}
|
||||
cx={(last % cols) + 0.5}
|
||||
cy={Math.floor(last / cols) + 0.5}
|
||||
r={0.09}
|
||||
fill="#fff"
|
||||
opacity={0.85}
|
||||
/>
|
||||
)}
|
||||
{(v.winLine ?? []).map((p, k) => (
|
||||
<circle
|
||||
key={`w${p.x}-${p.y}`}
|
||||
className="c4-win"
|
||||
style={{ '--c4-delay': `${k * 120}ms` } as React.CSSProperties}
|
||||
cx={p.x + 0.5}
|
||||
cy={p.y + 0.5}
|
||||
r={0.36}
|
||||
fill="none"
|
||||
stroke="#fff"
|
||||
strokeWidth={0.1}
|
||||
/>
|
||||
))}
|
||||
{ghostCol !== null && v.myColor && <Disc color={v.myColor} cx={ghostCol + 0.5} cy={-0.55} r={0.41} ghost={preview === null} />}
|
||||
{myTurn && kbd && <rect x={cursor + 0.04} y={-1.08} width={0.92} height={rows + 1.04} rx={0.12} fill="none" stroke="var(--focus)" strokeWidth={0.07} />}
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { OmokOptions, OmokView, Pt } from '@bg/games/omok';
|
||||
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, sfx } from '../../lib/feedback';
|
||||
import { BOARD_MOTION_CSS, useAnimOver, useMoveDiff } from '../board-motion';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -23,6 +24,7 @@ function stars(size: number): Pt[] {
|
||||
function Stone({ color, cx, cy, r, ghost }: { color: Color; cx: number; cy: number; r: number; ghost?: boolean }) {
|
||||
return (
|
||||
<g opacity={ghost ? 0.55 : 1}>
|
||||
{!ghost && <ellipse cx={cx + r * 0.1} cy={cy + r * 0.16} rx={r} ry={r * 0.96} fill="#000" opacity={0.22} />}
|
||||
<circle cx={cx} cy={cy} r={r} fill={color === 'black' ? '#151515' : '#fbfbf8'} stroke={color === 'black' ? '#000' : '#666'} strokeWidth={0.06} />
|
||||
{color === 'black' ? (
|
||||
<circle cx={cx - r * 0.3} cy={cy - r * 0.3} r={r * 0.28} fill="#fff" opacity={0.15} />
|
||||
@@ -46,18 +48,20 @@ function OmokBoard({ view: v, act, pending, tapConfirm }: BoardProps<OmokView>)
|
||||
const prevTurn = useRef(v.turn);
|
||||
|
||||
const forbidden = useMemo(() => new Set(v.forbidden.map((p) => p.y * n + p.x)), [v.forbidden, n]);
|
||||
// What the board was before the last change: a new stone sets down, stones taken back by 무르기 fade away.
|
||||
const { before, forward } = useMoveDiff(v.board, v.moveCount);
|
||||
const lifted = before && !forward ? before.flatMap((c, i) => (c !== 0 && v.board[i] === 0 ? [{ i, color: (c === 1 ? 'black' : 'white') as Color }] : [])) : [];
|
||||
const fresh = !!before && forward;
|
||||
const [liftedOver, liftedEnd] = useAnimOver(v.moveCount);
|
||||
|
||||
// Sounds, vibration and screen-reader announcements on new moves.
|
||||
// Sounds, vibration and screen-reader announcements on new moves (mine, the opponent's and the computer's).
|
||||
useEffect(() => {
|
||||
if (v.moveCount > prevCount.current && v.lastMove) {
|
||||
sounds.stone();
|
||||
sfx.stone();
|
||||
const who = v.moves[v.moves.length - 1]!.color;
|
||||
setAnnounce(`${COLOR_KO[who]}이 ${label(n, v.lastMove)}에 두었어요.`);
|
||||
}
|
||||
if (v.phase === 'playing' && myTurn && (prevTurn.current !== v.turn || v.moveCount === 0) && v.moveCount !== prevCount.current) {
|
||||
haptic(40);
|
||||
if (document.visibilityState === 'hidden') sounds.myTurn();
|
||||
}
|
||||
} else if (v.moveCount < prevCount.current) sfx.whoosh();
|
||||
if (v.phase === 'playing' && myTurn && (prevTurn.current !== v.turn || v.moveCount === 0) && v.moveCount !== prevCount.current) haptic(40);
|
||||
prevCount.current = v.moveCount;
|
||||
prevTurn.current = v.turn;
|
||||
setPreview(null);
|
||||
@@ -77,6 +81,7 @@ function OmokBoard({ view: v, act, pending, tapConfirm }: BoardProps<OmokView>)
|
||||
if (!myTurn || v.board[p.y * n + p.x] !== 0) return;
|
||||
if (forbidden.has(p.y * n + p.x)) {
|
||||
haptic([30, 30, 30]);
|
||||
sfx.bad();
|
||||
setAnnounce('여기는 금수 자리라 둘 수 없어요.');
|
||||
return;
|
||||
}
|
||||
@@ -113,11 +118,11 @@ function OmokBoard({ view: v, act, pending, tapConfirm }: BoardProps<OmokView>)
|
||||
}
|
||||
};
|
||||
|
||||
const winSet = new Set((v.winLine ?? []).map((p) => p.y * n + p.x));
|
||||
const ghost = preview ?? (hover && canPlace(hover) ? hover : null);
|
||||
const pad = 0.9;
|
||||
return (
|
||||
<div className="board-wrap stack" style={{ gap: 10 }}>
|
||||
<style>{BOARD_MOTION_CSS}</style>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
viewBox={`${-pad} ${-pad} ${n - 1 + 2 * pad} ${n - 1 + 2 * pad}`}
|
||||
@@ -165,10 +170,40 @@ function OmokBoard({ view: v, act, pending, tapConfirm }: BoardProps<OmokView>)
|
||||
<line x1={p.x + 0.2} y1={p.y - 0.2} x2={p.x - 0.2} y2={p.y + 0.2} />
|
||||
</g>
|
||||
))}
|
||||
{v.board.map((c, i) => (c === 0 ? null : <Stone key={i} color={c === 1 ? 'black' : 'white'} cx={i % n} cy={Math.floor(i / n)} r={0.46} />))}
|
||||
{v.lastMove && <circle cx={v.lastMove.x} cy={v.lastMove.y} r={0.13} fill="#ef4444" />}
|
||||
{[...winSet].map((i) => (
|
||||
<circle key={`win${i}`} cx={i % n} cy={Math.floor(i / n)} r={0.5} fill="none" stroke="#22c55e" strokeWidth={0.1} />
|
||||
{v.board.map((c, i) => {
|
||||
if (c === 0) return null;
|
||||
// The newest stone is keyed by the move number so it sets down again even on a re-used point (after 무르기).
|
||||
const isLast = fresh && v.lastMove !== null && i === v.lastMove.y * n + v.lastMove.x;
|
||||
return (
|
||||
<g key={isLast ? `m${v.moveCount}` : i} className={isLast ? 'bm-place' : undefined}>
|
||||
<Stone color={c === 1 ? 'black' : 'white'} cx={i % n} cy={Math.floor(i / n)} r={0.46} />
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{!liftedOver &&
|
||||
lifted.map(({ i, color }) => (
|
||||
<g key={`u${v.moveCount}-${i}`} className="bm-gone" onAnimationEnd={liftedEnd}>
|
||||
<Stone color={color} cx={i % n} cy={Math.floor(i / n)} r={0.46} />
|
||||
</g>
|
||||
))}
|
||||
{v.lastMove && (
|
||||
<g key={`lm${v.moveCount}`}>
|
||||
{fresh && <circle className="bm-ring" cx={v.lastMove.x} cy={v.lastMove.y} r={0.5} fill="none" stroke="#ef4444" strokeWidth={0.06} />}
|
||||
<circle className={fresh ? 'anim-pop' : undefined} style={{ animationDelay: '0.2s', transformBox: 'fill-box', transformOrigin: 'center' }} cx={v.lastMove.x} cy={v.lastMove.y} r={0.13} fill="#ef4444" />
|
||||
</g>
|
||||
)}
|
||||
{(v.winLine ?? []).map((p, k) => (
|
||||
<circle
|
||||
key={`win${p.x}-${p.y}`}
|
||||
className="bm-win"
|
||||
style={{ '--bm-delay': `${k * 110}ms` } as React.CSSProperties}
|
||||
cx={p.x}
|
||||
cy={p.y}
|
||||
r={0.5}
|
||||
fill="none"
|
||||
stroke="#22c55e"
|
||||
strokeWidth={0.1}
|
||||
/>
|
||||
))}
|
||||
{ghost && v.myColor && <Stone color={v.myColor} cx={ghost.x} cy={ghost.y} r={0.46} ghost />}
|
||||
{myTurn && kbd && <rect x={cursor.x - 0.5} y={cursor.y - 0.5} width={1} height={1} fill="none" stroke="var(--focus)" strokeWidth={0.06} />}
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { OthelloLegalMove, OthelloOptions, OthelloView } from '@bg/games/ot
|
||||
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, sfx, tone } from '../../lib/feedback';
|
||||
import { BOARD_MOTION_CSS } from '../board-motion';
|
||||
import { toast } from '../../store/toast';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
@@ -20,19 +21,29 @@ const COLOR_KO: Record<Color, string> = { black: '흑', white: '백' };
|
||||
const other = (c: Color): Color => (c === 'black' ? 'white' : 'black');
|
||||
const label = (p: Pt) => `${'abcdefgh'[p.x]}${p.y + 1}`;
|
||||
const FLIP_MS = 240;
|
||||
/** The placed disc lands first; the flips start right after. */
|
||||
const PLACE_MS = 140;
|
||||
|
||||
const CSS = `
|
||||
@keyframes oth-flip { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.05); } 100% { transform: scaleX(1); } }
|
||||
/* A disc is lifted a little while it turns over (edge-on in the middle), then set back down. */
|
||||
@keyframes oth-flip { 0% { transform: scale(1); } 50% { transform: scale(0.05, 1.14) translateY(-6%); } 100% { transform: scale(1); } }
|
||||
@keyframes oth-old { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
|
||||
@keyframes oth-drop { 0% { transform: scale(0.4); opacity: 0.4; } 100% { transform: scale(1); opacity: 1; } }
|
||||
.oth-flip { transform-box: fill-box; transform-origin: center; animation: oth-flip ${FLIP_MS}ms ease-in-out both; }
|
||||
.oth-old { animation: oth-old ${FLIP_MS}ms linear both; }
|
||||
.oth-drop { transform-box: fill-box; transform-origin: center; animation: oth-drop 160ms ease-out both; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.oth-flip, .oth-drop { animation: none; }
|
||||
.oth-flip { animation: none; }
|
||||
.oth-old { display: none; }
|
||||
}`;
|
||||
|
||||
/** Disc set down, then one light click per disc as it turns over (staggered like the animation). */
|
||||
function placeSound(flipDelays: number[]) {
|
||||
sfx.stone();
|
||||
flipDelays
|
||||
.sort((a, b) => a - b)
|
||||
.slice(0, 10)
|
||||
.forEach((d, k) => tone(1500 + (k % 4) * 90, 30, 'triangle', 0.06, d + FLIP_MS / 2));
|
||||
}
|
||||
|
||||
function Disc({ color, cx, cy, r = 0.4, ghost }: { color: Color; cx: number; cy: number; r?: number; ghost?: boolean }) {
|
||||
const black = color === 'black';
|
||||
return (
|
||||
@@ -74,6 +85,7 @@ function OthelloBoard({ view: v, act, pending, tapConfirm }: BoardProps<OthelloV
|
||||
prevCount.current = v.moveCount;
|
||||
setPreview(null);
|
||||
if (v.moveCount <= prev) {
|
||||
if (v.moveCount < prev) sfx.whoosh();
|
||||
setAnim(null);
|
||||
return;
|
||||
}
|
||||
@@ -95,16 +107,17 @@ function OthelloBoard({ view: v, act, pending, tapConfirm }: BoardProps<OthelloV
|
||||
setAnnounce(texts.join(' '));
|
||||
const lm = v.lastMove;
|
||||
if (lm && added.some((m) => m.kind === 'place')) {
|
||||
sounds.stone();
|
||||
const dist = (i: number) => Math.max(Math.abs((i % N) - lm.x), Math.abs(Math.floor(i / N) - lm.y));
|
||||
const maxD = Math.max(1, ...lm.flipped.map(dist));
|
||||
const step = maxD > 1 ? Math.min(60, (400 - FLIP_MS) / (maxD - 1)) : 0;
|
||||
setAnim({ key: v.moveCount, at: lm.y * N + lm.x, from: other(lm.color), delay: new Map(lm.flipped.map((i) => [i, (dist(i) - 1) * step])) });
|
||||
} else setAnim(null);
|
||||
if (v.phase === 'playing' && v.myColor === v.turn) {
|
||||
haptic(40);
|
||||
if (document.visibilityState === 'hidden') sounds.myTurn();
|
||||
const delay = new Map(lm.flipped.map((i) => [i, PLACE_MS + (dist(i) - 1) * step]));
|
||||
placeSound([...delay.values()]);
|
||||
setAnim({ key: v.moveCount, at: lm.y * N + lm.x, from: other(lm.color), delay });
|
||||
} else {
|
||||
if (added.length) sfx.whoosh();
|
||||
setAnim(null);
|
||||
}
|
||||
if (v.phase === 'playing' && v.myColor === v.turn) haptic(40);
|
||||
}, [v.moveCount]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const canPlace = (p: Pt) => myTurn && !pending && legal.has(p.y * N + p.x);
|
||||
@@ -178,7 +191,7 @@ function OthelloBoard({ view: v, act, pending, tapConfirm }: BoardProps<OthelloV
|
||||
|
||||
return (
|
||||
<div className="board-wrap stack" style={{ gap: 10 }}>
|
||||
<style>{CSS}</style>
|
||||
<style>{BOARD_MOTION_CSS + CSS}</style>
|
||||
<div
|
||||
aria-label={`돌 수: 흑 ${v.discs.black}개, 백 ${v.discs.white}개`}
|
||||
role="img"
|
||||
@@ -263,7 +276,7 @@ function OthelloBoard({ view: v, act, pending, tapConfirm }: BoardProps<OthelloV
|
||||
}
|
||||
if (anim && anim.at === i) {
|
||||
return (
|
||||
<g key={`a${anim.key}-${i}`} className="oth-drop">
|
||||
<g key={`a${anim.key}-${i}`} className="bm-place">
|
||||
<Disc color={color} cx={cx} cy={cy} />
|
||||
</g>
|
||||
);
|
||||
@@ -273,7 +286,12 @@ function OthelloBoard({ view: v, act, pending, tapConfirm }: BoardProps<OthelloV
|
||||
{[...flipSet].map((i) => (
|
||||
<circle key={`h${i}`} cx={(i % N) + 0.5} cy={Math.floor(i / N) + 0.5} r={0.44} fill="rgba(255, 224, 102, 0.45)" stroke="#ffd84d" strokeWidth={0.05} />
|
||||
))}
|
||||
{v.lastMove && <circle cx={v.lastMove.x + 0.5} cy={v.lastMove.y + 0.5} r={0.1} fill="#ef4444" stroke="#fff" strokeWidth={0.025} />}
|
||||
{v.lastMove && (
|
||||
<g key={`lm${v.moveCount}`}>
|
||||
{anim && anim.at === v.lastMove.y * N + v.lastMove.x && <circle className="bm-ring" cx={v.lastMove.x + 0.5} cy={v.lastMove.y + 0.5} r={0.48} fill="none" stroke="#ffd84d" strokeWidth={0.05} />}
|
||||
<circle cx={v.lastMove.x + 0.5} cy={v.lastMove.y + 0.5} r={0.1} fill="#ef4444" stroke="#fff" strokeWidth={0.025} />
|
||||
</g>
|
||||
)}
|
||||
{showGhost && target && v.myColor && <Disc color={v.myColor} cx={target.x + 0.5} cy={target.y + 0.5} ghost />}
|
||||
{myTurn && kbd && <rect x={cursor.x + 0.04} y={cursor.y + 0.04} width={0.92} height={0.92} rx={0.08} fill="none" stroke="var(--focus)" strokeWidth={0.07} />}
|
||||
</svg>
|
||||
|
||||
Reference in New Issue
Block a user