|
| 1 | +import { Link, useSearchParams } from "react-router-dom"; |
| 2 | +import { useState } from "react"; |
| 3 | +import GameLayout from "./GameLayout"; |
| 4 | +import Switch from "../components/Switch"; |
| 5 | +import usePageMeta from "../hooks/usePageMeta"; |
| 6 | + |
| 7 | +const MODES = [ |
| 8 | + { key: "classic", label: "Classic", desc: "10s per flag, 5 options, skip allowed", icon: "🎯" }, |
| 9 | + { key: "endless", label: "Endless", desc: "Infinite flags, one wrong and it's over", icon: "♾️" }, |
| 10 | + { key: "speed", label: "Speed Run", desc: "60s total, answer as many as you can", icon: "⚡" }, |
| 11 | + { key: "zen", label: "Zen", desc: "No timer, just accuracy", icon: "🧘" }, |
| 12 | + { key: "hardcore", label: "Hardcore", desc: "5s, 6 options, no skipping", icon: "💀" }, |
| 13 | +]; |
| 14 | + |
| 15 | +export default function FlagModeSelect() { |
| 16 | + const [searchParams] = useSearchParams(); |
| 17 | + const [typed, setTyped] = useState(false); |
| 18 | + const [suggestions, setSuggestions] = useState(true); |
| 19 | + |
| 20 | + const buildLink = (modeKey) => { |
| 21 | + const params = new URLSearchParams(searchParams); |
| 22 | + if (typed) { |
| 23 | + params.set("typed", "true"); |
| 24 | + if (!suggestions) params.set("noSuggestions", "true"); |
| 25 | + } else { |
| 26 | + params.delete("typed"); |
| 27 | + params.delete("noSuggestions"); |
| 28 | + } |
| 29 | + const qs = params.toString(); |
| 30 | + return `/guesstheflag/${modeKey}${qs ? `?${qs}` : ""}`; |
| 31 | + }; |
| 32 | + |
| 33 | + usePageMeta( |
| 34 | + "Where in the world? - Guess the Flag", |
| 35 | + "Choose a game mode for the flag guessing game" |
| 36 | + ); |
| 37 | + |
| 38 | + return ( |
| 39 | + <GameLayout> |
| 40 | + <h1 className="text-2xl font-bold text-center">Guess the Flag</h1> |
| 41 | + <p className="text-sm text-center opacity-60">Choose a game mode</p> |
| 42 | + |
| 43 | + <div className="flex flex-col gap-2"> |
| 44 | + {MODES.map((mode) => ( |
| 45 | + <Link |
| 46 | + key={mode.key} |
| 47 | + to={buildLink(mode.key)} |
| 48 | + className="border p-3 rounded-lg shadow hover:bg-black/10 dark:hover:bg-white/10 transition-all flex items-center gap-3" |
| 49 | + > |
| 50 | + <span className="text-2xl">{mode.icon}</span> |
| 51 | + <div className="flex flex-col"> |
| 52 | + <span className="font-semibold">{mode.label}</span> |
| 53 | + <small className="opacity-70">{mode.desc}</small> |
| 54 | + </div> |
| 55 | + </Link> |
| 56 | + ))} |
| 57 | + </div> |
| 58 | + |
| 59 | + <div className="flex flex-col items-center gap-2"> |
| 60 | + <Switch checked={typed} onChange={setTyped} label="Type answers (no multiple choice)" /> |
| 61 | + {typed && ( |
| 62 | + <Switch checked={suggestions} onChange={setSuggestions} label="Show suggestions" /> |
| 63 | + )} |
| 64 | + </div> |
| 65 | + </GameLayout> |
| 66 | + ); |
| 67 | +} |
0 commit comments