"""HTML/CSS rendering for Doodle Duel (human-draws mode only).""" from __future__ import annotations import html import random import config import game _LEADS = ["hmm...", "ooh!", "wait--", "is it...", "I think...", "let me guess...", "could be...", "aha,"] def _fmt_time(secs) -> str: t = int(secs) return f"{t // 60}:{t % 60:02d}" if t >= 60 else str(t) def _timer_ring(state) -> str: frac = max(0.0, min(1.0, state.time_left / config.ROUND_SECONDS)) R = 26 circ = 2 * 3.14159 * R off = circ * (1 - frac) color = "#46d39a" if frac > 0.5 else "#f4c04e" if frac > 0.2 else "#ef5d6c" return ( '' ) def render_topbar(state) -> str: if state.status == "idle": return ( '
' ) if state.status == "choosing": return ( '' ) ring = _timer_ring(state) hint_tag = "" if state.hints_used: pat = game.masked(state.word, state.revealed).replace(" ", " / ") hint_tag = f' · 💡{html.escape(pat)}'
cat_badge = (
f'{html.escape(state.category)}'
if state.category else ""
)
diff_icon = {"easy": "🟢", "medium": "🟡", "hard": "🔴"}.get(state.difficulty, "")
diff_badge = f'{diff_icon} {state.difficulty}'
best_tag = (
f'🏆 {state.best}'
if state.best > 0 else ""
)
return (
f''
)
def render_ai(state) -> str:
face = "🤖"
mood = "idle"
if state.status == "won":
face, mood = "🎉", "win"
elif state.status == "drawing":
mood = "think"
if state.status == "idle":
bubble = "👋 Ready when you are!"
elif state.status == "choosing":
face, mood = "🙈", "idle"
bubble = "👀 Eyes closed — pick your word!"
elif state.status == "won":
bubble = f"🎉 Got it — {html.escape(state.last_caught)}!"
elif state.status == "lost":
bubble = f"😵 Argh! It was {html.escape(state.word)} — I never stood a chance!"
elif state.guess_log:
recent = state.guess_log[-4:]
chips = "".join(f'{html.escape(g)}' for g in recent)
bubble = f"{random.choice(_LEADS)} {chips}?"
else:
bubble = "🔍 Hmm, let me see what you\'re drawing..."
return (
f'