타자 대결 연습 모드: 한컴 타자연습처럼 짧은글 10문장·단어 20개·긴글 한 편 전체를 제한 시간·점수 없이

- 대결 방식에 "연습" 추가(각자 치기, 라운드 1번, 시계·점수 없음). 긴글은 고른 주제 중 한 편을 처음부터 끝까지(8줄 단락이 아님).
- 줄마다 첫 타부터 시간을 재서 줄 사이에 쉬어도 타수가 안 떨어짐(첫 타 몫 0.15초 앞당김 → 붙여 넣기 막기 그대로).
  줄 최고 타수(best) 기록. 컴퓨터도 연습에서는 첫 타를 바로 보냄.
- 화면: 라운드 대신 걸린 시간, 지금·평균·최고 타수·정확도·진행 %, 끝나면 평균·최고·정확도·틀린 줄, 참가자 옆은 타수.
  설정에서 라운드·제한 시간 숨김, 종목 이름 "연습 종목", 도움말·규칙·요약 카드·docs.
- 테스트: 연습 4개(엔진), 무작위 대국 2가지, 컴퓨터 1가지, 도움말 1개, e2e typingPractice·typingPracticeLong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-12 17:09:23 +09:00
parent 122cf5ed1f
commit 943e4be3fd
11 changed files with 321 additions and 51 deletions

View File

@@ -43,3 +43,15 @@ test('글자 표시: 맞음·틀림·조합 중인 글자', () => {
expect(marks('강아지', '강오지').marks).toEqual(['ok', 'bad', 'ok']);
expect(marks('abc', 'abcd')).toEqual({ marks: ['ok', 'ok', 'ok'], extra: 1 });
});
test('타자 대결: 연습은 라운드·점수 없이 평균·최고 타수', () => {
const { state: s0, now } = setupGame('typing', 1, { mode: 'practice' });
const s = tick(s0, now + 3000);
const t = helpNow(view(s, 'A'), 'A', users);
expect(t).toContain('연습.');
expect(t).not.toContain('라운드');
expect(t).toContain('최고 0타');
s.phase = 'ended';
s.final = { ranking: [], summary: '연습 끝! 타수와 정확도를 확인해요' };
expect(helpNow(view(s, 'A'), 'A', users)).toContain('연습이 끝났어요');
});

View File

