새 게임 사건 파일: 직접 지은 협력 추리 게임(1~5명). 정해진 날짜·시간 안에 단서를 골라 읽고(이동 시간·야근·돋보기·조언), 마지막에 객관식 수사 보고서로 점수와 등급(S/A/B/미해결)
- 엔진 packages/games/src/case-file/(types·index·cases): 의뢰→수사→보고서→결과, 함께 풀기(반장 돌아가며/투표/아무나)·따로 겨루기, 시간·야근·피로, 열림 규칙(OR)·깊이 보기로 열림, 아침 소식, 조언 감점, 남은 시간 보너스, 한 사람만 읽기, 팀 답 다수결·동점 처리, 시간 초과·자리 비움·나가기 - 사건 3개(c1·c2·c3)를 docs/games/case-file-cases.md 글 그대로 cases/<id>.ts로 옮김(서버 전용). 웹은 types 모듈(라벨·스키마)만 가져오고, view에는 읽은 단서 본문만 나감 - 옵션: 문서 §2 전부(사건·모드·결정 방식·하루 시간·야근·돋보기·조언·남은 시간 보너스·아침 소식·읽기 모드·고르기/보고서/전체 제한 시간). kidSafeChat은 방 채팅을 그대로 쓰므로 방 설정의 채팅 필터로 대신(문서 구현 메모) - 컴퓨터 상대 없음(문서 §8.7, BOT_GAMES에 넣지 않음) - 웹 apps/web/src/games/case-file/: 수사 막대(날짜·시각·돋보기·조언·피로·반장·타이머), 탭 [단서·보고서·결과] [기록] [자료] [메모], 종이 서류 본문 카드(16px 이상), 지도, 장소별 단서 카드(이동+시간·🔍·야근·추천), 두 번 눌러 확정, 투표, 보고서, 등급 도장·문제별 답·풀이·놓친 단서, 30초 요약·도움말 - 등록: GAMES·CATALOG·GAME_UI·GAME_ICON·여럿이 파티 탭, @bg/games/case-file/types 내보내기, docs/games/README.md, e2e/games.e2e.ts - 테스트: 사건 데이터 검사(id·여는 조건·도달·이동표·문제·점수표·고운 말·빠듯한 길을 실제 엔진으로 따라가 해결), 규칙 30여 개(문서 §10), 무작위 판(1~5명·옵션 7조합) 비밀 유출·JSON 왕복·결정성, onTimeout 합법, 방 통합(의뢰·반장·보고서·따로 겨루기 시계), 웹 빌드 결과물에 사건 본문·정답·풀이가 없는지 검사(no-case-text.test.ts), E2E(PC+휴대폰, 한 사람만 읽기 비밀·깊이 보기·하루 마치기·보고서·결과, 320px 가로 넘침 없음) - 문서: case-file.md 구현 메모, case-file-cases.md c2 빠듯한 길 수정(원래 길은 열림 조건상 갈 수 없었음) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
89
apps/server/src/rooms/case-file.room.test.ts
Normal file
89
apps/server/src/rooms/case-file.room.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
/** 사건 파일 through a real Room: briefing clock, captain passes, report clock, race clock, and views that keep unread texts on the server (docs/games/case-file.md §8.5). */
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import type { ServerMessage } from '@bg/shared';
|
||||
import { GAMES } from '@bg/games';
|
||||
import { CASES, type CaseFileOptions, type CaseFileState } from '@bg/games/case-file';
|
||||
import { openDb } from '../db';
|
||||
import { Room, type Conn, type RoomConfig } from './room';
|
||||
import { RoomStore } from './store';
|
||||
|
||||
function harness(players: string[], opts: Partial<CaseFileOptions> = {}) {
|
||||
const db = openDb(':memory:');
|
||||
const store = new RoomStore(db);
|
||||
let now = 1_000_000;
|
||||
const clock = { now: () => now, set: (t: number) => (now = t), advance: (ms: number) => (now += ms) };
|
||||
const games = { 'case-file': GAMES['case-file']! };
|
||||
const deps = { store, games, users: { publicUser: (id: string) => ({ id, nickname: id, avatar: null, kind: 'guest' as const }) }, now: clock.now };
|
||||
const config: RoomConfig = { gameId: 'case-file', options: games['case-file'].optionsSchema.parse(opts), maxPlayers: players.length, visibility: 'private', allowSpectators: true, chatEnabled: true, chatFilter: true, graceSec: 60 };
|
||||
const room = new Room('room1', '482913', config, players[0]!, deps);
|
||||
store.insertRoom({ id: 'room1', code: '482913', hostId: players[0]!, gameId: 'case-file', status: 'lobby', visibility: 'private', config, stateJson: '{}', now });
|
||||
const conns: Record<string, Conn & { msgs: ServerMessage[] }> = {};
|
||||
for (const p of players) {
|
||||
const msgs: ServerMessage[] = [];
|
||||
conns[p] = { userId: p, msgs, send: (m) => msgs.push(m), close: () => {} };
|
||||
room.join(conns[p], 'player');
|
||||
}
|
||||
expect(room.start(players[0]!)).toBeNull();
|
||||
room.clearTimer();
|
||||
const state = () => room.game!.state as CaseFileState;
|
||||
/** Jumps to the current deadline and lets the room fire it. */
|
||||
const expire = () => {
|
||||
clock.set(Math.max(clock.now(), room.effectiveDeadline()!));
|
||||
room.onTimer();
|
||||
room.clearTimer();
|
||||
};
|
||||
let cs = 0;
|
||||
/** Sends an action like the client and fails on a reject. */
|
||||
const act = (p: string, a: unknown) => {
|
||||
const before = conns[p]!.msgs.length;
|
||||
room.act(p, ++cs, a);
|
||||
room.clearTimer();
|
||||
const rej = conns[p]!.msgs.slice(before).find((m) => m.t === 'reject');
|
||||
if (rej) throw new Error(`${p} ${JSON.stringify(a)} rejected: ${JSON.stringify(rej)}`);
|
||||
};
|
||||
return { room, clock, conns, state, expire, act };
|
||||
}
|
||||
|
||||
const allText = (msgs: ServerMessage[]) => JSON.stringify(msgs);
|
||||
|
||||
describe('사건 파일 room flow', () => {
|
||||
test('의뢰 60초 → 수사, 반장 시간 초과는 넘기기만, 보고서 시간 초과 → 채점', () => {
|
||||
const { room, state, expire, conns, act } = harness(['A', 'B'], { turnSeconds: 60, reportSeconds: 180 });
|
||||
expect(state().phase).toBe('briefing');
|
||||
expire();
|
||||
expect(state().phase).toBe('investigate');
|
||||
const cap = state().players[state().decider]!.id;
|
||||
expire();
|
||||
expect(state().players[state().decider]!.id).not.toBe(cap);
|
||||
expect(state().investigations.team!.visited).toHaveLength(0);
|
||||
const now = state().players[state().decider]!.id;
|
||||
act(now, { type: 'pick', lead: 'c1-03' });
|
||||
// The read text went out; texts nobody read did not.
|
||||
const c = CASES.c1;
|
||||
expect(allText(conns.A!.msgs)).toContain(JSON.stringify(c.leads[2]!.text).slice(1, 40));
|
||||
expect(allText(conns.B!.msgs)).not.toContain(JSON.stringify(c.leads[10]!.text).slice(1, 40));
|
||||
expect(allText(conns.B!.msgs)).not.toContain(JSON.stringify(c.solution).slice(1, 40));
|
||||
const next = state().players[state().decider]!.id;
|
||||
act(next, { type: 'report' });
|
||||
expect(state().phase).toBe('report');
|
||||
act('A', { type: 'answer', q: 'q1', choice: 0 });
|
||||
expire();
|
||||
expire();
|
||||
expect(room.game!.finished).toBe(true);
|
||||
expect(room.lastResult!.summary).toContain('범인은 강민재였어요');
|
||||
});
|
||||
|
||||
test('따로 겨루기: 전체 시간이 끝나면 모두 보고서, 끝나면 순위', () => {
|
||||
const { room, state, expire, act } = harness(['A', 'B'], { mode: 'race', raceMinutes: 30, reportSeconds: 180 });
|
||||
expire();
|
||||
expect(state().raceEndsAt).not.toBeNull();
|
||||
act('A', { type: 'pick', lead: 'c1-01' });
|
||||
expire();
|
||||
expect(state().phase).toBe('report');
|
||||
act('B', { type: 'answer', q: 'q1', choice: 0 });
|
||||
act('B', { type: 'submit' });
|
||||
expire();
|
||||
expect(room.game!.finished).toBe(true);
|
||||
expect(room.lastResult!.ranking).toEqual([['B'], ['A']]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user