/** 요트 다이스 화면 (docs/games/yacht.md §9). */ import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'; import type { Category, ScoreEntry, YachtOptions, YachtSheetView, YachtView } from '@bg/games/yacht'; import type { PublicUser } from '@bg/shared/lite'; import { Avatar, ConfirmSheet } from '../../components/ui'; import { TurnTimer } from '../../components/TurnTimer'; import { haptic, noise, sfx, tone } from '../../lib/feedback'; import type { BoardProps, GameUI, OptionsProps } from '../types'; import { helpNow } from './help'; import { quickStart } from './quick'; import { fxMs, useMotionHold } from '../../lib/motion'; // The client draws from the view only; names and hints live here so the rules module isn't bundled. const NAME: Record = { ones: '에이스', twos: '듀스', threes: '트레이', fours: '포', fives: '파이브', sixes: '식스', choice: '초이스', threeKind: '쓰리 카인드', fourKind: '포 카인드', fullHouse: '풀 하우스', smallStraight: '스몰 스트레이트', largeStraight: '라지 스트레이트', yacht: '요트', }; const UPPER: Category[] = ['ones', 'twos', 'threes', 'fours', 'fives', 'sixes']; const catName = (c: Category, scoring: YachtOptions['scoring']) => (c === 'choice' && scoring === 'yahtzee' ? '찬스' : NAME[c]); const ROLL_MS = 600; const nick = (players: Record, id: string) => players[id]?.nickname ?? '알 수 없음'; const userOf = (players: Record, id: string): PublicUser => players[id] ?? { id, nickname: '알 수 없음', avatar: null, kind: 'guest' }; const reducedMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches; // ---------------------------------------------------------------- sounds (docs/games/yacht.md §9 소리·움직임) /** Dice rattled in the cup, then each rolled die clacking down as the tumble animation ends. */ function rollSound(n: number, animated: boolean) { if (!animated) return sfx.dice(); for (let i = 0; i < 7; i++) noise(30, 0.1, i * 50, 'bandpass', 1600 + (i % 3) * 350, 3); const land = ROLL_MS - 110; for (let i = 0; i < Math.min(n, 5); i++) { noise(45, 0.13, land + i * 28, 'lowpass', 1100); tone(680 + i * 70, 30, 'triangle', 0.05, land + i * 28); } } /** Die set aside (lower knock) or put back in the cup (lighter tick). */ function holdSound(on: boolean) { if (on) { tone(520, 45, 'triangle', 0.13); noise(25, 0.06, 0, 'lowpass', 1800); } else tone(780, 40, 'triangle', 0.1); } /** Pencil scribble on the score sheet. */ function writeSound() { for (let i = 0; i < 3; i++) noise(45, 0.07, i * 55, 'highpass', 3500 + i * 300); tone(990, 70, 'triangle', 0.08, 170); } /** A zero crossed into a box. */ function zeroSound() { noise(160, 0.07, 0, 'lowpass', 500); tone(260, 180, 'triangle', 0.08, 0, { slideTo: 180 }); } /** "Your turn" chime (the room page already plays one when the tab is hidden). */ function turnCue(delay: number) { tone(660, 120, 'sine', 0.13, delay); tone(880, 160, 'sine', 0.13, delay + 120); } /** Wraps a number that should bump when it changes (not on the first render). */ function Bump({ value, children }: { value: number; children: ReactNode }) { const r = useRef({ v: value, n: 0 }); if (r.current.v !== value) r.current = { v: value, n: r.current.n + 1 }; return ( {children} ); } const CSS = ` .yt-wrap { width: 100%; max-width: 1080px; display: flex; flex-direction: column; gap: 12px; } .yt-tray { display: flex; flex-direction: column; gap: 12px; align-items: stretch; } .yt-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; } .yt-dice { display: flex; gap: 8px; justify-content: center; padding: 6px 0 18px; } .yt-die { --s: 64px; width: var(--s); height: var(--s); padding: 0; border-radius: 14px; border: 3px solid #c9c4b8; background: #fffdf8; box-shadow: 0 3px 0 #b7b1a3, 0 4px 10px rgba(0,0,0,.15); cursor: pointer; position: relative; transition: transform .15s ease, border-color .15s; flex: none; } .yt-die svg { display: block; width: 100%; height: 100%; } .yt-die:disabled { cursor: default; } .yt-die.held { transform: translateY(14px); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft), 0 3px 8px rgba(0,0,0,.15); } .yt-die.blank { background: var(--surface-2); border-style: dashed; box-shadow: none; } .yt-die:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; } .yt-lock { position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); background: var(--primary); color: var(--primary-text); font-size: .72rem; font-weight: 800; border-radius: 999px; padding: 1px 7px; white-space: nowrap; line-height: 1.4; } @keyframes yt-tumble { 0% { transform: translateY(-18px) rotate(-30deg) scale(.9); } 40% { transform: translateY(4px) rotate(200deg); } 70% { transform: translateY(-6px) rotate(330deg); } 100% { transform: translateY(0) rotate(360deg); } } .yt-die.rolling { animation: yt-tumble ${ROLL_MS}ms ease-out both; } .yt-flash { position: fixed; inset: 0; z-index: 30; pointer-events: none; display: flex; align-items: center; justify-content: center; padding-bottom: 18vh; } .yt-flash > div { font-size: clamp(2.4rem, 10vw, 4rem); font-weight: 900; line-height: 1.1; text-align: center; white-space: nowrap; color: #fde047; text-shadow: 0 4px 12px rgba(0,0,0,.55), 0 0 2px #854d0e; } .yt-flash small { display: block; font-size: .4em; color: #fff; } .yt-flash.sub > div { font-size: clamp(1.8rem, 7vw, 2.8rem); } .yt-roll { min-height: 64px; font-size: 1.2rem; } .yt-sheet { padding: 0; overflow: auto; } .yt-table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; } .yt-table th, .yt-table td { height: 38px; padding: 0 6px; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; } .yt-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; height: 46px; font-size: .9rem; } .yt-table th.yt-cat { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 700; padding-left: 12px; min-width: 112px; } .yt-table thead th.yt-cat { z-index: 3; } .yt-table td { min-width: 56px; } .yt-table td.mine { background: var(--primary-soft); min-width: 72px; font-size: 1.08rem; } .yt-table th.turn { box-shadow: inset 0 -4px 0 var(--focus); } .yt-table tr.yt-sum th, .yt-table tr.yt-sum td { background: var(--surface-2); font-weight: 700; font-size: .92rem; } .yt-table tr.yt-sum td.mine { background: var(--primary-soft); } .yt-table tr.yt-total th, .yt-table tr.yt-total td { font-weight: 900; font-size: 1.1rem; border-bottom: 0; height: 44px; } .yt-filled { font-weight: 800; } .yt-ghost { color: var(--text-sub); opacity: .75; font-weight: 600; } .yt-cell { width: 100%; height: 34px; border-radius: 8px; border: 2px dashed var(--border); background: var(--surface); color: var(--text-sub); font: inherit; font-weight: 700; cursor: pointer; } .yt-cell.good { border-style: solid; border-color: var(--success); color: var(--success); background: var(--success-soft); } .yt-cell.zero { opacity: .6; } .yt-cell:hover:not(:disabled) { border-color: var(--primary); color: var(--text); } .yt-cell:disabled { cursor: not-allowed; opacity: .35; } .yt-cell:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; } @keyframes yt-new { from { background: #fde68a; color: #1c1e21; } to { background: transparent; } } .yt-new { display: inline-block; min-width: 2em; animation: yt-new 1.6s ease-out, anim-bump .35s ease; border-radius: 6px; } .yt-new.zero { animation: yt-new 1.6s ease-out, anim-shake .4s ease; } .yt-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; } .yt-bar > span { display: block; height: 100%; background: var(--success); transition: width .3s; } .yt-pname { display: inline-block; max-width: 72px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; } /* PC: fill the play column. Dice tray (left) and score sheet (right) take the full height; dice grow with the tray, the sheet's rows stretch to the column height and its text grows with it. */ @media (min-width: 1100px) { .yt-wrap { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); max-width: none; flex: 1 1 auto; min-height: 0; align-self: stretch; } /* Head on top; dice, roll button and notes centred in the rest of the tray. */ .yt-tray > :last-child { margin-bottom: auto; } .yt-dice { --s: clamp(64px, min(calc((var(--play-w) - 12px) * .5 / 6.4), calc(var(--play-h) * .12)), 150px); margin-top: auto; gap: clamp(8px, calc(var(--play-w) * .008), 18px); padding-bottom: calc(var(--s) * .3); } .yt-die { --s: inherit; border-radius: calc(var(--s) * .22); } .yt-die.held { transform: translateY(calc(var(--s) * .2)); } .yt-lock { font-size: clamp(.72rem, calc(var(--s) * .14), .95rem); bottom: calc(var(--s) * -.14); } .yt-roll { min-height: clamp(64px, calc(var(--play-h) * .075), 84px); font-size: clamp(1.2rem, calc(var(--play-h) * .022), 1.5rem); } .yt-sheet { max-height: 100%; } .yt-table { height: 100%; font-size: clamp(1rem, calc(var(--play-h) * .017), 1.25rem); } .yt-table th, .yt-table td { height: 34px; } .yt-table thead th { font-size: .9em; } .yt-table td.mine { font-size: 1.08em; } .yt-table tr.yt-sum th, .yt-table tr.yt-sum td { font-size: .92em; } .yt-table tr.yt-total th, .yt-table tr.yt-total td { font-size: 1.1em; } .yt-cell { height: clamp(30px, calc(var(--play-h) * .04), 44px); } } @media (prefers-reduced-motion: reduce) { .yt-die, .yt-die.held { transition: none; } .yt-die.rolling, .yt-new, .yt-flash .anim-banner { animation: none; } } `; // ---------------------------------------------------------------- dice const PIPS: Record = { 1: [[50, 50]], 2: [[28, 28], [72, 72]], 3: [[26, 26], [50, 50], [74, 74]], 4: [[28, 28], [72, 28], [28, 72], [72, 72]], 5: [[26, 26], [74, 26], [50, 50], [26, 74], [74, 74]], 6: [[28, 24], [72, 24], [28, 50], [72, 50], [28, 76], [72, 76]], }; function DieFace({ value }: { value: number | null }) { return ( {value !== null && PIPS[value]!.map(([x, y], i) => )} ); } /** Small static die for the rules / last-score line. */ function MiniDie({ value, size = 26 }: { value: number; size?: number }) { return ( ); } function DiceRow({ dice, size }: { dice: number[]; size?: number }) { return ( {dice.map((d, i) => ( ))} ); } // ---------------------------------------------------------------- board interface RollAnim { key: number; mask: boolean[]; /** All five the same: the 요트! flash waits until the dice have landed. */ yacht?: { sub?: string }; } function YachtBoard({ view: v, me, players, act, pending, tapConfirm }: BoardProps) { const myTurn = v.phase === 'playing' && !!me && v.current === me; const [held, setHeld] = useState(v.held); const [anim, setAnim] = useState(null); const [flick, setFlick] = useState(null); const [flash, setFlash] = useState<{ text: string; sub?: string; key: number } | null>(null); const [announce, setAnnounce] = useState(''); const [confirm, setConfirm] = useState<{ category: Category; points: number } | null>(null); const prevRoll = useRef(v.rollSeq); const prevTurn = useRef(v.turnSeq); const prevCurrent = useRef(v.current); const prevScore = useRef(v.lastScore ? `${v.lastScore.player}:${v.lastScore.category}` : ''); const prevUpper = useRef>(Object.fromEntries(Object.entries(v.sheets).map(([p, sh]) => [p, sh.upperBonus]))); const prevHold = useRef({ seq: `${v.turnSeq}:${v.rollSeq}`, held: v.held.join() }); const pointer = useRef(''); // Server holds win once our own pending action is answered (optimistic taps in between). useEffect(() => { if (!pending) setHeld(v.held); }, [v.held, v.turnSeq, v.rollSeq, pending]); const yachtFlash = (sub: string | undefined, key: number) => { setFlash({ text: '요트!', sub, key }); sfx.fanfare(); haptic([80, 40, 80]); }; // Roll animation, sound, yacht flash and screen-reader text when a new roll arrives (anyone's roll). useLayoutEffect(() => { if (v.rollSeq <= prevRoll.current || !v.dice) { prevRoll.current = v.rollSeq; return; } prevRoll.current = v.rollSeq; const who = v.current === me ? '내가' : `${nick(players, v.current ?? '')}님이`; setAnnounce(`${who} 굴렸어요: ${v.dice.join(', ')}`); const mask = v.rollsUsed === 1 ? [true, true, true, true, true] : v.held.map((h) => !h); const animated = !reducedMotion(); rollSound(mask.filter(Boolean).length, animated); const yacht = v.dice.every((d) => d === v.dice![0]) ? { sub: v.current === me ? undefined : nick(players, v.current ?? '') } : undefined; if (animated) setAnim({ key: v.rollSeq, mask, yacht }); else if (yacht) yachtFlash(yacht.sub, v.rollSeq); }, [v.rollSeq]); // eslint-disable-line react-hooks/exhaustive-deps // Someone else (re)holding dice: the same knock I hear on my own taps. useEffect(() => { const seq = `${v.turnSeq}:${v.rollSeq}`; const h = v.held.join(); const p = prevHold.current; prevHold.current = { seq, held: h }; if (p.seq !== seq || p.held === h || v.current === me) return; holdSound(v.held.filter(Boolean).length >= p.held.split(',').filter((x) => x === 'true').length); }, [v.held, v.turnSeq, v.rollSeq]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { if (!anim) return; const t = setInterval(() => setFlick([0, 1, 2, 3, 4].map(() => 1 + Math.floor(Math.random() * 6))), 70); const end = setTimeout(() => { setAnim(null); setFlick(null); if (anim.yacht) yachtFlash(anim.yacht.sub, anim.key); }, fxMs(ROLL_MS)); return () => { clearInterval(t); clearTimeout(end); }; }, [anim]); // eslint-disable-line react-hooks/exhaustive-deps // The tumble is staged with timers (flicking faces): results wait for it. useMotionHold(!!anim); useEffect(() => { if (!flash) return; const t = setTimeout(() => setFlash(null), fxMs(1600)); return () => clearTimeout(t); }, [flash]); // Score sound/banner/announcement + my-turn cue on turn changes (anyone's score). useEffect(() => { if (v.turnSeq === prevTurn.current) return; prevTurn.current = v.turnSeq; setConfirm(null); const ls = v.lastScore; const key = ls ? `${ls.player}:${ls.category}` : ''; if (ls && key !== prevScore.current) { const who = ls.player === me ? '내가' : `${nick(players, ls.player)}님이`; setAnnounce(`${who} ${catName(ls.category, v.options.scoring)}에 ${ls.points}점을 기록했어요${ls.bonus ? ` (요트 보너스 +${ls.bonus})` : ''}${ls.auto ? ' (시간 초과로 자동 기록)' : ''}.`); const big = ls.bonus > 0 || (ls.points > 0 && (ls.category === 'yacht' || ls.category === 'largeStraight')); if (ls.points === 0 && !ls.bonus) zeroSound(); else writeSound(); if (big) sfx.good(); const gotUpper = (v.sheets[ls.player]?.upperBonus ?? 0) > 0 && !(prevUpper.current[ls.player] ?? 0); if (gotUpper) { sfx.collect(); setFlash({ text: '상단 보너스 +35', sub: ls.player === me ? undefined : nick(players, ls.player), key: v.turnSeq }); } else if (ls.bonus) setFlash({ text: `요트 보너스 +${ls.bonus}`, sub: ls.player === me ? undefined : nick(players, ls.player), key: v.turnSeq }); } prevScore.current = key; prevUpper.current = Object.fromEntries(Object.entries(v.sheets).map(([p, sh]) => [p, sh.upperBonus])); const mineNow = v.phase === 'playing' && v.current === me; if (mineNow) haptic(40); // Only when the turn comes back from someone else; a hidden tab gets the room page's chime instead. if (mineNow && prevCurrent.current !== me && document.visibilityState === 'visible') turnCue(350); prevCurrent.current = v.current; }, [v.turnSeq]); // eslint-disable-line react-hooks/exhaustive-deps const canRoll = myTurn && !pending && v.rollsUsed < 3 && !(v.rollsUsed > 0 && held.every(Boolean)); const canHold = myTurn && v.rollsUsed > 0 && v.rollsUsed < 3; const toggle = (i: number) => { if (!canHold) return; const next = held.map((h, j) => (j === i ? !h : h)); holdSound(next[i]!); setHeld(next); act({ type: 'hold', held: next }); }; const roll = () => { if (!canRoll) return; act({ type: 'roll' }); }; const score = (category: Category, points: number, viaMouse: boolean) => { if (!myTurn || pending) return; if (points === 0 || (tapConfirm && !viaMouse)) setConfirm({ category, points }); else act({ type: 'score', category }); }; const shownDice = v.dice ?? null; const rollLabel = v.rollsUsed >= 3 ? '점수 칸을 골라 주세요' : v.rollsUsed > 0 && held.every(Boolean) ? '모두 고정했어요' : `🎲 굴리기 (남은 ${v.rollsLeft}번)`; const curName = v.current ? (v.current === me ? '내' : `${nick(players, v.current)}님`) : ''; return (
{v.phase === 'finished' ? '게임 끝' : `${v.round} / ${v.totalRounds} 라운드`} {v.current && ( {curName} 차례 {'●'.repeat(v.rollsUsed)} {'○'.repeat(3 - v.rollsUsed)} )}
{[0, 1, 2, 3, 4].map((i) => { const value = shownDice ? (anim?.mask[i] && flick ? flick[i]! : shownDice[i]!) : null; const isHeld = !!shownDice && v.rollsUsed > 0 && held[i]!; const rolling = !!anim && anim.mask[i]; return ( ); })}
{myTurn ? ( ) : (

{v.phase === 'finished' ? '게임이 끝났어요' : v.current ? `${nick(players, v.current)}님이 굴리는 중이에요` : ''}

)} {myTurn && v.rollsUsed > 0 && v.rollsUsed < 3 &&

남길 주사위를 누르면 고정돼요. 점수표의 칸을 누르면 기록해요.

} {v.lastScore && }

