|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { useAtomValue } from 'jotai'; |
4 | | -import { type FC, useCallback, useMemo, useState } from 'react'; |
5 | | -import type { Dictionary } from '@/dictionaries'; |
6 | | -import { GameCard } from '@/game/_components/card'; |
7 | | -import { gameSettingsAtom } from '../../_store/game-settings'; |
8 | | -import { GameTimer } from './timer'; |
| 3 | +import { useAtomValue } from "jotai"; |
| 4 | +import { type FC, useCallback, useMemo, useState } from "react"; |
| 5 | +import { GameCard } from "@/game/_components/card"; |
| 6 | +import { gameSettingsAtom } from "../../_store/game-settings"; |
| 7 | +import { GameTimer } from "./timer"; |
| 8 | +import { Dictionary } from "@/dictionaries"; |
| 9 | +import enWords from "@/word-bank/en.json"; |
| 10 | +import esWords from "@/word-bank/es.json"; |
| 11 | +import type { Locale } from "@/dictionaries"; |
9 | 12 |
|
10 | | -export const Game: FC<{ dict: Dictionary }> = ({ dict }) => { |
| 13 | + |
| 14 | +export const Game: FC<{ dict: Dictionary; lang: Locale }> = ({ dict, lang }) => { |
11 | 15 | const gameSettings = useAtomValue(gameSettingsAtom); |
12 | 16 | const [currentPlayerIndex, setCurrentPlayerIndex] = useState(0); |
13 | 17 | const [gameKey, setGameKey] = useState(0); |
14 | 18 |
|
| 19 | + // Get random word based on language |
| 20 | + const word = useMemo(() => { |
| 21 | + const words = lang === "es" ? esWords : enWords; |
| 22 | + const randomIndex = Math.floor(Math.random() * words.length); |
| 23 | + return words[randomIndex]; |
| 24 | + }, [lang, gameKey]); |
| 25 | + |
15 | 26 | // Generate spy assignments |
16 | 27 | // biome-ignore lint/correctness/useExhaustiveDependencies: gameKey is intentionally used to trigger regeneration |
17 | 28 | const playerRoles = useMemo(() => { |
@@ -72,7 +83,7 @@ export const Game: FC<{ dict: Dictionary }> = ({ dict }) => { |
72 | 83 |
|
73 | 84 | <GameCard |
74 | 85 | player={currentPlayer} |
75 | | - word="WORD" |
| 86 | + word={word} |
76 | 87 | dict={dict} |
77 | 88 | onFinishCheck={() => setCurrentPlayerIndex(currentPlayerIndex + 1)} |
78 | 89 | /> |
|
0 commit comments