사과 게임 무제한: 스톱워치(시작부터 더 지울 사과가 없거나 여기까지 할 때까지, 0.1초 단위)와 💡 힌트(합 10 묶음 하나를 나에게만 노란 점선 상자로), 결과창·순위·요약에 걸린 시간과 힌트 횟수
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,10 @@ export function helpNow(v: AppleView, me: string | null, players: Record<string,
|
||||
if (mine.status === 'done') return `여기까지 했어요. 사과 ${mine.score}개를 지웠어요. 모두 끝내면 순위가 나와요.${lead ? `\n${lead}` : ''}`;
|
||||
const lines = [HOW, '빈 칸은 합에 들어가지 않아서, 사이가 비어 있어도 멀리 있는 사과끼리 묶을 수 있어요.', `지금 내 점수는 사과 ${mine.score}개예요.`];
|
||||
if (lead) lines.push(lead);
|
||||
if (secs === null) lines.push('제한 시간이 없어요. 그만하고 싶으면 아래 [여기까지 할래요]를 두 번 눌러요.');
|
||||
if (secs === null) {
|
||||
lines.push('제한 시간이 없어요. 위의 스톱워치가 더 지울 사과가 없어질 때까지 걸린 시간을 재요. 그만하고 싶으면 아래 [여기까지 할래요]를 두 번 눌러요.');
|
||||
lines.push('막히면 [💡 힌트]를 눌러요. 판에 합이 10인 묶음 하나가 노란 점선 상자로 보여요. 받은 횟수는 결과에 걸린 시간과 함께 나와요.');
|
||||
}
|
||||
lines.push(KEYS);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** 사과 게임 화면 (docs/games/apple.md §9). */
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react';
|
||||
import type { AppleOptions, AppleView, SeatView } from '@bg/games/apple';
|
||||
import { extraText, formatElapsed, type AppleOptions, type AppleView, type SeatView } from '@bg/games/apple';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { useServerNow } from '../../components/TurnTimer';
|
||||
@@ -50,6 +50,11 @@ const clock = (ms: number) => {
|
||||
const s = Math.ceil(Math.max(0, ms) / 1000);
|
||||
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
|
||||
};
|
||||
/** 무제한 stopwatch on the board: "1:05.4". */
|
||||
const watch = (ms: number) => {
|
||||
const t = Math.floor(Math.max(0, ms) / 100);
|
||||
return `${Math.floor(t / 600)}:${String(Math.floor((t % 600) / 10)).padStart(2, '0')}.${t % 10}`;
|
||||
};
|
||||
const limitLabel = (sec: number | null) => (sec === null ? '무제한' : sec % 60 === 0 ? `${sec / 60}분` : `${sec}초`);
|
||||
|
||||
/** Game sounds on top of the shared palette (site volume applies). */
|
||||
@@ -114,6 +119,9 @@ const CSS = `
|
||||
.ap-pill b, .ap-others li b { display: inline-block; }
|
||||
.ap-over.count b { display: block; animation: ap-count .9s ease-out both; }
|
||||
.ap-stop { min-height: 40px; }
|
||||
.ap-acts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
|
||||
.ap-hint { animation: ap-hint 1s ease-in-out infinite alternate; }
|
||||
@keyframes ap-hint { from { opacity: .45; } to { opacity: 1; } }
|
||||
.ap-over { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; pointer-events: none;
|
||||
border-radius: 14px; text-align: center; padding: 12px; }
|
||||
.ap-over.count { background: rgba(0,0,0,.35); color: #fff; font-size: 5rem; font-weight: 900; text-shadow: 0 3px 8px rgba(0,0,0,.5); }
|
||||
@@ -129,7 +137,7 @@ const CSS = `
|
||||
@keyframes ap-count { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.85); opacity: .85; } }
|
||||
@keyframes ap-pop { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.25); opacity: .9; } 100% { transform: scale(.2) translateY(-30px); opacity: 0; } }
|
||||
@keyframes ap-flash { 0% { opacity: 0; transform: translateX(-50%) scale(.8); } 15% { opacity: 1; transform: translateX(-50%) scale(1.05); } 70% { opacity: 1; } 100% { opacity: 0; } }
|
||||
@media (prefers-reduced-motion: reduce) { .ap-pop { animation-duration: .01s; } .ap-flash, .ap-in, .ap-burst, .ap-over.count b { animation: none; } .ap-burst { display: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .ap-hint { animation: none; } .ap-pop { animation-duration: .01s; } .ap-flash, .ap-in, .ap-burst, .ap-over.count b { animation: none; } .ap-burst { display: none; } }
|
||||
`;
|
||||
|
||||
// ---------------------------------------------------------------- art
|
||||
@@ -204,7 +212,8 @@ interface Pop {
|
||||
}
|
||||
|
||||
function AppleBoard({ view: v, me, players, act }: BoardProps<AppleView>) {
|
||||
const now = useServerNow(200);
|
||||
// 무제한 runs a stopwatch in tenths: a quicker clock there.
|
||||
const now = useServerNow(v.endsAt === null ? 100 : 200);
|
||||
const phone = useNarrow();
|
||||
const [drag, setDrag] = useState<{ a: Cell; b: Cell } | null>(null);
|
||||
const [cursor, setCursor] = useState<Cell>([0, 0]);
|
||||
@@ -372,6 +381,8 @@ function AppleBoard({ view: v, me, players, act }: BoardProps<AppleView>) {
|
||||
};
|
||||
|
||||
const left = v.endsAt === null ? null : Math.max(0, v.endsAt - Math.max(now, v.countdownEndsAt));
|
||||
// 무제한 stopwatch: from the start until I have nothing more to clear (or 「여기까지」); spectators see the room's clock.
|
||||
const elapsed = mine?.timeMs ?? (v.phase === 'playing' && (!mine || mine.status === 'playing') ? Math.max(0, now - v.countdownEndsAt) : null);
|
||||
const countdown = v.phase === 'countdown' ? Math.max(1, Math.ceil((v.countdownEndsAt - now) / 1000)) : 0;
|
||||
const sumState = !sel || sel.idx.length === 0 ? 'idle' : sel.sum === 10 ? 'ok' : sel.sum > 10 ? 'over' : 'under';
|
||||
// Sounds that follow the clock and the state: 3·2·1, start, last 10 seconds, "10!" while dragging, finished.
|
||||
@@ -413,14 +424,36 @@ function AppleBoard({ view: v, me, players, act }: BoardProps<AppleView>) {
|
||||
);
|
||||
}
|
||||
const [cr, cc] = toDisp(cursor);
|
||||
// 💡 힌트: a glowing box around one group that adds up to 10 (only mine, only while it still does).
|
||||
let hintBox: ReactNode = null;
|
||||
if (v.hint && canPlay && cells && inside(cells, v.hint).sum === 10) {
|
||||
const [ar, ac] = toDisp([v.hint.r0, v.hint.c0]);
|
||||
const [br, bc] = toDisp([v.hint.r1, v.hint.c1]);
|
||||
hintBox = (
|
||||
<rect
|
||||
className="ap-hint"
|
||||
x={Math.min(ac, bc) * S + 1.5}
|
||||
y={Math.min(ar, br) * S + 1.5}
|
||||
width={(Math.abs(ac - bc) + 1) * S - 3}
|
||||
height={(Math.abs(ar - br) + 1) * S - 3}
|
||||
rx={7}
|
||||
fill="rgba(250,204,21,.25)"
|
||||
stroke="#f59e0b"
|
||||
strokeWidth={4}
|
||||
strokeDasharray="8 4"
|
||||
pointerEvents="none"
|
||||
data-hint
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ap">
|
||||
<style>{CSS}</style>
|
||||
<div className="ap-top">
|
||||
{left === null ? (
|
||||
<span className="ap-pill" aria-label="제한 시간 없음">
|
||||
⏱ 무제한
|
||||
<span className="ap-pill" aria-label={elapsed === null ? '제한 시간 없음' : `걸린 시간 ${formatElapsed(elapsed)}`}>
|
||||
⏱ {elapsed === null ? '무제한' : <b style={{ fontSize: '1rem' }}>{watch(elapsed)}</b>}
|
||||
</span>
|
||||
) : (
|
||||
<span className={`ap-pill${v.phase === 'playing' && left <= 10_000 ? ' warn' : ''}`} role="timer" aria-label={`남은 시간 ${Math.floor(Math.ceil(left / 1000) / 60)}분 ${Math.ceil(left / 1000) % 60}초`}>
|
||||
@@ -499,6 +532,7 @@ function AppleBoard({ view: v, me, players, act }: BoardProps<AppleView>) {
|
||||
);
|
||||
}),
|
||||
)}
|
||||
{hintBox}
|
||||
{selBox}
|
||||
{focused && canPlay && <rect x={cc * S + 2} y={cr * S + 2} width={S - 4} height={S - 4} rx={8} fill="none" stroke="#f59e0b" strokeWidth={3} strokeDasharray="5 3" pointerEvents="none" />}
|
||||
</svg>
|
||||
@@ -515,29 +549,42 @@ function AppleBoard({ view: v, me, players, act }: BoardProps<AppleView>) {
|
||||
)}
|
||||
{mine && mine.status === 'stuck' && v.phase === 'playing' && (
|
||||
<div className="ap-over note" role="status">
|
||||
더 지울 수 있는 사과가 없어요! 사과 {mine.score}개 · 끝날 때까지 기다려요
|
||||
더 지울 수 있는 사과가 없어요! 사과 {mine.score}개{extraText(mine)} · 끝날 때까지 기다려요
|
||||
</div>
|
||||
)}
|
||||
{mine && mine.status === 'done' && v.phase === 'playing' && (
|
||||
<div className="ap-over note" role="status">
|
||||
여기까지 했어요! 사과 {mine.score}개 · 모두 끝날 때까지 기다려요
|
||||
여기까지 했어요! 사과 {mine.score}개{extraText(mine)} · 모두 끝날 때까지 기다려요
|
||||
</div>
|
||||
)}
|
||||
{mine && mine.status === 'left' && v.phase !== 'ended' && <div className="ap-over note">게임에서 나갔어요.</div>}
|
||||
{!mine && v.phase !== 'ended' && <div className="ap-over note">관전 중이에요 · 위에서 점수를 볼 수 있어요</div>}
|
||||
</div>
|
||||
{unlimited && canPlay && (
|
||||
<button
|
||||
type="button"
|
||||
className={`btn ${stopAsk ? 'btn-primary' : 'btn-secondary'} ap-stop`}
|
||||
onClick={() => {
|
||||
if (!stopAsk) return setStopAsk(true);
|
||||
setStopAsk(false);
|
||||
act({ type: 'stop' });
|
||||
}}
|
||||
>
|
||||
{stopAsk ? '한 번 더 누르면 여기까지 해요' : `여기까지 할래요 (사과 ${mine.score}개)`}
|
||||
</button>
|
||||
<div className="ap-acts">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-soft ap-stop"
|
||||
disabled={!!hintBox}
|
||||
onClick={() => {
|
||||
act({ type: 'hint' });
|
||||
say('힌트: 판에 노란 점선 상자로 합이 10인 묶음을 보여 줘요.');
|
||||
}}
|
||||
>
|
||||
💡 힌트{mine.hints ? ` (${mine.hints}번 받음)` : ''}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`btn ${stopAsk ? 'btn-primary' : 'btn-secondary'} ap-stop`}
|
||||
onClick={() => {
|
||||
if (!stopAsk) return setStopAsk(true);
|
||||
setStopAsk(false);
|
||||
act({ type: 'stop' });
|
||||
}}
|
||||
>
|
||||
{stopAsk ? '한 번 더 누르면 여기까지 해요' : `여기까지 할래요 (사과 ${mine.score}개)`}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{!phone && mine && v.phase !== 'ended' && <p className="ap-keys">마우스로 드래그해서 합이 10이면 손을 떼요 · 키보드: 화살표 + 스페이스(시작점·끝점), Esc 취소</p>}
|
||||
<p className="sr-only" aria-live="polite">
|
||||
@@ -573,6 +620,7 @@ function AppleSide({ view: v, me, players }: BoardProps<AppleView>) {
|
||||
{nick(players, s.id)}
|
||||
{s.id === me ? ' (나)' : ''}
|
||||
{s.status === 'stuck' ? ' · 다 지움' : s.status === 'done' ? ' · 여기까지' : s.status === 'left' ? ' · 나감' : ''}
|
||||
{s.timeMs !== null ? ` · ${formatElapsed(s.timeMs)}` : ''}
|
||||
</span>
|
||||
<strong style={{ fontVariantNumeric: 'tabular-nums' }} aria-hidden>
|
||||
🍎 {s.score}
|
||||
@@ -590,6 +638,7 @@ function AppleSide({ view: v, me, players }: BoardProps<AppleView>) {
|
||||
<span className="muted small">
|
||||
{' '}
|
||||
· 사과 {r.score}개 · {r.clears}번{r.left ? ' · 나감' : ''}
|
||||
{extraText(r)}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
@@ -615,8 +664,8 @@ function statusText(v: AppleView, me: string | null, players: Record<string, Pub
|
||||
return top && top.score > 0 ? `${nick(players, top.id)}님이 사과 ${top.score}개로 앞서요` : '모두 같은 판을 풀고 있어요';
|
||||
}
|
||||
if (mine.status === 'left') return '게임에서 나갔어요';
|
||||
if (mine.status === 'stuck') return `더 지울 사과가 없어요 · 사과 ${mine.score}개 · 끝날 때까지 기다려요`;
|
||||
if (mine.status === 'done') return `여기까지 했어요 · 사과 ${mine.score}개 · 모두 끝날 때까지 기다려요`;
|
||||
if (mine.status === 'stuck') return `더 지울 사과가 없어요 · 사과 ${mine.score}개${extraText(mine)} · 끝날 때까지 기다려요`;
|
||||
if (mine.status === 'done') return `여기까지 했어요 · 사과 ${mine.score}개${extraText(mine)} · 모두 끝날 때까지 기다려요`;
|
||||
return `사과 ${mine.score}개 지웠어요 · 합이 10이 되게 드래그!`;
|
||||
}
|
||||
|
||||
@@ -652,7 +701,7 @@ function Options({ value: o, onChange }: OptionsProps<AppleOptions>) {
|
||||
/>
|
||||
<span className="small muted">
|
||||
{o.timeLimitSec === null
|
||||
? '시간 제한 없이 각자 더 지울 사과가 없거나 [여기까지 할래요]를 누를 때까지 해요. 모두 끝나면 가장 많이 지운 사람이 이겨요.'
|
||||
? '시간 제한 없이 각자 더 지울 사과가 없거나 [여기까지 할래요]를 누를 때까지 해요. 스톱워치로 걸린 시간을 재고, 💡 힌트도 받을 수 있어요(결과에 걸린 시간과 힌트 횟수가 나와요). 모두 끝나면 가장 많이 지운 사람이 이겨요.'
|
||||
: '원래 게임은 2분이에요. 시간이 끝났을 때 사과를 가장 많이 지운 사람이 이겨요.'}
|
||||
</span>
|
||||
</div>
|
||||
@@ -686,7 +735,7 @@ function Rules({ options }: { options?: AppleOptions }) {
|
||||
</p>
|
||||
<p>
|
||||
{limitSec === null
|
||||
? '이 방은 제한 시간이 없어요. 각자 더 지울 수 있는 묶음이 없거나 [여기까지 할래요]를 누르면 끝나고, 모두 끝나면 사과를 가장 많이 지운 사람이 이겨요. 개수가 같으면 같은 순위예요. 연결이 끊긴 채 오래 돌아오지 않으면 그때까지 점수로 끝낸 것으로 봐요.'
|
||||
? '이 방은 제한 시간이 없어요. 각자 더 지울 수 있는 묶음이 없거나 [여기까지 할래요]를 누르면 끝나고, 모두 끝나면 사과를 가장 많이 지운 사람이 이겨요. 개수가 같으면 같은 순위예요. 연결이 끊긴 채 오래 돌아오지 않으면 그때까지 점수로 끝낸 것으로 봐요. 시작부터 끝낼 때까지 스톱워치로 시간을 재고, 막히면 [💡 힌트]로 합이 10인 묶음 하나를 볼 수 있어요. 결과에 걸린 시간과 힌트를 받은 횟수가 함께 나와요.'
|
||||
: `제한 시간은 ${limit}이에요. 시간이 끝나면 사과를 가장 많이 지운 사람이 이기고, 개수가 같으면 같은 순위예요. 모두 더 지울 수 있는 묶음이 없으면 조금 일찍 끝나요.`}{' '}
|
||||
혼자서도 할 수 있어요.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user