{announce}

{flash && (
4 ? ' sub' : ''}`} aria-hidden>
{flash.text} {flash.sub && {flash.sub}}
)} {confirm && ( act({ type: 'score', category: confirm.category })} onClose={() => setConfirm(null)} /> )}
); } function LastScore({ entry: e, view: v, me, players }: { entry: ScoreEntry; view: YachtView; me: string | null; players: Record }) { return (

방금: {e.player === me ? '나' : nick(players, e.player)} → {catName(e.category, v.options.scoring)} {e.points}점{e.bonus ? ` +${e.bonus}` : ''} {e.auto ? ' (자동)' : ''}

); } // ---------------------------------------------------------------- score sheet function ScoreSheet({ view: v, me, players, myTurn, pending, rolling, onScore, pointer, }: { view: YachtView; me: string | null; players: Record; myTurn: boolean; pending: boolean; /** Dice still tumbling: the points they make are not shown (or pickable) until they land. */ rolling: boolean; onScore: (c: Category, points: number, viaMouse: boolean) => void; pointer: React.MutableRefObject; }) { // My column first (bigger), then everyone else in turn order. const cols = me && v.order.includes(me) ? [me, ...v.order.filter((p) => p !== me)] : v.order; const upper = v.categories.filter((c) => UPPER.includes(c)); const lower = v.categories.filter((c) => !UPPER.includes(c)); const ls = v.lastScore; const yz = v.options.scoring === 'yahtzee'; const cell = (p: string, c: Category) => { const sh = v.sheets[p]!; const val = sh.scores[c]; if (val !== undefined) { const fresh = ls && ls.player === p && ls.category === c; return ( {val} ); } const prev = v.current === p ? v.preview?.[c] : undefined; if (p === me && myTurn && v.rollsUsed > 0 && prev !== undefined) { const allowed = v.allowed.includes(c); const show = v.options.showPreview && !rolling; return ( ); } if (prev !== undefined && v.options.showPreview && !rolling) return {prev}; return null; }; const header = ( 칸 {cols.map((p) => { const sh = v.sheets[p]!; return ( {p === me ? '나' : nick(players, p)} {sh.left &&
기권
} {!sh.left && sh.away &&
자리 비움
} ); })} ); const row = (c: Category) => ( {catName(c, v.options.scoring)} {cols.map((p) => ( {cell(p, c)} ))} ); const sumRow = (label: string, f: (s: YachtSheetView) => React.ReactNode, cls = 'yt-sum') => ( {label} {cols.map((p) => ( {f(v.sheets[p]!)} ))} ); return (
{header} {upper.map(row)} {sumRow('소계', (s) => `${s.upper}/${v.upperBonusThreshold}`)} {sumRow('보너스 +35', (s) => (s.upperBonus ? `+${s.upperBonus}` : {`${Math.max(0, v.upperBonusThreshold - s.upper)} 남음`}))} {lower.map(row)} {yz && sumRow('요트 보너스', (s) => (s.yahtzeeBonus ? `+${s.yahtzeeBonus}` : '-'))} {sumRow('총점', (s) => {s.total}, 'yt-total')}
); } // ---------------------------------------------------------------- side panel function YachtSide({ view: v, me, players, act, deadline }: BoardProps) { const [ask, setAsk] = useState(false); const mine = me ? v.sheets[me] : undefined; const total = v.options.turnSeconds > 0 ? v.options.turnSeconds * 1000 : deadline ? Math.max(1000, deadline - v.turnStartedAt) : 60_000; return ( <>
{v.order.map((p, i) => { const sh = v.sheets[p]!; const turn = v.current === p; return (
{i + 1}
{nick(players, p)} {p === me && (나)}
{sh.left ? '기권' : sh.away ? '자리 비움' : turn ? '굴리는 중' : `${sh.filled}/${v.totalRounds}칸`}
{sh.total} {turn && v.phase === 'playing' && }
); })}
{mine && !mine.left && (
상단 보너스 {mine.upperBonus ? '35점 확보!' : `${v.upperBonusThreshold}까지 ${Math.max(0, v.upperBonusThreshold - mine.upper)}점 남음`}
)} {v.phase === 'playing' && mine && !mine.left && ( )} {ask && ( act({ type: 'concede' })} onClose={() => setAsk(false)} /> )} ); } // ---------------------------------------------------------------- status function isMyTurn(v: YachtView, me: string | null): boolean { return v.phase === 'playing' && !!me && v.current === me; } function statusText(v: YachtView, me: string | null, players: Record): string { if (v.phase === 'finished') return v.result?.summary ?? '게임이 끝났어요'; if (me && v.sheets[me]?.left) return '기권했어요. 구경하는 중이에요'; if (isMyTurn(v, me)) { if (v.rollsUsed === 0) return '내 차례예요. 주사위를 굴려 주세요'; if (v.rollsUsed < 3) return `내 차례예요. 다시 굴리거나(${v.rollsLeft}번 남음) 칸을 골라 주세요`; return '내 차례예요. 점수를 넣을 칸을 골라 주세요'; } return v.current ? `${nick(players, v.current)}님 차례예요 · ${v.round}/${v.totalRounds}라운드` : '잠시만 기다려 주세요'; } // ---------------------------------------------------------------- options function Seg({ value, options, onChange }: { value: T; options: [T, string][]; onChange: (v: T) => void }) { return (
{options.map(([k, l]) => ( ))}
); } function Field({ label, children }: { label: string; children: React.ReactNode }) { return (
{label} {children}
); } function Options({ value: o, onChange }: OptionsProps) { const set = (patch: Partial) => onChange({ ...o, ...patch }); return (
set({ scoring })} /> {o.scoring === 'yacht51' ? ( set({ fullHouseAllowsYacht: k === 'on' })} /> ) : ( set({ yahtzeeJoker })} /> )} set({ turnSeconds })} /> set({ showPreview: k === 'on' })} />
); } function optionsSummary(o: YachtOptions): string { return [ o.scoring === 'yacht51' ? '요트 12칸' : '13칸 변형', ...(o.scoring === 'yacht51' && !o.fullHouseAllowsYacht ? ['풀 하우스에 요트 불인정'] : []), ...(o.scoring === 'yahtzee' ? [o.yahtzeeJoker === 'forced' ? '추가 요트는 정해진 순서' : '추가 요트는 아무 칸'] : []), o.turnSeconds > 0 ? `한 차례 ${o.turnSeconds}초` : '시간 무제한', ...(o.showPreview ? [] : ['미리 보기 끔']), ].join(' · '); } // ---------------------------------------------------------------- rules function Rules({ options }: { options?: YachtOptions }) { const yz = options?.scoring === 'yahtzee'; const fhYacht = options?.fullHouseAllowsYacht ?? true; const rows: [string, string, number[]][] = yz ? [ ['에이스~식스', '그 눈이 나온 주사위의 합', [6, 6, 6, 2, 1]], ['쓰리 카인드', '같은 눈 3개 이상이면 5개 합', [4, 4, 4, 2, 5]], ['포 카인드', '같은 눈 4개 이상이면 5개 합', [3, 3, 3, 3, 6]], ['풀 하우스', '같은 눈 3개 + 다른 같은 눈 2개면 25점', [2, 2, 5, 5, 5]], ['스몰 스트레이트', '이어지는 눈 4개면 30점', [1, 2, 3, 4, 6]], ['라지 스트레이트', '이어지는 눈 5개면 40점', [2, 3, 4, 5, 6]], ['요트', '5개 모두 같은 눈이면 50점', [5, 5, 5, 5, 5]], ['찬스', '아무 조합이나 5개 합', [6, 5, 4, 4, 2]], ] : [ ['에이스~식스', '그 눈이 나온 주사위의 합', [6, 6, 6, 2, 1]], ['초이스', '아무 조합이나 5개 합', [6, 5, 4, 4, 2]], ['포 카인드', '같은 눈 4개 이상이면 5개 합', [3, 3, 3, 3, 6]], ['풀 하우스', `같은 눈 3개 + 다른 같은 눈 2개면 5개 합${fhYacht ? '(5개 모두 같아도 인정)' : ''}`, [2, 2, 5, 5, 5]], ['스몰 스트레이트', '이어지는 눈 4개면 15점', [1, 2, 3, 4, 6]], ['라지 스트레이트', '이어지는 눈 5개면 30점', [2, 3, 4, 5, 6]], ['요트', '5개 모두 같은 눈이면 50점', [5, 5, 5, 5, 5]], ]; return (

주사위 5개를 한 차례에 최대 3번 굴려요. 마음에 드는 주사위는 눌러서 고정하고 나머지만 다시 굴릴 수 있어요. 고정은 굴릴 때마다 바꿀 수 있어요.

굴린 뒤에는 점수표의 빈 칸 하나를 골라 지금 주사위로 점수를 적어요. 조건에 맞지 않는 칸에 넣으면 0점이에요. 한 번 적은 칸은 바꿀 수 없고, 3번 굴린 뒤에는 꼭 적어야 해요.

{yz ? '13칸' : '12칸'}을 모두 채우면 끝나고, 총점이 가장 높은 사람이 이겨요. 혼자서 최고 점수에 도전할 수도 있어요.

{rows.map(([name, rule, dice]) => (
{name} · {rule}
))}

상단 보너스: 에이스~식스 6칸의 합이 63점 이상이면 35점을 더 받아요(눈마다 3개씩 모으면 딱 63점이에요).

{yz && (

추가 요트: 요트 칸에 50점을 적은 뒤 요트가 또 나오면 100점을 더 받아요.{' '} {options?.yahtzeeJoker === 'free' ? '이때는 아무 빈 칸에나 적을 수 있어요.' : '이때는 그 눈의 윗칸이 비어 있으면 거기에 먼저 적어야 하고, 윗칸이 차 있으면 아래쪽 칸에 적어요.'}{' '} 그 눈의 윗칸이 이미 차 있으면 풀 하우스 25점, 스트레이트 30·40점을 조건과 상관없이 인정해요.

)}

시간 안에 적지 않으면 지금 주사위로 가장 높은 점수가 나오는 칸에 자동으로 적혀요(아직 안 굴렸으면 먼저 굴려요). 기권하면 남은 칸은 모두 0점이 돼요.

); } const ui: GameUI = { Board: YachtBoard, Side: YachtSide, statusText, isMyTurn, Options, optionsSummary, Rules, quickStart, helpNow, }; export default ui;