Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/components/game/GameCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,29 @@ function GameCanvas({
});
}, 1000);
} else if (questionTimeLeft === 0 && showQuestionModal) {
// 시간 초과 시 자동 제출
submitAnswer();
setShowQuestionModal(false);
// 시간 초과 시 자동으로 오답 처리
if (currentPixel) {
// 시간 초과시 자동으로 false 결과 전송
startCooldown(1);
setLives((prev) => Math.max(0, prev - 1));

sendGameResult({
x: currentPixel.x,
y: currentPixel.y,
color: currentPixel.color,
result: false,
});

setShowQuestionModal(false);
setShowResult(false);
setCurrentPixel(null);
}
}

return () => {
clearInterval(timerId);
};
}, [showQuestionModal, questionTimeLeft, submitAnswer]);
}, [showQuestionModal, questionTimeLeft, currentPixel, startCooldown, setLives, sendGameResult]);

// 게임 데이터 및 캔버스 초기화
const { getSynchronizedServerTime } = useTimeSyncStore();
Expand Down
14 changes: 12 additions & 2 deletions src/components/modal/QuestionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ const QuestionModal: React.FC<QuestionModalProps> = ({
}) => {
if (!isOpen || !currentQuestion) return null;

const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.key === 'Enter') {
event.preventDefault(); // 엔터 키 기본 동작 방지
event.stopPropagation(); // 이벤트 전파 중단
}
};

return (
<div className='fixed inset-0 z-50 flex items-center justify-center bg-black/70'>
<div
className='fixed inset-0 z-50 flex items-center justify-center bg-black/70'
onKeyDown={handleKeyDown} // 엔터 키 이벤트 핸들러 추가
>
<div className='w-full max-w-md rounded-xl bg-gray-900 p-6 shadow-2xl'>
<div className='mb-4 flex items-center justify-between'>
<h3 className='text-xl font-bold text-white'>문제</h3>
Expand Down Expand Up @@ -129,4 +139,4 @@ const QuestionModal: React.FC<QuestionModalProps> = ({
);
};

export default QuestionModal;
export default QuestionModal;