M9: 게임 26종 30초 요약 카드·[?] 지금 할 수 있는 것 내용
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
68
apps/web/src/games/marble/help.test.ts
Normal file
68
apps/web/src/games/marble/help.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
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 users = usersOf(['A', 'B']);
|
||||
const view = (s: unknown, who: string | null) => GAMES.marble!.view(s, who) as any;
|
||||
/** Scripted dice: int(6) returns the queued faces (1..6). */
|
||||
const dice = (...faces: number[]) => ({ next: () => 0, int: () => faces.shift()! - 1, shuffle: <T,>(a: readonly T[]) => [...a] }) as any;
|
||||
|
||||
function fresh(opts: Record<string, unknown> = {}) {
|
||||
const { state } = setupGame('marble', 2, opts);
|
||||
state.order = ['A', 'B'];
|
||||
state.current = 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
test('땅따먹기: 굴리기 차례 / 상대 차례 / 관전', () => {
|
||||
const s = fresh();
|
||||
const a = helpNow(view(s, 'A'), 'A', users);
|
||||
expect(a).toContain('[🎲 주사위 굴리기]');
|
||||
expect(a).toContain('지금 내 포인트는 300P');
|
||||
const b = helpNow(view(s, 'B'), 'B', users);
|
||||
expect(b).toContain('호랑이님 차례예요(1/20라운드). 기다려 주세요.');
|
||||
expect(helpNow(view(s, null), null, users)).toContain('호랑이님 차례예요(1/20라운드).');
|
||||
});
|
||||
|
||||
test('땅따먹기: 빈 땅에 서면 사기 / 내 땅에 다시 오면 짓기', () => {
|
||||
let s = fresh();
|
||||
s = applyAction('marble', s, 'A', { type: 'ROLL' }, dice(2, 4)); // → 6 방콕
|
||||
const t = helpNow(view(s, 'A'), 'A', users);
|
||||
expect(t).toContain('방콕에 왔어요. 주인 없는 땅이라 10P에 살 수 있어요.');
|
||||
expect(t).toContain('[사기]');
|
||||
expect(helpNow(view(s, 'B'), 'B', users)).toContain('방콕에서 할 일을 고르는 중이에요');
|
||||
const s2 = fresh();
|
||||
s2.owners[6] = { owner: 'A', level: 0 };
|
||||
const s3 = applyAction('marble', s2, 'A', { type: 'ROLL' }, dice(2, 4));
|
||||
const u = helpNow(view(s3, 'A'), 'A', users);
|
||||
expect(u).toContain('내 땅 방콕에 왔어요. 별장을 5P에 지을 수 있어요. 지으면 통행료가 6P가 돼요.');
|
||||
expect(u).toContain('[짓기]');
|
||||
});
|
||||
|
||||
test('땅따먹기: 무인도, 더블, 우주여행, 모자란 포인트', () => {
|
||||
let s = fresh();
|
||||
s.players.A.pos = 10;
|
||||
s.players.A.islandLeft = 2;
|
||||
expect(helpNow(view(s, 'A'), 'A', users)).toContain('무인도에 갇혔어요(2번 남음)');
|
||||
expect(helpNow(view(s, 'B'), 'B', users)).toContain('무인도에 갇혀 있어요(2번 남음)');
|
||||
|
||||
s = fresh();
|
||||
s = applyAction('marble', s, 'A', { type: 'ROLL' }, dice(3, 3)); // → 6 방콕, double
|
||||
s = applyAction('marble', s, 'A', { type: 'PASS' });
|
||||
expect(helpNow(view(s, 'A'), 'A', users)).toContain('더블이 나와서 한 번 더 굴려요');
|
||||
|
||||
s = fresh();
|
||||
s.players.A.spacePending = true;
|
||||
s.players.A.pos = 30;
|
||||
expect(helpNow(view(s, 'A'), 'A', users)).toContain('우주여행이에요');
|
||||
|
||||
s = fresh();
|
||||
s.owners[6] = { owner: 'B', level: 3 };
|
||||
s.owners[39] = { owner: 'A', level: 0 };
|
||||
s.players.A.cash = 5;
|
||||
s = applyAction('marble', s, 'A', { type: 'ROLL' }, dice(2, 4)); // 통행료 25 > 5
|
||||
expect(s.phase).toBe('debt');
|
||||
expect(helpNow(view(s, 'A'), 'A', users)).toContain('20P가 모자라요');
|
||||
expect(helpNow(view(s, 'B'), 'B', users)).toContain('모자란 포인트 20P');
|
||||
});
|
||||
94
apps/web/src/games/marble/help.ts
Normal file
94
apps/web/src/games/marble/help.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
/** 주사위 땅따먹기 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view (+ the pure board data). */
|
||||
import type { MarbleView } from '@bg/games/marble';
|
||||
import { SPACES } from '@bg/games/marble/board';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
|
||||
const LEVEL_KO = ['땅', '별장', '빌딩', '호텔', '랜드마크'];
|
||||
const P = (n: number) => `${n}P`;
|
||||
const batchim = (w: string) => {
|
||||
const c = w.charCodeAt(w.length - 1);
|
||||
return c >= 0xac00 && c <= 0xd7a3 && (c - 0xac00) % 28 !== 0;
|
||||
};
|
||||
const eul = (w: string) => `${w}${batchim(w) ? '을' : '를'}`;
|
||||
const space = (pos: number) => SPACES[pos]?.name ?? `${pos}번 칸`;
|
||||
|
||||
export function helpNow(v: MarbleView, me: string | null, players: Record<string, PublicUser>): string {
|
||||
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
|
||||
const name = (id: string | null | undefined) => `${(id && players[id]?.nickname) || '다른 사람'}님`;
|
||||
const round = v.maxRounds > 0 ? `${v.round}/${v.maxRounds}라운드` : `${v.round}라운드`;
|
||||
const meP = me ? v.players.find((p) => p.id === me) : undefined;
|
||||
const m = v.my;
|
||||
|
||||
// What is happening, told neutrally (for waiting players and spectators).
|
||||
const situation = (): string => {
|
||||
if (v.phase === 'debt' && v.debt) return `${name(v.debt.debtor)}이 모자란 포인트 ${P(v.debt.short)}를 땅이나 건물을 팔아 채우는 중이에요.`;
|
||||
if (v.phase === 'tradeResponse' && v.trade) return `${name(v.trade.to)}이 ${name(v.trade.from)}의 교환 제안을 보는 중이에요.`;
|
||||
const cur = v.current ? v.players.find((p) => p.id === v.current) : undefined;
|
||||
let s = `${name(v.current)} 차례예요(${round}).`;
|
||||
if (v.phase === 'decide' && v.decision) s += ` ${space(v.decision.pos)}에서 할 일을 고르는 중이에요.`;
|
||||
else if (cur?.spacePending) s += ' 우주여행으로 갈 칸을 고르는 중이에요.';
|
||||
else if (cur && cur.islandLeft > 0) s += ` 무인도에 갇혀 있어요(${cur.islandLeft}번 남음).`;
|
||||
return s;
|
||||
};
|
||||
|
||||
if (!meP) return `${situation()}\n주사위를 굴려 판을 돌며 땅을 사고 건물을 지어요. 남의 땅에 서면 통행료를 내요.`;
|
||||
if (!meP.alive) return `나는 ${meP.conceded ? '기권' : '파산'}해서 지금은 구경만 할 수 있어요.\n${situation()}`;
|
||||
|
||||
const mine = `지금 내 포인트는 ${P(meP.cash)}, 내 땅은 ${meP.lands.length}곳이에요.`;
|
||||
|
||||
if (m?.respond && v.trade) return `${name(v.trade.from)}이 교환을 제안했어요. 주고받을 땅과 포인트를 잘 보고 [받기] 또는 [거절]을 눌러 주세요.`;
|
||||
|
||||
if (m?.sell && v.debt) {
|
||||
const lines = [`내야 할 ${P(v.debt.amount)} 중에 ${P(v.debt.short)}가 모자라요. 땅이나 건물을 은행에 팔아(낸 값의 절반을 받아요) 채워야 해요.`];
|
||||
lines.push(m.autoSell ? '[가장 싼 것부터 팔기] 버튼을 누르거나, ‘내 땅’ 목록에서 직접 골라 팔아요. 다 모이면 자동으로 내요.' : '‘내 땅’ 목록에서 팔 것을 골라 주세요. 다 모이면 자동으로 내요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
if (m?.decide) {
|
||||
const d = m.decide;
|
||||
const where = space(d.pos);
|
||||
if (d.buy !== null) {
|
||||
return `${where}에 왔어요. 주인 없는 땅이라 ${P(d.buy)}에 살 수 있어요.\n[사기]를 누르면 내 땅이 되고, 다른 사람이 여기 서면 나에게 통행료를 내요. 사지 않으려면 [안 사기]를 눌러요.\n${mine}`;
|
||||
}
|
||||
if (d.build) {
|
||||
const toll = SPACES[d.pos]?.tolls?.[d.build.level];
|
||||
const after = toll !== undefined ? ` 지으면 통행료가 ${P(toll)}가 돼요.` : '';
|
||||
const head = d.boughtThisVisit ? `방금 산 ${where}에 이 방 규칙으로 바로` : `내 땅 ${where}에 왔어요.`;
|
||||
return `${head} ${eul(LEVEL_KO[d.build.level]!)} ${P(d.build.cost)}에 지을 수 있어요.${after}\n[짓기] 또는 [안 짓기]를 눌러 주세요. 건물은 한 번 올 때마다 한 단계씩 지어요.\n${mine}`;
|
||||
}
|
||||
if (d.takeover !== null) {
|
||||
return `${where}에서 통행료를 냈어요. 이 방 규칙에서는 ${P(d.takeover)}를 내고 이 땅을 건물째 가져올(인수) 수 있어요.\n[인수하기] 또는 [안 하기]를 눌러 주세요.\n${mine}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (m?.space) return `🚀 우주여행이에요! 판에서 반짝이는 칸을 누르면 미리 보기가 나오고, 거기서 갈 곳을 정해요.\n출발 칸을 지나가면 월급 ${P(v.options.salary)}를 받아요. [출발로 가기]를 눌러도 돼요.\n${mine}`;
|
||||
|
||||
if (m?.island) {
|
||||
const isl = m.island;
|
||||
const lines = [`🏝️ 무인도에 갇혔어요(${isl.left}번 남음). [🎲 탈출 굴리기]를 눌러 더블(두 주사위가 같은 눈)이 나오면 바로 나가요.`];
|
||||
const ways: string[] = [];
|
||||
if (isl.hasCard) ways.push('[탈출권 쓰기]');
|
||||
if (isl.fee !== null) ways.push(`[탈출비 ${P(isl.fee)} 내기]${isl.canPayFee ? '' : '(포인트가 모자라 지금은 못 눌러요)'}`);
|
||||
if (ways.length) lines.push(`${ways.join(' 또는 ')}로 바로 나갈 수도 있어요.`);
|
||||
lines.push('무인도에 있어도 내 땅의 통행료는 받아요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
if (m?.canRoll) {
|
||||
const lines: string[] = [];
|
||||
if (v.extraRoll) lines.push(`더블이 나와서 한 번 더 굴려요! [🎲 한 번 더 굴리기]를 눌러 주세요.${v.doublesThisTurn === 2 ? ' 또 더블이 나오면 무인도로 가요.' : ''}`);
|
||||
else lines.push(`내 차례예요(${round}). [🎲 주사위 굴리기]를 누르면 나온 수만큼 앞으로 가요.`);
|
||||
lines.push('주인 없는 땅에 서면 살 수 있고, 남의 땅에 서면 통행료를 내요. 더블이면 한 번 더 굴려요.');
|
||||
if (m.canPropose) lines.push(`굴리기 전에 [🤝 교환 제안하기]로 다른 사람과 땅·포인트를 바꾸자고 할 수 있어요.`);
|
||||
lines.push(mine);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
// Waiting for someone else.
|
||||
const lines = [`${situation()} 기다려 주세요.`];
|
||||
if (v.phase === 'tradeResponse' && v.trade?.from === me) lines[0] = `내 교환 제안에 ${name(v.trade.to)}이 답하기를 기다리는 중이에요.`;
|
||||
if (meP.islandLeft > 0) lines.push(`나는 무인도에 있어요(${meP.islandLeft}번 남음). 그래도 내 땅의 통행료는 받아요.`);
|
||||
else if (meP.spacePending) lines.push('다음 내 차례에 우주여행으로 원하는 칸에 갈 수 있어요.');
|
||||
lines.push(mine);
|
||||
return lines.join('\n');
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { Avatar, ConfirmSheet, Sheet } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
|
||||
type GameEvent = MarbleView['log'][number];
|
||||
|
||||
@@ -1388,6 +1390,8 @@ const ui: GameUI<MarbleView, MarbleOptions> = {
|
||||
Options,
|
||||
optionsSummary,
|
||||
Rules,
|
||||
quickStart,
|
||||
helpNow,
|
||||
};
|
||||
|
||||
export default ui;
|
||||
|
||||
87
apps/web/src/games/marble/quick.tsx
Normal file
87
apps/web/src/games/marble/quick.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
/** 주사위 땅따먹기 30초 규칙 요약 (docs/07 §5). */
|
||||
import type { ReactNode } from 'react';
|
||||
import type { QuickCard } from '../types';
|
||||
|
||||
const PIPS: Record<number, [number, number][]> = {
|
||||
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 Die({ value }: { value: number }) {
|
||||
return (
|
||||
<svg viewBox="0 0 100 100" width={56} height={56} aria-hidden>
|
||||
<rect x={4} y={4} width={92} height={92} rx={18} fill="#fffdf8" stroke="#9ca3af" strokeWidth={5} />
|
||||
{PIPS[value]!.map(([x, y], i) => (
|
||||
<circle key={i} cx={x} cy={y} r={10} fill="#1c1e21" />
|
||||
))}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** A city square like on the board: colour band, name, and a line below. */
|
||||
function Tile({ name, color, children, owner }: { name: string; color: string; children: ReactNode; owner?: string }) {
|
||||
return (
|
||||
<div style={{ width: 96, borderRadius: 10, overflow: 'hidden', border: `3px solid ${owner ?? '#d1d5db'}`, background: '#fff', textAlign: 'center' }}>
|
||||
<div style={{ background: color, height: 16 }} />
|
||||
<div style={{ fontWeight: 800, fontSize: '1rem', padding: '4px 0 0', color: '#111' }}>{name}</div>
|
||||
<div style={{ fontSize: '0.95rem', padding: '2px 4px 6px', color: '#111' }}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const row = { display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 } as const;
|
||||
|
||||
export const quickStart: QuickCard[] = [
|
||||
{
|
||||
pic: (
|
||||
<div style={row} aria-hidden>
|
||||
<Die value={3} />
|
||||
<Die value={5} />
|
||||
<span style={{ fontSize: 28 }}>➜</span>
|
||||
<Tile name="방콕" color="#38bdf8">
|
||||
<b>10P</b>에 사기
|
||||
</Tile>
|
||||
</div>
|
||||
),
|
||||
alt: '주사위 3과 5를 굴려 방콕 칸에 도착하고, 10P에 살 수 있어요',
|
||||
title: '굴리고 땅을 사요',
|
||||
text: '주사위 2개를 굴린 만큼 판을 돌아요. 주인 없는 땅에 서면 [사기]로 내 땅으로 만들 수 있어요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<div style={row} aria-hidden>
|
||||
<Tile name="로마" color="#db2777" owner="#dc2626">
|
||||
<span style={{ fontSize: 22 }}>🏠🏢🏨</span>
|
||||
</Tile>
|
||||
<div style={{ textAlign: 'center', fontWeight: 800, color: '#b91c1c' }}>
|
||||
<div style={{ fontSize: 30 }}>🚶</div>
|
||||
통행료
|
||||
<br />
|
||||
40P
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
alt: '별장·빌딩·호텔을 지은 로마 칸에 다른 사람이 와서 통행료 40P를 내요',
|
||||
title: '짓고 통행료 받기',
|
||||
text: '내 땅에 다시 오면 별장→빌딩→호텔을 한 단계씩 지어요. 남이 내 땅에 서면 통행료를 받고, 건물이 클수록 비싸요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<div style={{ ...row, gap: 16 }} aria-hidden>
|
||||
<div style={{ textAlign: 'center', fontWeight: 700 }}>
|
||||
<div style={{ fontSize: 44 }}>🏝️</div>무인도
|
||||
</div>
|
||||
<div style={{ textAlign: 'center', fontWeight: 700 }}>
|
||||
<div style={{ fontSize: 44 }}>🏆</div>총자산 1등
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
alt: '무인도 섬과 총자산 1등 트로피 그림',
|
||||
title: '총자산이 많으면 이겨요',
|
||||
text: '무인도에선 몇 차례 쉬어요(더블이면 바로 탈출). 라운드가 다 끝날 때 총자산(포인트+땅+건물)이 가장 많거나, 남이 모두 파산하면 이겨요.',
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user