import { createMemo, createSignal, onCleanup, onMount } from 'solid-js' import Box from '@suid/material/Box' import Button from '@suid/material/Button' import Card from '@suid/material/Card' import CardContent from '@suid/material/CardContent' import Divider from '@suid/material/Divider' import Stack from '@suid/material/Stack' import TextField from '@suid/material/TextField' import Typography from '@suid/material/Typography' import AttemptIndicator from '../ui/AttemptIndicator' import ScoreDisplay from '../ui/ScoreDisplay' import Timer from '../ui/Timer' import { useTimer } from '../hooks/useTimer' export default function GameRoute() { // Placeholder game state until backend exists. const [question] = createSignal({ theme: 'Général', text: 'Quel est le plus petit nombre premier ?' }) const [answer, setAnswer] = createSignal('') const [attempts, setAttempts] = createSignal(0) const [hintUsed, setHintUsed] = createSignal(false) const [score, setScore] = createSignal(0) const [message, setMessage] = createSignal(null) const durationMs = 30 * 60 * 1000 const { remainingMs, isExpired, start } = useTimer(durationMs) onMount(() => start()) onCleanup(() => { // no-op; hook cleans itself }) const attemptsLeft = createMemo(() => Math.max(0, 3 - attempts())) const submit = () => { if (isExpired()) { setMessage('Session terminée (timeout).') return } const normalized = answer().trim().toLowerCase() const correct = normalized === '2' || normalized === 'deux' setAttempts((a) => a + 1) if (correct) { const delta = hintUsed() ? 1 : 2 setScore((s) => s + delta) setMessage(`Bonne réponse (+${delta}).`) } else { setMessage('Mauvaise réponse.') } setAnswer('') } const useHint = () => { if (hintUsed()) return setHintUsed(true) setMessage('Indice: c’est le seul nombre premier pair.') } return ( Partie Thème : {question().theme} {question().text} setAnswer(e.currentTarget.value)} fullWidth InputLabelProps={{ style: { color: '#cbd5e1' } }} InputProps={{ style: { color: '#e5e7eb' } }} onKeyDown={(e) => { if (e.key === 'Enter') submit() }} /> {message() && {message()}} {attemptsLeft() === 0 && Plus d'essais.} {isExpired() && Temps écoulé.} ) }