도둑잡기(old-maid): 규칙·화면·컴퓨터 상대·테스트·문서·E2E
- 규칙 모듈 packages/games/src/old-maid: 2~8명, 트럼프 52장 + 조커 1장을 첫 사람(무작위)부터 한 장씩 나누고 같은 숫자 짝은 자동으로 버림. 차례에는 다음 자리(왼쪽)의 카드 있는 사람 손패에서 자리(index)로 한 장 뽑기(from 함께 보내 대상이 바뀌면 거절), 짝이 없으면 내 손패 무작위 자리에 숨김. 다 턴 순서대로 순위, 마지막 조커를 든 사람이 도둑(꼴찌). 결과 scoreText 에 "🃏 도둑"/"다 털었어요"/"나감" 표시. - 내 손패 섞기: 남은 사람 누구나 언제든, 차례마다 3번까지, 시계는 그대로. 남에게 보이는 자리는 실제 손패 순서이고, view 에는 남의 손패 장수만(뽑은 카드는 뽑은 사람에게만). - 시간 초과는 무작위 한 장 뽑기(3번 연속이면 5초), 카드를 든 채 나가면 그 카드를 섞어 다음 자리부터 한 장씩 나눠 주고 짝을 버림, 나간 사람은 맨 아래. 둘만 남았을 때 나가면 도둑 없이 끝. - 컴퓨터 상대(BOT_GAMES): 단계와 관계없이 무작위로 뽑고 가끔(15%) 자기 손패를 먼저 섞음. - 화면 apps/web/src/games/old-maid: 뽑힐 사람의 뒷면 카드를 펼쳐 고르기(tapConfirm 이면 두 번 눌러 확인, PC 한 번, 키보드 방향키+Enter), 섞으면 흔들림, 지난 뽑기·버린 짝, 내 손패(조커 표시)와 [🔀 섞기], 조커를 넘기면 알림. 30초 요약, 지금 할 수 있는 것, 규칙. - 등록(GAMES, 카탈로그, BOT_GAMES·전략, 화면 레지스트리, 아이콘·카드 탭), 도움말 테스트 게임 수 27, 문서 docs/games/old-maid.md, E2E 계획(PC 1 + 휴대폰 2, 끝까지). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
48
apps/web/src/games/old-maid/help.test.ts
Normal file
48
apps/web/src/games/old-maid/help.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
|
||||
import { GAMES } from '@bg/games';
|
||||
import { helpNow } from './help';
|
||||
|
||||
const ids = ['A', 'B', 'C'];
|
||||
const users = usersOf(ids);
|
||||
const view = (s: unknown, who: string | null) => GAMES['old-maid']!.view(s, who) as any;
|
||||
const nickOf = (id: string) => users[id]!.nickname;
|
||||
|
||||
/** Rigged 3-player game: A draws from B, B from C, C from A. Unlisted cards count as thrown away. */
|
||||
function rigged(hands: Record<string, string[]>, turn = 'A') {
|
||||
const { state } = setupGame('old-maid', 3);
|
||||
for (const p of ids) {
|
||||
state.hands[p] = hands[p];
|
||||
state.discards[p] = [];
|
||||
}
|
||||
state.out = [];
|
||||
state.turn = turn;
|
||||
return state;
|
||||
}
|
||||
|
||||
test('도둑잡기: 내 차례 / 뽑히는 사람 / 기다림 / 관전', () => {
|
||||
const s = rigged({ A: ['2H', '3H'], B: ['2S', 'X1'], C: ['3S', '4H', '4S'] });
|
||||
const a = helpNow(view(s, 'A'), 'A', users);
|
||||
expect(a).toContain(`내 차례예요. ${nickOf('B')}님의 뒷면 카드 2장`);
|
||||
expect(a).toContain('도둑');
|
||||
const b = helpNow(view(s, 'B'), 'B', users);
|
||||
expect(b).toContain(`${nickOf('A')}님이 내 카드를 고르는 중`);
|
||||
expect(b).toContain('조커가 내 손에 있어요! [🔀 섞기]');
|
||||
expect(helpNow(view(s, 'C'), 'C', users)).toContain('기다려 주세요');
|
||||
expect(helpNow(view(s, null), null, users)).toContain(`${nickOf('A')}님이 ${nickOf('B')}님의 카드를 고르는 중`);
|
||||
});
|
||||
|
||||
test('도둑잡기: 다 털고 구경, 게임 끝(도둑)', () => {
|
||||
let s = rigged({ A: ['2H', '3H'], B: ['2S', 'X1'], C: ['3S'] });
|
||||
s = applyAction('old-maid', s, 'A', { type: 'draw', from: 'B', index: 0 }); // 2H·2S 짝 → A [3H], B [X1]
|
||||
s = applyAction('old-maid', s, 'B', { type: 'draw', from: 'C', index: 0 }); // B [X1, 3S], C 다 털어서 1등
|
||||
expect(helpNow(view(s, 'C'), 'C', users)).toContain('1등이에요');
|
||||
expect(s.turn).toBe('A');
|
||||
s = applyAction('old-maid', s, 'A', { type: 'draw', from: 'B', index: s.hands.B.indexOf('3S') }); // A 2등, B 도둑
|
||||
expect(s.final.thief).toBe('B');
|
||||
expect(helpNow(view(s, 'B'), 'B', users)).toContain('내가 조커를 끝까지 들고 있어서 도둑');
|
||||
const a = helpNow(view(s, 'A'), 'A', users);
|
||||
expect(a).toContain(`${nickOf('B')}님이 조커를 끝까지`);
|
||||
expect(a).toContain('나는 2등으로');
|
||||
expect(helpNow(view(s, null), null, users)).toContain('게임이 끝났어요');
|
||||
});
|
||||
42
apps/web/src/games/old-maid/help.ts
Normal file
42
apps/web/src/games/old-maid/help.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/** 도둑잡기 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
|
||||
import type { OldMaidView } from '@bg/games/old-maid';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
|
||||
const JOKER = 'X1';
|
||||
|
||||
export function helpNow(v: OldMaidView, me: string | null, players: Record<string, PublicUser>): string {
|
||||
const mine = me && v.order.includes(me) ? me : null;
|
||||
const name = (id: string) => `${players[id]?.nickname ?? '다른 사람'}님`;
|
||||
const goal = '같은 숫자 두 장은 저절로 짝으로 버려져요. 손패를 먼저 다 털면 이기고, 마지막에 조커를 든 사람이 도둑(꼴찌)이에요.';
|
||||
|
||||
if (v.phase === 'finished') {
|
||||
const f = v.final;
|
||||
if (!f) return '게임이 끝났어요.';
|
||||
const thief = f.thief ? (f.thief === mine ? '내가 조커를 끝까지 들고 있어서 도둑이 됐어요.' : `${name(f.thief)}이 조커를 끝까지 들고 있어서 도둑이에요.`) : '한 사람이 나가서 도둑 없이 끝났어요.';
|
||||
const place = mine && v.places[mine] ? `나는 ${v.places[mine]}등으로 손패를 다 털었어요!` : null;
|
||||
return ['게임이 끝났어요.', thief, place].filter(Boolean).join('\n');
|
||||
}
|
||||
|
||||
const lines: string[] = [];
|
||||
const turn = v.turn!;
|
||||
const target = v.target;
|
||||
const hand = mine ? (v.myHand ?? []) : [];
|
||||
if (mine && v.status[mine] === 'out') {
|
||||
lines.push(`나는 손패를 다 털어서 ${v.places[mine]}등이에요! 끝날 때까지 구경해요.`);
|
||||
lines.push(`지금은 ${name(turn)}이 ${target ? `${name(target)}의` : ''} 카드를 고르는 중이에요.`);
|
||||
return lines.join('\n');
|
||||
}
|
||||
if (mine && v.status[mine] === 'left') return '게임을 나가서 구경만 할 수 있어요.';
|
||||
if (turn === mine && target) {
|
||||
lines.push(`내 차례예요. ${name(target)}의 뒷면 카드 ${v.handCounts[target]}장 중 한 장을 골라 뽑아요.`);
|
||||
lines.push('카드를 누르면 골라지고, 한 번 더 누르면 뽑아요(PC는 한 번 누르면 바로 뽑아요). 짝이 생기면 저절로 버려져요.');
|
||||
} else if (target === mine) {
|
||||
lines.push(`${name(turn)}이 내 카드를 고르는 중이에요.`);
|
||||
lines.push(hand.includes(JOKER) ? '조커가 내 손에 있어요! [🔀 섞기]로 순서를 바꿔 조커를 숨겨 보세요.' : '[🔀 섞기]로 내 손패 순서를 바꿀 수 있어요.');
|
||||
} else {
|
||||
lines.push(`${name(turn)}이 ${target ? `${name(target)}의 카드를` : '카드를'} 고르는 중이에요.${mine ? ' 기다려 주세요.' : ''}`);
|
||||
if (mine && hand.includes(JOKER)) lines.push('조커가 내 손에 있어요. 내 카드를 뽑을 사람이 가져가길 기다려요.');
|
||||
}
|
||||
lines.push(goal);
|
||||
return lines.join('\n');
|
||||
}
|
||||
653
apps/web/src/games/old-maid/index.tsx
Normal file
653
apps/web/src/games/old-maid/index.tsx
Normal file
@@ -0,0 +1,653 @@
|
||||
/** 도둑잡기 화면 (docs/games/old-maid.md §9). Cards are the shared trump card SVGs. */
|
||||
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import type { LogEntry, OldMaidOptions, OldMaidView } from '@bg/games/old-maid';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { PlayingCard, cardAria } from '../../components/cards/PlayingCard';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { toast } from '../../store/toast';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
|
||||
// Kept local (type-only import above) so the screen chunk does not pull in the rules module + zod.
|
||||
const JOKER = 'X1';
|
||||
const SHUFFLES_PER_TURN = 3;
|
||||
|
||||
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' };
|
||||
const who = (players: Record<string, PublicUser>, id: string, me: string | null) => (id === me ? '나' : `${nick(players, id)}님`);
|
||||
|
||||
/** "♥7", "조커". */
|
||||
function cardName(c: string): string {
|
||||
if (c.startsWith('X')) return '조커';
|
||||
const r = c[0]!;
|
||||
return `${{ S: '♠', H: '♥', D: '◆', C: '♣' }[c[1]!] ?? ''}${r === 'T' ? '10' : r}`;
|
||||
}
|
||||
|
||||
function logText(e: LogEntry, players: Record<string, PublicUser>, me: string | null): string {
|
||||
switch (e.t) {
|
||||
case 'draw': {
|
||||
const base = `${who(players, e.drawer, me)}${e.drawer === me ? '는' : '이'} ${who(players, e.from, me)}의 ${e.index + 1}번째 카드를 뽑았어요`;
|
||||
const pair = e.pair ? ` → ${cardName(e.pair[0])}·${cardName(e.pair[1])} 짝을 버렸어요` : '';
|
||||
return `${base}${pair}${e.auto ? ' (시간 초과)' : ''}`;
|
||||
}
|
||||
case 'out':
|
||||
return `${who(players, e.player, me)}${e.player === me ? '는' : '이'} 손패를 다 털었어요! ${e.place}등`;
|
||||
case 'shuffle':
|
||||
return `${who(players, e.player, me)}${e.player === me ? '는' : '이'} 손패를 섞었어요`;
|
||||
case 'left':
|
||||
return `${nick(players, e.player)}님이 나가서 카드를 ${e.gave.map((g) => `${who(players, g.to, me)}에게 ${g.count}장`).join(', ') || '아무에게도 안'} 나눠 줬어요${e.pairs.length ? ` (짝 ${e.pairs.length}쌍 버림)` : ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- styles
|
||||
|
||||
const CSS = `
|
||||
.om-board { width: 100%; max-width: 1040px; max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px; }
|
||||
.om-seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
|
||||
.om-seat { position: relative; background: var(--surface); border-radius: var(--radius-lg); padding: 8px 10px; box-shadow: var(--shadow); border: 3px solid transparent; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
|
||||
.om-seat.turn { border-color: var(--focus); }
|
||||
.om-seat.target { border-color: var(--primary); border-style: dashed; }
|
||||
.om-seat.done { opacity: .72; }
|
||||
.om-seat.thief { border-color: var(--danger); opacity: 1; }
|
||||
.om-head { display: flex; align-items: center; gap: 7px; min-height: 30px; min-width: 0; }
|
||||
.om-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
|
||||
.om-badges { display: flex; gap: 4px; flex-wrap: wrap; min-height: 22px; }
|
||||
.om-badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-weight: 800; font-size: .78rem; background: var(--surface-2); color: var(--text); white-space: nowrap; }
|
||||
.om-badge.turn { background: var(--focus); color: #1c1e21; }
|
||||
.om-badge.target { background: var(--primary-soft); color: var(--text); }
|
||||
.om-badge.win { background: var(--success-soft); color: var(--success); }
|
||||
.om-badge.lose { background: var(--danger-soft); color: var(--danger); }
|
||||
.om-meta { font-size: .85rem; color: var(--text-sub); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||
.om-mini { display: inline-flex; align-items: center; }
|
||||
.om-mini i { width: 12px; height: 17px; border-radius: 3px; background: #1e3a8a; border: 1.5px solid #fff; box-shadow: 0 0 0 1px #1e3a8a; margin-left: -6px; display: inline-block; }
|
||||
.om-mini i:first-child { margin-left: 0; }
|
||||
.om-bubble { position: absolute; right: 8px; top: -12px; background: var(--text); color: var(--surface); border-radius: 12px; padding: 2px 10px; font-weight: 800; font-size: .8rem; box-shadow: var(--shadow); animation: om-pop .25s ease-out; z-index: 2; }
|
||||
.om-table { background: var(--felt); color: #fff; border-radius: var(--radius-lg); padding: 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; min-height: 200px; }
|
||||
.om-table .small { color: #fff; opacity: .92; }
|
||||
.om-title { font-weight: 900; font-size: 1.05rem; text-align: center; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
|
||||
.om-title .arrow { opacity: .85; }
|
||||
.om-fan { --cw: 60px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 14px 4px 4px; max-width: 760px; }
|
||||
.om-fan.many { --cw: 50px; gap: 5px; }
|
||||
.om-fan.shake { animation: om-shake .5s ease-in-out; }
|
||||
.om-back { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); padding: 0; border: 0; background: none; border-radius: 9px; cursor: default; transition: transform .12s ease; }
|
||||
button.om-back { cursor: pointer; }
|
||||
button.om-back:hover:not(:disabled) { transform: translateY(-5px); }
|
||||
.om-back[aria-pressed='true'] { transform: translateY(-12px); box-shadow: 0 0 0 4px #fde047; z-index: 2; }
|
||||
.om-back:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; z-index: 3; }
|
||||
.om-back:disabled { cursor: default; }
|
||||
.om-back .om-no { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; font-weight: 800; border-radius: 6px; padding: 0 4px; pointer-events: none; }
|
||||
.om-face { display: block; width: 100%; height: 100%; }
|
||||
.om-face svg, .om-face > span { width: 100% !important; height: 100% !important; display: block; }
|
||||
.om-last { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.22); border-radius: 12px; padding: 8px 10px; width: 100%; flex-wrap: wrap; justify-content: center; }
|
||||
.om-last .cards { display: flex; gap: 4px; }
|
||||
.om-last .cards .om-card { --cw: 40px; }
|
||||
.om-card { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); display: inline-block; }
|
||||
.om-pile { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; align-items: center; font-size: .85rem; }
|
||||
.om-pile .pair { display: inline-flex; gap: 2px; }
|
||||
.om-pile .om-card { --cw: 28px; }
|
||||
.om-me { position: relative; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 10px 12px; border: 3px solid var(--primary); display: flex; flex-direction: column; gap: 8px; }
|
||||
.om-me.turn { border-color: var(--focus); }
|
||||
.om-me.target { border-style: dashed; }
|
||||
.om-me .om-bubble { right: auto; left: 16px; top: -14px; }
|
||||
.om-hand { --cw: 64px; display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.om-hand.many { --cw: 52px; }
|
||||
.om-hand .om-card.joker { box-shadow: 0 0 0 3px var(--danger); border-radius: 9px; }
|
||||
.om-hand .om-card.fresh { animation: om-pop .45s ease-out; box-shadow: 0 0 0 3px #f59e0b; border-radius: 9px; }
|
||||
.om-mine { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
|
||||
.om-shuffle { min-height: 44px; }
|
||||
.om-note { font-size: .85rem; color: var(--text-sub); }
|
||||
.om-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .88rem; }
|
||||
@keyframes om-pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
|
||||
@keyframes om-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px) rotate(-1deg); } 40% { transform: translateX(8px) rotate(1deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
|
||||
@media (max-width: 719px) {
|
||||
.om-board { max-height: none; overflow: visible; }
|
||||
.om-seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
|
||||
.om-seat { padding: 6px 8px; }
|
||||
.om-fan { --cw: 46px; gap: 5px; }
|
||||
.om-fan.many { --cw: 44px; gap: 4px; }
|
||||
.om-hand { --cw: 50px; gap: 5px; }
|
||||
.om-hand.many { --cw: 44px; gap: 4px; }
|
||||
.om-table { min-height: 0; padding: 10px 8px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.om-fan.shake, .om-bubble, .om-hand .om-card.fresh { animation: none; }
|
||||
.om-back, .om-back[aria-pressed='true'] { transition: none; }
|
||||
}
|
||||
`;
|
||||
|
||||
// ---------------------------------------------------------------- pieces
|
||||
|
||||
function Card({ card, className }: { card: string | null; className?: string }) {
|
||||
return (
|
||||
<span className={`om-card${className ? ` ${className}` : ''}`} aria-hidden>
|
||||
<span className="om-face">
|
||||
<PlayingCard card={card} size="lg" style={{ width: '100%', height: '100%', filter: 'none' }} />
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function MiniBacks({ n }: { n: number }) {
|
||||
return (
|
||||
<span className="om-mini" aria-hidden>
|
||||
{Array.from({ length: Math.min(n, 8) }, (_, i) => (
|
||||
<i key={i} />
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function seatLabel(v: OldMaidView, id: string, me: string | null, players: Record<string, PublicUser>): string {
|
||||
const st = v.status[id];
|
||||
const parts = [`${nick(players, id)}님${id === me ? '(나)' : ''}`];
|
||||
if (st === 'out') parts.push(`다 털었어요, ${v.places[id]}등`);
|
||||
else if (st === 'left') parts.push('나갔어요');
|
||||
else parts.push(`카드 ${v.handCounts[id]}장`);
|
||||
parts.push(`버린 짝 ${v.pairCounts[id]}쌍`);
|
||||
if (v.turn === id) parts.push('뽑는 차례');
|
||||
if (v.target === id) parts.push('카드를 뽑히는 중');
|
||||
if (v.final?.thief === id) parts.push('도둑');
|
||||
if (v.away[id]) parts.push('자리 비움');
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
function Seat({ id, v, me, players, deadline, bubble }: { id: string; v: OldMaidView; me: string | null; players: Record<string, PublicUser>; deadline: number | null; bubble: string | null }) {
|
||||
const u = userOf(players, id);
|
||||
const st = v.status[id];
|
||||
const thief = v.final?.thief === id;
|
||||
const cls = ['om-seat', v.turn === id ? 'turn' : '', v.target === id ? 'target' : '', st !== 'playing' && !thief ? 'done' : '', thief ? 'thief' : ''].filter(Boolean).join(' ');
|
||||
return (
|
||||
<section className={cls} aria-label={seatLabel(v, id, me, players)}>
|
||||
{bubble && (
|
||||
<span className="om-bubble" aria-hidden>
|
||||
{bubble}
|
||||
</span>
|
||||
)}
|
||||
<div className="om-head">
|
||||
<Avatar user={u} size={26} />
|
||||
<span className="om-name">{u.nickname}</span>
|
||||
{v.turn === id && <TurnTimer deadline={deadline} totalMs={v.turnMs} mine={false} size={30} />}
|
||||
</div>
|
||||
<div className="om-badges" aria-hidden>
|
||||
{v.turn === id && <span className="om-badge turn">뽑는 중</span>}
|
||||
{v.target === id && <span className="om-badge target">{v.turn === me ? '여기서 뽑아요' : '뽑히는 중'}</span>}
|
||||
{st === 'out' && <span className="om-badge win">🎉 {v.places[id]}등</span>}
|
||||
{st === 'left' && <span className="om-badge">나감</span>}
|
||||
{thief && <span className="om-badge lose">🃏 도둑</span>}
|
||||
{v.away[id] && <span className="om-badge">자리 비움</span>}
|
||||
</div>
|
||||
<div className="om-meta" aria-hidden>
|
||||
{st === 'playing' || thief ? (
|
||||
<>
|
||||
<MiniBacks n={v.handCounts[id] ?? 0} />
|
||||
<span>{v.handCounts[id]}장</span>
|
||||
</>
|
||||
) : (
|
||||
<span>{st === 'out' ? '다 털었어요' : '나갔어요'}</span>
|
||||
)}
|
||||
<span>· 짝 {v.pairCounts[id]}</span>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** The face-down hand of the player being drawn from. Interactive only for the drawer. */
|
||||
function Fan({ v, me, players, act, pending, tapConfirm, shake }: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; shake: boolean }) {
|
||||
const target = v.target!;
|
||||
const mine = !!v.my?.canDraw && v.my.from === target;
|
||||
const count = mine ? v.my!.count : (v.handCounts[target] ?? 0);
|
||||
const [sel, setSel] = useState<number | null>(null);
|
||||
// A new turn, or the owner shuffled / the fan changed: start over.
|
||||
useEffect(() => setSel(null), [v.turnNo, target, count, v.shuffles[target]]);
|
||||
const draw = (index: number) => {
|
||||
if (pending) return;
|
||||
act({ type: 'draw', from: target, index });
|
||||
setSel(null);
|
||||
};
|
||||
const tap = (i: number) => {
|
||||
if (!mine) return;
|
||||
if (sel === i || !tapConfirm) draw(i);
|
||||
else setSel(i);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key === 'Escape') {
|
||||
setSel(null);
|
||||
return;
|
||||
}
|
||||
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
||||
const btns = Array.from(e.currentTarget.querySelectorAll<HTMLButtonElement>('button.om-back'));
|
||||
const i = btns.indexOf(document.activeElement as HTMLButtonElement);
|
||||
if (i < 0) return;
|
||||
e.preventDefault();
|
||||
btns[(i + (e.key === 'ArrowRight' ? 1 : btns.length - 1)) % btns.length]?.focus();
|
||||
};
|
||||
const owner = who(players, target, me);
|
||||
return (
|
||||
<div
|
||||
className={`om-fan${count > 12 ? ' many' : ''}${shake ? ' shake' : ''}`}
|
||||
role="group"
|
||||
aria-label={mine ? `${owner}의 뒤집힌 카드 ${count}장. 좌우 방향키로 고르고 Enter로 뽑아요` : `${owner}의 뒤집힌 카드 ${count}장`}
|
||||
onKeyDown={onKey}
|
||||
>
|
||||
{Array.from({ length: count }, (_, i) =>
|
||||
mine ? (
|
||||
<button
|
||||
key={i}
|
||||
type="button"
|
||||
className="om-back"
|
||||
aria-pressed={sel === i}
|
||||
disabled={pending}
|
||||
aria-label={`${i + 1}번째 카드${sel === i ? '. 한 번 더 누르면 뽑아요' : ''}`}
|
||||
onClick={() => tap(i)}
|
||||
>
|
||||
<span className="om-face" aria-hidden>
|
||||
<PlayingCard card={null} size="lg" style={{ width: '100%', height: '100%', filter: 'none' }} />
|
||||
</span>
|
||||
<span className="om-no" aria-hidden>
|
||||
{i + 1}
|
||||
</span>
|
||||
</button>
|
||||
) : (
|
||||
<span key={i} className="om-back" aria-hidden>
|
||||
<span className="om-face">
|
||||
<PlayingCard card={null} size="lg" style={{ width: '100%', height: '100%', filter: 'none' }} />
|
||||
</span>
|
||||
</span>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LastDraw({ v, me, players }: { v: OldMaidView; me: string | null; players: Record<string, PublicUser> }) {
|
||||
const d = v.lastDraw;
|
||||
if (!d) return null;
|
||||
const mineDraw = d.drawer === me;
|
||||
const text = `${who(players, d.drawer, me)}${mineDraw ? '는' : '이'} ${who(players, d.from, me)}의 ${d.index + 1}번째 카드를 뽑았어요${d.auto ? '(시간 초과)' : ''}`;
|
||||
let tail: string;
|
||||
if (d.pair) tail = `${cardName(d.pair[0])}·${cardName(d.pair[1])} 짝을 버렸어요`;
|
||||
else if (mineDraw && d.card) tail = d.card === JOKER ? '앗, 조커를 뽑았어요!' : `뽑은 카드 ${cardName(d.card)} · 짝이 없어서 손에 넣었어요`;
|
||||
else tail = '짝이 없어서 손에 넣었어요';
|
||||
return (
|
||||
<div className="om-last" role="status" aria-label={`${text}. ${tail}`}>
|
||||
{(d.pair || (mineDraw && d.card)) && (
|
||||
<span className="cards" aria-hidden>
|
||||
{d.pair ? d.pair.map((c) => <Card key={c} card={c} />) : <Card card={d.card} />}
|
||||
</span>
|
||||
)}
|
||||
<span className="small" style={{ lineHeight: 1.45 }} aria-hidden>
|
||||
{text}
|
||||
<br />
|
||||
<strong>{tail}</strong>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Pile({ v }: { v: OldMaidView }) {
|
||||
const pairs = v.log.flatMap((e) => (e.t === 'draw' && e.pair ? [e.pair] : e.t === 'left' ? e.pairs : [])).slice(-6);
|
||||
const total = Object.values(v.pairCounts).reduce((a, b) => a + b, 0);
|
||||
return (
|
||||
<div className="om-pile" aria-label={`버린 짝 모두 ${total}쌍${pairs.length ? `, 최근: ${pairs.map((p) => `${cardName(p[0])}·${cardName(p[1])}`).join(', ')}` : ''}`} role="group">
|
||||
<span>버린 짝 {total}쌍 / 26쌍</span>
|
||||
{pairs.map((p, i) => (
|
||||
<span key={i} className="pair" aria-hidden>
|
||||
<Card card={p[0]} />
|
||||
<Card card={p[1]} />
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Table(props: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; shake: boolean }) {
|
||||
const { v, me, players } = props;
|
||||
if (v.phase === 'finished') {
|
||||
const f = v.final!;
|
||||
return (
|
||||
<div className="om-table" role="group" aria-label="테이블">
|
||||
<strong className="om-title">게임이 끝났어요</strong>
|
||||
{f.thief ? (
|
||||
<>
|
||||
<Card card={JOKER} />
|
||||
<span style={{ textAlign: 'center', fontWeight: 800 }}>🃏 도둑: {who(players, f.thief, me)}</span>
|
||||
</>
|
||||
) : (
|
||||
<span style={{ textAlign: 'center' }}>한 사람이 나가서 도둑 없이 끝났어요.</span>
|
||||
)}
|
||||
<span className="small" style={{ textAlign: 'center' }}>
|
||||
{f.summary}
|
||||
</span>
|
||||
<LastDraw v={v} me={me} players={players} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const drawer = v.turn!;
|
||||
const target = v.target;
|
||||
return (
|
||||
<div className="om-table" role="group" aria-label="테이블">
|
||||
<div className="om-title">
|
||||
<span>{who(players, drawer, me)}</span>
|
||||
<span className="arrow" aria-hidden>
|
||||
←
|
||||
</span>
|
||||
<span>{target ? `${who(players, target, me)}의 카드 ${v.handCounts[target]}장` : ''}</span>
|
||||
</div>
|
||||
{target && <Fan {...props} />}
|
||||
{v.my?.canDraw ? (
|
||||
<span className="small" style={{ textAlign: 'center' }}>
|
||||
{props.tapConfirm ? '뽑을 카드를 눌러 고르고, 한 번 더 누르면 뽑아요.' : '뽑을 카드를 누르면 바로 뽑아요.'} 숫자는 왼쪽부터의 자리예요.
|
||||
</span>
|
||||
) : (
|
||||
<span className="small" style={{ textAlign: 'center' }}>
|
||||
{target === me ? `${who(players, drawer, me)}이 내 카드를 고르는 중이에요. 아래 [🔀 섞기]로 순서를 바꿀 수 있어요.` : `${who(players, drawer, me)}이 고르는 중이에요.`}
|
||||
</span>
|
||||
)}
|
||||
<LastDraw v={v} me={me} players={players} />
|
||||
<Pile v={v} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MyArea({ v, me, players, act, pending, deadline, fresh, bubble }: { v: OldMaidView; me: string; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; deadline: number | null; fresh: string | null; bubble: string | null }) {
|
||||
const hand = v.myHand ?? [];
|
||||
const st = v.status[me];
|
||||
const cls = ['om-me', v.turn === me ? 'turn' : '', v.target === me ? 'target' : ''].filter(Boolean).join(' ');
|
||||
return (
|
||||
<section className={cls} aria-label="내 자리">
|
||||
{bubble && (
|
||||
<span className="om-bubble" aria-hidden>
|
||||
{bubble}
|
||||
</span>
|
||||
)}
|
||||
<div className="om-head">
|
||||
<Avatar user={userOf(players, me)} size={26} />
|
||||
<span className="om-name">{nick(players, me)} (나)</span>
|
||||
{v.away[me] && <span className="om-badge">자리 비움</span>}
|
||||
{st === 'out' && <span className="om-badge win">🎉 {v.places[me]}등</span>}
|
||||
{v.final?.thief === me && <span className="om-badge lose">🃏 도둑</span>}
|
||||
{v.turn === me && <TurnTimer deadline={deadline} totalMs={v.turnMs} mine size={30} />}
|
||||
</div>
|
||||
<div className="om-mine">
|
||||
<strong>
|
||||
내 손패 {hand.length}장 · 버린 짝 {v.pairCounts[me]}쌍
|
||||
</strong>
|
||||
{v.phase === 'playing' && st === 'playing' && (
|
||||
<button type="button" className="btn btn-secondary om-shuffle" disabled={!v.my?.canShuffle || pending} onClick={() => act({ type: 'shuffle' })}>
|
||||
🔀 섞기{v.my ? ` (${v.my.shufflesLeft}/${SHUFFLES_PER_TURN})` : ''}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{hand.length > 0 ? (
|
||||
<div className={`om-hand${hand.length > 12 ? ' many' : ''}`} role="list" aria-label={`내 손패, 왼쪽부터: ${hand.map(cardAria).join(', ')}`}>
|
||||
{hand.map((c) => (
|
||||
<span key={c} role="listitem" aria-label={cardAria(c)} style={{ display: 'contents' }}>
|
||||
<Card card={c} className={[c === JOKER ? 'joker' : '', c === fresh ? 'fresh' : ''].filter(Boolean).join(' ')} />
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="om-note">{st === 'out' ? '손패를 다 털었어요! 끝날 때까지 구경해요.' : '손에 카드가 없어요.'}</span>
|
||||
)}
|
||||
{st === 'playing' && v.phase === 'playing' && (
|
||||
<span className="om-note">다른 사람에게는 이 순서 그대로 뒷면으로 보여요. 조커를 어디에 둘지 섞어서 숨겨 보세요.</span>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- board
|
||||
|
||||
function OldMaidBoard({ view: v, me, players, act, pending, deadline, tapConfirm }: BoardProps<OldMaidView>) {
|
||||
const amPlayer = !!me && v.order.includes(me);
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const [bubbles, setBubbles] = useState<Record<string, string>>({});
|
||||
const [shake, setShake] = useState(false);
|
||||
const [fresh, setFresh] = useState<string | null>(null);
|
||||
const prev = useRef({ logCount: v.logCount, hand: v.myHand ?? [], turn: v.turn });
|
||||
|
||||
useEffect(() => {
|
||||
const p = prev.current;
|
||||
// New public log entries since last time (the log keeps only the last 30).
|
||||
const n = Math.max(0, Math.min(v.log.length, v.logCount - p.logCount));
|
||||
const added = n ? v.log.slice(-n) : [];
|
||||
const msgs: string[] = [];
|
||||
const bub: Record<string, string> = {};
|
||||
let shook = false;
|
||||
for (const e of added) {
|
||||
msgs.push(logText(e, players, me));
|
||||
if (e.t === 'shuffle') {
|
||||
bub[e.player] = '🔀 섞었어요';
|
||||
if (e.player === v.target) shook = true;
|
||||
} else if (e.t === 'draw' && e.pair) bub[e.drawer] = '짝!';
|
||||
else if (e.t === 'out') bub[e.player] = '🎉 다 털었어요';
|
||||
}
|
||||
const hand = v.myHand ?? [];
|
||||
const ld = v.lastDraw;
|
||||
if (amPlayer && ld && added.some((e) => e.t === 'draw')) {
|
||||
if (ld.drawer === me && ld.card === JOKER) {
|
||||
toast('앗, 조커를 뽑았어요! 다른 사람이 가져가게 섞어 보세요.');
|
||||
haptic([40, 30, 40]);
|
||||
} else if (ld.from === me && p.hand.includes(JOKER) && !hand.includes(JOKER)) {
|
||||
toast('조커를 넘겼어요! 😆');
|
||||
haptic(40);
|
||||
}
|
||||
setFresh(ld.drawer === me && !ld.pair ? ld.card : null);
|
||||
}
|
||||
if (amPlayer && v.turn === me && p.turn !== me && v.phase === 'playing') {
|
||||
sounds.myTurn();
|
||||
haptic(40);
|
||||
msgs.push('내 차례예요.');
|
||||
}
|
||||
if (msgs.length) setAnnounce(msgs.join(' '));
|
||||
if (Object.keys(bub).length) {
|
||||
setBubbles((b) => ({ ...b, ...bub }));
|
||||
setTimeout(() => setBubbles((b) => Object.fromEntries(Object.entries(b).filter(([k]) => !(k in bub)))), 2500);
|
||||
}
|
||||
prev.current = { logCount: v.logCount, hand, turn: v.turn };
|
||||
if (shook) {
|
||||
setShake(true);
|
||||
const t = setTimeout(() => setShake(false), 550);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
return undefined;
|
||||
}, [v.seq]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const seats = amPlayer ? v.order.slice(v.order.indexOf(me!) + 1).concat(v.order.slice(0, v.order.indexOf(me!))) : v.order;
|
||||
return (
|
||||
<div className="om-board" role="region" aria-label="도둑잡기 판">
|
||||
<style>{CSS}</style>
|
||||
<div className="om-seats">
|
||||
{seats.map((p) => (
|
||||
<Seat key={p} id={p} v={v} me={me} players={players} deadline={deadline} bubble={bubbles[p] ?? null} />
|
||||
))}
|
||||
</div>
|
||||
<Table v={v} me={me} players={players} act={act} pending={pending} tapConfirm={tapConfirm} shake={shake} />
|
||||
{amPlayer && <MyArea v={v} me={me!} players={players} act={act} pending={pending} deadline={deadline} fresh={fresh} bubble={bubbles[me!] ?? null} />}
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- side
|
||||
|
||||
function OldMaidSide({ view: v, me, players, deadline }: BoardProps<OldMaidView>) {
|
||||
const running = v.phase === 'playing';
|
||||
const log = v.log.filter((e) => e.t !== 'shuffle').slice(-8).reverse();
|
||||
return (
|
||||
<>
|
||||
<style>{CSS}</style>
|
||||
<div className="card stack" style={{ gap: 8, padding: 12 }}>
|
||||
<div className="row" style={{ justifyContent: 'space-between' }}>
|
||||
<strong>{running ? `${nick(players, v.turn!)}님 차례` : '게임 끝'}</strong>
|
||||
{running && <TurnTimer deadline={deadline} totalMs={v.turnMs} mine={v.turn === me} size={36} />}
|
||||
</div>
|
||||
<span className="small muted">{optionsSummary(v.options)}</span>
|
||||
<ol style={{ listStyle: 'none', margin: 0, padding: 0, display: 'grid', gap: 6 }} aria-label="참가자(앉은 순서, 다음 사람에게서 뽑아요)">
|
||||
{v.order.map((p) => (
|
||||
<li key={p} className="row" style={{ gap: 6, flexWrap: 'nowrap', alignItems: 'center' }} aria-label={seatLabel(v, p, me, players)}>
|
||||
<Avatar user={userOf(players, p)} size={24} />
|
||||
<span style={{ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontWeight: p === me ? 800 : 600 }} aria-hidden>
|
||||
{nick(players, p)}
|
||||
{v.turn === p ? ' · 차례' : ''}
|
||||
{v.final?.thief === p ? ' · 🃏 도둑' : ''}
|
||||
</span>
|
||||
<span className="small muted" style={{ whiteSpace: 'nowrap' }} aria-hidden>
|
||||
{v.status[p] === 'out' ? `${v.places[p]}등` : v.status[p] === 'left' ? '나감' : `${v.handCounts[p]}장`}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
{v.final && (
|
||||
<div className="card stack" style={{ gap: 6, padding: 12 }}>
|
||||
<strong>결과</strong>
|
||||
<span>{v.final.thief ? `🃏 도둑은 ${who(players, v.final.thief, me)}${v.final.thief === me ? '예요' : '이에요'}.` : '한 사람이 나가서 끝났어요.'}</span>
|
||||
<ol className="om-log">
|
||||
{v.final.ranking.map((g, i) => (
|
||||
<li key={i}>
|
||||
<strong>{v.final!.ranking.slice(0, i).reduce((n, x) => n + x.length, 1)}등</strong> {g.map((p) => `${nick(players, p)}${p === v.final!.thief ? ' (도둑)' : v.status[p] === 'left' ? ' (나감)' : ''}`).join(', ')}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
)}
|
||||
{log.length > 0 && (
|
||||
<div className="card stack" style={{ gap: 6, padding: 12 }}>
|
||||
<strong>최근 기록</strong>
|
||||
<ol className="om-log" aria-label="최근 기록, 새 것부터">
|
||||
{log.map((e, i) => (
|
||||
<li key={i}>{logText(e, players, me)}</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
)}
|
||||
<details className="card" style={{ padding: 12 }} open={running}>
|
||||
<summary style={{ cursor: 'pointer', fontWeight: 700 }}>도움말</summary>
|
||||
<ul className="small" style={{ margin: '8px 0 0', paddingLeft: 18, display: 'grid', gap: 4 }}>
|
||||
<li>내 차례에는 다음 사람(왼쪽)의 뒷면 카드 중 한 장을 뽑아요.</li>
|
||||
<li>같은 숫자 두 장은 저절로 짝으로 버려져요(무늬는 상관없어요).</li>
|
||||
<li>손패를 먼저 다 털수록 높은 등수예요.</li>
|
||||
<li>마지막까지 조커를 든 사람이 도둑(꼴찌)이에요.</li>
|
||||
<li>[🔀 섞기]로 내 손패 순서를 섞을 수 있어요(차례마다 3번까지).</li>
|
||||
</ul>
|
||||
</details>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- status
|
||||
|
||||
function isMyTurn(v: OldMaidView, me: string | null): boolean {
|
||||
return !!me && v.phase === 'playing' && v.turn === me;
|
||||
}
|
||||
|
||||
function statusText(v: OldMaidView, me: string | null, players: Record<string, PublicUser>): string {
|
||||
if (v.phase === 'finished') return v.final?.summary ?? '게임이 끝났어요';
|
||||
const t = v.turn!;
|
||||
const target = v.target;
|
||||
if (isMyTurn(v, me)) return `내 차례예요. ${target ? `${nick(players, target)}님 카드에서 한 장 뽑아요` : '기다려 주세요'}`;
|
||||
if (target && target === me) return `${nick(players, t)}님이 내 카드를 고르는 중이에요`;
|
||||
return `${nick(players, t)}님이 ${target ? `${nick(players, target)}님 카드를 ` : ''}고르는 중이에요`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- options
|
||||
|
||||
function Seg<T extends string | number | boolean>({ 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]) => (
|
||||
<button key={String(k)} type="button" aria-pressed={value === k} onClick={() => onChange(k)}>
|
||||
{l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Field({ label, children }: { label: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className="stack" style={{ gap: 6 }}>
|
||||
<strong>{label}</strong>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Options({ value: o, onChange }: OptionsProps<OldMaidOptions>) {
|
||||
return (
|
||||
<div className="stack" style={{ gap: 16 }}>
|
||||
<Field label="한 번 뽑는 제한 시간">
|
||||
<Seg
|
||||
label="한 번 뽑는 제한 시간"
|
||||
value={o.turnSeconds}
|
||||
options={[
|
||||
[10, '10초'],
|
||||
[20, '20초'],
|
||||
[30, '30초'],
|
||||
[60, '60초'],
|
||||
]}
|
||||
onChange={(turnSeconds) => onChange({ ...o, turnSeconds })}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function optionsSummary(o: OldMaidOptions): string {
|
||||
return `트럼프 52장 + 조커 1장 · 제한 ${o.turnSeconds}초`;
|
||||
}
|
||||
|
||||
function Rules({ options }: { options?: OldMaidOptions }) {
|
||||
const row: CSSProperties = { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' };
|
||||
return (
|
||||
<div className="stack">
|
||||
<p>
|
||||
옆 사람 손패에서 한 장씩 몰래 뽑아 같은 숫자 짝을 버리다가, <strong>마지막에 조커를 들고 있는 사람이 도둑(꼴찌)</strong>이 되는 카드놀이예요. 2~8명이 할 수 있어요.
|
||||
</p>
|
||||
<div style={row} role="img" aria-label="하트 7과 스페이드 7은 짝이라 버리고, 조커는 짝이 없어요">
|
||||
<PlayingCard card="7H" size="sm" />
|
||||
<PlayingCard card="7S" size="sm" />
|
||||
<span aria-hidden>→ 짝! 버려요 ·</span>
|
||||
<PlayingCard card={JOKER} size="sm" />
|
||||
<span aria-hidden>짝 없음</span>
|
||||
</div>
|
||||
<p>
|
||||
<strong>준비</strong>: 트럼프 52장에 조커 1장을 넣은 53장을 섞어 모두에게 한 장씩 고르게 나눠요(한 장 차이는 괜찮아요). 먼저 나누어 받는 사람은 무작위로 정하고, 그 사람이 먼저 뽑아요. 나눈 뒤 각자 손에서 같은 숫자 두 장을 짝으로 모두
|
||||
버려요(무늬는 상관없어요). 이건 저절로 돼요.
|
||||
</p>
|
||||
<p>
|
||||
<strong>뽑기</strong>: 내 차례에는 다음 사람(왼쪽)이 뒷면으로 내민 카드 중 한 장을 골라 뽑아요. 뽑은 카드로 짝이 생기면 바로 버리고, 짝이 없으면 내 손에 넣어요(내 손패 아무 자리에 섞여 들어가요). 그다음 차례는 내가 뽑아 온 사람이에요.
|
||||
</p>
|
||||
<p>
|
||||
<strong>섞기</strong>: 언제든 [🔀 섞기]로 내 손패 순서를 섞을 수 있어요(차례마다 {SHUFFLES_PER_TURN}번까지). 다른 사람에게는 내 손패가 순서 그대로 뒷면으로 보이니, 조커를 숨길 때 써 보세요.
|
||||
</p>
|
||||
<p>
|
||||
<strong>끝</strong>: 손패를 다 턴 사람은 빠지고, 먼저 턴 순서대로 1등, 2등…이에요. 짝이 다 버려지면 조커 한 장만 남고, 그걸 든 사람이 도둑이에요.
|
||||
</p>
|
||||
<p className="muted">
|
||||
{options?.turnSeconds ?? 20}초 안에 고르지 않으면 무작위로 한 장을 뽑아요. 세 번 연속 시간을 넘기면 제한 시간이 5초로 줄어요. 카드를 든 채 게임을 나가면 그 사람 카드는 섞어서 남은 사람들에게 다음 자리부터 한 장씩 나눠 주고(짝이
|
||||
생기면 버려요), 나간 사람은 맨 아래 등수가 돼요. 둘만 남았을 때 한 사람이 나가면 도둑 없이 끝나요.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ui: GameUI<OldMaidView, OldMaidOptions> = {
|
||||
Board: OldMaidBoard,
|
||||
Side: OldMaidSide,
|
||||
statusText,
|
||||
isMyTurn,
|
||||
Options,
|
||||
optionsSummary,
|
||||
Rules,
|
||||
quickStart,
|
||||
helpNow,
|
||||
};
|
||||
|
||||
export default ui;
|
||||
51
apps/web/src/games/old-maid/quick.tsx
Normal file
51
apps/web/src/games/old-maid/quick.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
/** 도둑잡기 30초 규칙 요약 (docs/07 §5). */
|
||||
import { PlayingCard } from '../../components/cards/PlayingCard';
|
||||
import type { QuickCard } from '../types';
|
||||
|
||||
const row = { display: 'flex', alignItems: 'center', gap: 8 } as const;
|
||||
const label = { fontSize: 13, fontWeight: 800, color: '#374151', textAlign: 'center' } as const;
|
||||
|
||||
export const quickStart: QuickCard[] = [
|
||||
{
|
||||
pic: (
|
||||
<div style={row} aria-hidden>
|
||||
<div style={{ display: 'flex', gap: 4 }}>
|
||||
<PlayingCard card="7H" size="md" highlight />
|
||||
<PlayingCard card="7S" size="md" highlight />
|
||||
</div>
|
||||
<span style={{ fontSize: 26, fontWeight: 900 }}>→</span>
|
||||
<span style={{ background: '#15803d', color: '#fff', fontWeight: 900, fontSize: 18, borderRadius: 10, padding: '2px 12px' }}>짝! 버려요</span>
|
||||
</div>
|
||||
),
|
||||
alt: '하트 7과 스페이드 7이 짝이 되어 버려져요',
|
||||
title: '같은 숫자는 짝으로 버려요',
|
||||
text: '같은 숫자 두 장(무늬는 상관없어요)은 저절로 짝으로 버려져요. 손패를 먼저 다 털수록 높은 등수예요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<div style={{ ...row, flexDirection: 'column', gap: 6 }} aria-hidden>
|
||||
<div style={{ display: 'flex', gap: 4 }}>
|
||||
<PlayingCard card={null} size="sm" />
|
||||
<PlayingCard card={null} size="sm" selected />
|
||||
<PlayingCard card={null} size="sm" />
|
||||
<PlayingCard card={null} size="sm" />
|
||||
</div>
|
||||
<span style={label}>옆 사람의 뒷면 카드에서 한 장 뽑기</span>
|
||||
</div>
|
||||
),
|
||||
alt: '옆 사람의 뒤집힌 카드 네 장 중 두 번째 카드를 고른 모습',
|
||||
title: '옆 사람 카드를 한 장 뽑아요',
|
||||
text: '내 차례에는 다음 사람(왼쪽)의 뒷면 카드 중 한 장을 골라 뽑아요. 짝이 생기면 바로 버려져요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<div style={row} aria-hidden>
|
||||
<PlayingCard card="X1" size="lg" highlight />
|
||||
<span style={{ background: '#b91c1c', color: '#fff', fontWeight: 900, fontSize: 18, borderRadius: 10, padding: '2px 12px' }}>도둑!</span>
|
||||
</div>
|
||||
),
|
||||
alt: '조커 카드 한 장과 도둑이라는 빨간 글자',
|
||||
title: '조커를 든 사람이 도둑',
|
||||
text: '조커는 짝이 없어요. 마지막에 조커를 들고 있는 사람이 도둑(꼴찌)! [🔀 섞기]로 내 손패를 섞어 숨겨 보세요.',
|
||||
},
|
||||
];
|
||||
@@ -26,6 +26,7 @@ export const GAME_UI: Record<string, () => Promise<{ default: GameUI }>> = {
|
||||
'cockroach-poker': () => import('./cockroach-poker'),
|
||||
'ninety-nine': () => import('./ninety-nine'),
|
||||
'connect-four': () => import('./connect-four'),
|
||||
'old-maid': () => import('./old-maid'),
|
||||
dobble: () => import('./dobble'),
|
||||
catchmind: () => import('./catchmind'),
|
||||
mafia: () => import('./mafia'),
|
||||
|
||||
@@ -22,6 +22,7 @@ export const GAME_ICON: Record<string, string> = {
|
||||
'las-vegas': '⚅',
|
||||
'cockroach-poker': '🐞',
|
||||
'ninety-nine': '💯',
|
||||
'old-maid': '🤡',
|
||||
dobble: '👀',
|
||||
catchmind: '🖍️',
|
||||
mafia: '🌙',
|
||||
@@ -39,4 +40,7 @@ export const GAME_GROUPS: { key: string; label: string; ids: string[] }[] = [
|
||||
{ key: 'board', label: '판·주사위', ids: ['omok', 'connect-four', 'othello', 'chess', 'janggi', 'baduk', 'quoridor', 'yut', 'marble', 'yacht', 'las-vegas'] },
|
||||
{ key: 'cards', label: '카드·패', ids: ['seotda', 'poker', 'one-card', 'gostop', 'dalmuti', 'splendor', 'cockroach-poker', 'ninety-nine', 'mahjong', 'rummikub', 'davinci-code'] },
|
||||
{ key: 'party', label: '여럿이 파티', ids: ['bang', 'halli-galli', 'dobble', 'catchmind', 'mafia', 'apple'] },
|
||||
{ key: 'board', label: '판·주사위', ids: ['omok', 'othello', 'chess', 'janggi', 'baduk', 'quoridor', 'yut', 'marble', 'yacht', 'las-vegas'] },
|
||||
{ key: 'cards', label: '카드·패', ids: ['seotda', 'poker', 'one-card', 'gostop', 'dalmuti', 'splendor', 'cockroach-poker', 'ninety-nine', 'old-maid', 'mahjong', 'rummikub', 'davinci-code'] },
|
||||
{ key: 'party', label: '여럿이 파티', ids: ['bang', 'halli-galli', 'dobble', 'catchmind', 'mafia'] },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user