@@ -10,6 +10,7 @@ const MODE_LINE: Record<TypingView['options']['mode'], string> = {
speed: '각자 한 줄씩 치고 Enter를 누르면 다음 줄이 나와요. 라운드 타수(1분에 친 타 수, 틀린 만큼은 빼요)가 가장 높은 사람이 1점이에요.',
accuracy: '각자 한 줄씩 치고 Enter를 누르면 다음 줄이 나와요. 정확도가 가장 높은 사람이 1점이에요(같으면 타수).',
timeAttack: '시간이 끝날 때까지 나오는 글을 계속 쳐요. 정확하게 친 타 수가 가장 많은 사람이 1점이에요.',
practice: '제한 시간과 점수 없이 한 줄씩 제 속도로 쳐요. 문장마다 첫 글자를 친 때부터 타수를 재요.',
};
function leader(v: TypingView, players: Record<string, PublicUser>, me: string | null): string {
@@ -22,10 +23,13 @@ function leader(v: TypingView, players: Record<string, PublicUser>, me: string |
}
export function helpNow(v: TypingView, me: string | null, players: Record<string, PublicUser>): string {
if (v.phase === 'ended') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n최종 순위에서 각자의 점수, 평균 타수와 정확도를 볼 수 있어요.';
if (v.phase === 'ended')
return v.options.mode === 'practice'
? `연습이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n평균·최고 타수와 정확도를 확인하고, [한 판 더]로 한 번 더 연습할 수 있어요.'
: `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n최종 순위에서 각자의 점수, 평균 타수와 정확도를 볼 수 있어요.';
const mode = v.options.mode;
const surv = mode === 'survival' ? ` 탈락 조건은 "${ELIM_KO[v.options.elimination]}"${v.options.elimination === 'wrong' ? `, 목숨은 ${v.options.lives}개` : ''}예요.` : '';
const head = `${MODE_KO[mode]} · 라운드 ${v.round}/${v.options.rounds}.${surv}`;
const head = mode === 'practice' ? `${MODE_KO[mode]}.` : `${MODE_KO[mode]} · 라운드 ${v.round}/${v.options.rounds}.${surv}`;
const lead = leader(v, players, me);
if (v.phase === 'countdown') return `${head}\n곧 시작해요. ${HOW}\n${MODE_LINE[mode]}`;
if (v.phase === 'roundEnd') return `${head}\n라운드가 끝났어요. ${v.rounds.at(-1)?.summary ?? ''}. 잠시 뒤 다음 라운드가 시작해요.${lead ? `\n${lead}` : ''}`;
@@ -39,7 +43,7 @@ export function helpNow(v: TypingView, me: string | null, players: Record<string
else if (v.flow === 'lane' && mine.finished) lines.push('이번 라운드를 다 쳤어요. 다른 사람이 끝내기를 기다려요.');
else lines.push(HOW);
lines.push(MODE_LINE[mode]);
lines.push(`이번 라운드: ${mine.roundKpm}타, 정확도 ${mine.roundTried ? `${mine.roundAcc}%` : '아직 없음'}${mine.wrong ? `, 틀린 Enter ${mine.wrong}번` : ''}.`);
lines.push(`${mode === 'practice' ? `지금까지: 평균 ${mine.roundKpm}타, 최고 ${mine.bestKpm}타` : `이번 라운드: ${mine.roundKpm}타`}, 정확도 ${mine.roundTried ? `${mine.roundAcc}%` : '아직 없음'}${mine.wrong ? `, 틀린 Enter ${mine.wrong}번` : ''}.`);
if (mode === 'survival' && v.options.elimination === 'wrong') lines.push(`남은 목숨 ${mine.lives}개.`);
if (lead) lines.push(lead);
lines.push(v.options.lang === 'ko' ? '영어가 쳐지면 한/영 키를 눌러 한글로 바꿔요.' : '한글이 쳐지면 한/영 키를 눌러 영어로 바꿔요.');

View File

@@ -181,6 +181,7 @@ function Seats({ v, me, players, live }: { v: TypingView; me: string | null; pla
const surv = v.options.mode === 'survival';
const lives = surv && v.options.elimination === 'wrong';
const unit = v.options.mode === 'first' ? '점' : '승';
const practice = v.options.mode === 'practice';
return (
<ul className="ty-seats" aria-label="참가자">
{v.seats.map((s) => {
@@ -197,8 +198,7 @@ function Seats({ v, me, players, live }: { v: TypingView; me: string | null; pla
{tag && <span className="small muted"> · {tag}</span>}
</span>
<span className="sc">
{lives && s.alive && <Hearts n={s.lives} max={v.options.lives} />} {s.points}
{unit}
{lives && s.alive && <Hearts n={s.lives} max={v.options.lives} />} {practice ? `${s.roundKpm}타` : `${s.points}${unit}`}
</span>
<span className="ty-bar" role="progressbar" aria-label={`${nick(players, s.id)} 진행`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(bar * 100)}>
<i data-s={state} style={{ width: `${Math.round(bar * 100)}%` }} />
@@ -269,8 +269,10 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
const laneDone = !shared && v.total !== null && myIdx >= v.total;
const canType = !!mine && mine.alive && !mine.left && v.phase === 'playing' && !!item && !(shared && mine.solved) && !(!shared && (mine.finished || laneDone));
const itemKey = `${v.round}:${myIdx}`;
const practice = v.options.mode === 'practice';
// When the current item's clock started (연습: at its first key, 0 = not yet).
const startedAt = useRef<{ key: string; at: number }>({ key: '', at: 0 });
if (startedAt.current.key !== itemKey && item) startedAt.current = { key: itemKey, at: shared ? Math.max(v.curAt, now) : now };
if (startedAt.current.key !== itemKey && item) startedAt.current = { key: itemKey, at: practice ? 0 : shared ? Math.max(v.curAt, now) : now };
// A new item: empty box, focus on it.
useEffect(() => {
@@ -390,11 +392,14 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
});
const ck = item ? correctKeys(item.text, typed) : 0;
const elapsed = item ? Math.max(0, now - startedAt.current.at) : 0;
const elapsed = item && startedAt.current.at ? Math.max(0, now - startedAt.current.at) : 0;
const curKpm = typed && elapsed > 500 ? kpm(ck, elapsed) : 0;
const langWarn = typed.length >= 2 && wrongLang(v.options.lang, typed);
const surv = v.options.mode === 'survival';
const roundLabel = `라운드 ${v.round}/${v.options.rounds}`;
const roundLabel = practice ? null : `라운드 ${v.round}/${v.options.rounds}`;
// 연습: how long I have been at it (like 한컴 타자연습's 경과 시간).
const spent = practice && v.phase === 'playing' && mine && !mine.finished && !laneDone ? Math.max(0, now - v.roundStartedAt) : null;
const progressPct = v.total ? Math.round((Math.min(myIdx, v.total) / v.total) * 100) : 0;
const itemLabel = shared ? (v.total ? `${Math.min(v.cur + 1, v.total)}/${v.total}번째` : `${v.cur + 1}번째`) : v.total ? `${Math.min(myIdx + 1, v.total)}/${v.total}줄` : `${myIdx + 1}번째 줄`;
const lastRound = v.rounds.at(-1);
const alive = v.seats.filter((s) => s.alive).length;
@@ -412,7 +417,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
<div className="ty">
<style>{CSS}</style>
<div className="ty-top">
<span className="ty-pill">{roundLabel}</span>
{roundLabel && <span className="ty-pill">{roundLabel}</span>}
<span className="ty-pill">{MODE_KO[v.options.mode]}</span>
{v.phase === 'playing' && <span className="ty-pill">{itemLabel}</span>}
{surv && v.phase === 'playing' && <span className="ty-pill">남은 사람 {alive}명</span>}
@@ -421,6 +426,11 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
⏱ {surv && !shared ? `탈락까지 ${clock(left)}` : clock(left)}
</span>
)}
{spent !== null && (
<span className="ty-pill" aria-label={`걸린 시간 ${clock(spent)}`}>
⏱ {clock(spent)}
</span>
)}
</div>
<div className="ty-card">
{v.passage && (
@@ -447,7 +457,9 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
) : (
<div className="ty-target" style={{ color: 'var(--text-sub)', fontSize: '1.15rem' }}>
{v.phase === 'ended'
? '게임 끝!'
? practice
? '연습 끝!'
: '게임 끝!'
: v.phase === 'countdown'
? '곧 시작해요!'
: gap
@@ -496,6 +508,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
onChange={(e) => {
const t = e.target.value;
if (t.length > typed.length && !composing.current) tySound.key();
if (practice && !startedAt.current.at && normalize(t)) startedAt.current.at = socket.now();
setTyped(t);
sendProgress(t);
}}
@@ -525,7 +538,26 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
{note.text}
</div>
)}
{mine && v.phase === 'playing' && (
{mine && v.phase === 'playing' && practice && (
<div className="ty-stats">
<span>지금 {curKpm}타</span>
<span>평균 {mine.roundKpm}타</span>
<span>최고 {mine.bestKpm}타</span>
<span>정확도 {mine.roundTried ? `${mine.roundAcc}%` : '-'}</span>
<span>진행 {progressPct}%</span>
</div>
)}
{mine && v.phase === 'ended' && practice && (
<div className="ty-stats" role="status" style={{ fontSize: '1.05rem' }}>
<span>평균 {mine.roundKpm}타</span>
<span>최고 {mine.bestKpm}타</span>
<span>정확도 {mine.roundTried ? `${mine.roundAcc}%` : '-'}</span>
<span>
{mine.done}줄 중 틀린 줄 {mine.wrong}개
</span>
</div>
)}
{mine && v.phase === 'playing' && !practice && (
<div className="ty-stats">
<span>지금 {curKpm}타</span>
<span>이번 라운드 {mine.roundKpm}타</span>
@@ -538,7 +570,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
<div className="ty-over" aria-hidden>
<b key={countdown}>{countdown}</b>
<small>
{v.round > 1 ? `라운드 ${v.round} · ` : ''}
{v.round > 1 && !practice ? `라운드 ${v.round} · ` : ''}
{CATEGORY_KO[v.options.category]} · {MODE_KO[v.options.mode]}
</small>
</div>
@@ -563,6 +595,7 @@ function TypingBoard({ view: v, me, players, act }: BoardProps<TypingView>) {
function TypingSide({ view: v, players }: BoardProps<TypingView>) {
const rows = [...v.seats].sort((a, b) => Number(a.left) - Number(b.left) || b.points - a.points || b.kpm - a.kpm);
const unit = v.options.mode === 'first' ? '점' : '승';
const practice = v.options.mode === 'practice';
return (
<>
<div className="card stack" style={{ gap: 6, padding: 12 }}>
@@ -580,10 +613,12 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
<span className="small muted" style={{ fontVariantNumeric: 'tabular-nums' }}>
{s.kpm}타 · {s.tried ? `${s.acc}%` : '-'}
</span>
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
{s.points}
{unit}
</strong>
{!practice && (
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
{s.points}
{unit}
</strong>
)}
</li>
))}
</ol>
@@ -595,7 +630,7 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
{v.rounds.map((r) => (
<div key={r.round} className="stack" style={{ gap: 4 }}>
<span className="small" style={{ fontWeight: 700 }}>
라운드 {r.round} · {r.winners.length ? r.winners.map((w) => nick(players, w)).join(', ') : '승자 없음'}
{practice ? '연습 기록' : `라운드 ${r.round} · ${r.winners.length ? r.winners.map((w) => nick(players, w)).join(', ') : '승자 없음'}`}
</span>
<RoundTable r={r} players={players} mode={v.options.mode} />
</div>
@@ -612,8 +647,7 @@ function TypingSide({ view: v, players }: BoardProps<TypingView>) {
{r.rank}등 {nick(players, r.id)}
<span className="muted small">
{' '}
· {r.points}
{unit} · 평균 {r.kpm}타 · 정확도 {r.acc}%{r.left ? ' · 나감' : ''}
· {practice ? '' : `${r.points}${unit} · `}평균 {r.kpm}타 · 정확도 {r.acc}%{r.left ? ' · 나감' : ''}
</span>
</span>
))}
@@ -635,10 +669,10 @@ function isMyTurn(v: TypingView, me: string | null): boolean {
function statusText(v: TypingView, me: string | null, players: Record<string, PublicUser>): string {
if (v.phase === 'ended') return v.result?.summary ?? '게임이 끝났어요';
if (v.phase === 'countdown') return `라운드 ${v.round} 곧 시작! 나오는 글을 그대로 쳐요`;
if (v.phase === 'countdown') return `${v.options.mode === 'practice' ? '연습' : `라운드 ${v.round}`} 곧 시작! 나오는 글을 그대로 쳐요`;
if (v.phase === 'roundEnd') return v.rounds.at(-1)?.summary ?? '라운드 끝';
const s = v.seats.find((x) => x.id === me);
if (!s) return `${MODE_KO[v.options.mode]} · 라운드 ${v.round}/${v.options.rounds}`;
if (!s) return v.options.mode === 'practice' ? MODE_KO.practice : `${MODE_KO[v.options.mode]} · 라운드 ${v.round}/${v.options.rounds}`;
if (s.left) return '게임에서 나갔어요';
if (!s.alive) return '탈락했어요 · 다음 라운드를 기다려요';
if (v.flow === 'shared') {
@@ -647,7 +681,7 @@ function statusText(v: TypingView, me: string | null, players: Record<string, Pu
return v.options.mode === 'first' ? '가장 먼저 정확하게 치면 1점!' : '제한 시간 안에 정확하게 쳐요!';
}
if (s.finished) return '다 쳤어요! 다른 사람을 기다려요';
return v.options.mode === 'timeAttack' ? '시간 안에 최대한 많이 쳐요!' : '한 줄씩 치고 Enter!';
return v.options.mode === 'timeAttack' ? '시간 안에 최대한 많이 쳐요!' : v.options.mode === 'practice' ? '한 줄씩 치고 Enter! 천천히 정확하게 연습해요' : '한 줄씩 치고 Enter!';
}
// ---------------------------------------------------------------- options
@@ -670,6 +704,7 @@ const MODE_HELP: Record<Mode, string> = {
speed: '각자 자기 속도로 글을 치고, 라운드의 타수(1분에 친 타 수, 오타는 빼고)가 가장 높은 사람이 1점이에요.',
accuracy: '각자 글을 치고, 정확도가 가장 높은 사람이 1점이에요. 정확도가 같으면 타수가 높은 사람이 이겨요.',
timeAttack: '정해진 시간 동안 끝없이 나오는 글을 쳐요. 정확하게 친 타 수가 가장 많은 사람이 1점이에요.',
practice: '한컴 타자연습처럼 혼자(또는 함께) 제 속도로 연습해요. 제한 시간과 점수 없이 짧은글은 10문장, 단어는 20개, 긴글은 한 편을 처음부터 끝까지 쳐요. 문장마다 첫 글자를 친 때부터 타수를 재요.',
};
const ELIM_HELP: Record<Elim, string> = {
wrong: '틀린 채로 Enter를 누르거나 시간 안에 못 치면 목숨이 하나 줄고, 목숨을 다 쓰면 탈락해요.',
@@ -688,7 +723,8 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
set({ topics: [...others, ...next] });
};
const timeLabel = o.mode === 'speed' || o.mode === 'accuracy' ? '라운드 제한 시간' : '한 문제 제한 시간';
const showTime = o.mode !== 'timeAttack' && !(o.mode === 'survival' && o.elimination === 'interval');
const practice = o.mode === 'practice';
const showTime = o.mode !== 'timeAttack' && !practice && !(o.mode === 'survival' && o.elimination === 'interval');
return (
<div className="stack" style={{ gap: 16 }}>
<div className="stack" style={{ gap: 6 }}>
@@ -720,8 +756,8 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
</div>
)}
<div className="stack" style={{ gap: 6 }}>
<strong>대결 종목</strong>
<Seg label="대결 종목" value={o.category} options={(['word', 'short', 'long'] as Category[]).map((c) => [c, CATEGORY_KO[c]])} onChange={(category) => set({ category })} />
<strong>{practice ? '연습 종목' : '대결 종목'}</strong>
<Seg label={practice ? '연습 종목' : '대결 종목'} value={o.category} options={(['word', 'short', 'long'] as Category[]).map((c) => [c, CATEGORY_KO[c]])} onChange={(category) => set({ category })} />
</div>
<div className="stack" style={{ gap: 6 }}>
<strong>주제 (여러 개 고를 수 있어요)</strong>
@@ -737,13 +773,15 @@ function Options({ value: o, onChange }: OptionsProps<TypingOptions>) {
</div>
<span className="small muted">
{picked.length === 0 ? `전체 ${topics.length}개 주제에서 골고루 나와요.` : `${picked.map((id) => topics.find((t) => t.id === id)?.name).join(', ')}에서 나와요.`}
{o.category === 'long' ? ' 긴글은 라운드마다 한 단락(8줄 안팎)씩 이어서 쳐요.' : ''}
{o.category === 'long' ? (practice ? ' 연습은 그중 한 편을 처음부터 끝까지 쳐요.' : ' 긴글은 라운드마다 한 단락(8줄 안팎)씩 이어서 쳐요.') : ''}
</span>
</div>
<div className="stack" style={{ gap: 6 }}>
<strong>라운드</strong>
<Seg label="라운드" value={o.rounds} options={Array.from({ length: 10 }, (_, i) => [i + 1, `${i + 1}`] as [number, string])} onChange={(rounds) => set({ rounds })} />
</div>
{!practice && (
<div className="stack" style={{ gap: 6 }}>
<strong>라운드</strong>
<Seg label="라운드" value={o.rounds} options={Array.from({ length: 10 }, (_, i) => [i + 1, `${i + 1}`] as [number, string])} onChange={(rounds) => set({ rounds })} />
</div>
)}
{showTime && (
<div className="stack" style={{ gap: 6 }}>
<strong>{timeLabel}</strong>
@@ -778,7 +816,7 @@ function optionsSummary(o: TypingOptions): string {
const topics = topicsFor(o.lang, o.category);
const picked = topics.filter((t) => o.topics.includes(t.id)).map((t) => t.name);
const sub = o.mode === 'survival' ? `(${ELIM_KO[o.elimination].replace(/\(.*\)/, '')}${o.elimination === 'wrong' ? ` · 목숨 ${o.lives}` : ''})` : '';
return `${LANG_KO[o.lang]} · ${MODE_KO[o.mode]}${sub} · ${CATEGORY_KO[o.category]}(${picked.length ? picked.join(', ') : '전체 주제'}) · ${o.rounds}라운드`;
return `${LANG_KO[o.lang]} · ${MODE_KO[o.mode]}${sub} · ${CATEGORY_KO[o.category]}(${picked.length ? picked.join(', ') : '전체 주제'})${o.mode === 'practice' ? '' : ` · ${o.rounds}라운드`}`;
}
// ---------------------------------------------------------------- rules
@@ -808,6 +846,9 @@ function Rules({ options: o }: { options?: TypingOptions }) {
<li>
<strong>타임어택</strong>: 정해진 시간 동안 끝없이 나오는 글을 쳐서, 정확하게 친 타 수가 가장 많은 사람이 1점.
</li>
<li>
<strong>연습</strong>: 한컴 타자연습처럼 제한 시간·점수 없이 제 속도로 쳐요. 짧은글 10문장, 단어 20개, 긴글은 한 편 전체. 지금·평균·최고 타수, 정확도, 진행률과 걸린 시간을 보여 줘요.
</li>
</ul>
<p>
라운드는 1~10번(기본 3번)이에요. 모두 끝나면 점수가 가장 높은 사람이 이기고, 같으면 평균 타수가 높은 사람이 앞서요. 한국어·영어, 단어·짧은글·긴글과 주제(여러 개)를 방 설정에서 골라요. 혼자서도, 컴퓨터와도 할 수

View File

@@ -78,7 +78,7 @@ export const quickStart: QuickCard[] = [
),
alt: '세 사람의 진행 막대예요. 호랑이가 먼저 다 쳤어요',
title: '빠르고 정확하게',
text: '가장 먼저 입력·서바이벌·타수 비교·정확도 대결·타임어택 중에서 골라요. 다른 사람이 친 만큼 막대로 보여요.',
text: '가장 먼저 입력·서바이벌·타수 비교·정확도 대결·타임어택 중에서 골라요. 다른 사람이 친 만큼 막대로 보여요. 혼자 연습하려면 연습!',
},
{
pic: (