Skip to content

Commit b06299e

Browse files
csantosrMrRoiz
authored andcommitted
feat: word selection
1 parent 2bc6105 commit b06299e

File tree

5 files changed

+254
-10
lines changed

5 files changed

+254
-10
lines changed

app/[lang]/game/local/play/_components/game.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
'use client';
22

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";
912

10-
export const Game: FC<{ dict: Dictionary }> = ({ dict }) => {
13+
14+
export const Game: FC<{ dict: Dictionary; lang: Locale }> = ({ dict, lang }) => {
1115
const gameSettings = useAtomValue(gameSettingsAtom);
1216
const [currentPlayerIndex, setCurrentPlayerIndex] = useState(0);
1317
const [gameKey, setGameKey] = useState(0);
1418

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+
1526
// Generate spy assignments
1627
// biome-ignore lint/correctness/useExhaustiveDependencies: gameKey is intentionally used to trigger regeneration
1728
const playerRoles = useMemo(() => {
@@ -72,7 +83,7 @@ export const Game: FC<{ dict: Dictionary }> = ({ dict }) => {
7283

7384
<GameCard
7485
player={currentPlayer}
75-
word="WORD"
86+
word={word}
7687
dict={dict}
7788
onFinishCheck={() => setCurrentPlayerIndex(currentPlayerIndex + 1)}
7889
/>

app/[lang]/game/local/play/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Page = async ({ params }: PageProps<'/[lang]/game/local/play'>) => {
88

99
const dict = await getDictionary(lang);
1010

11-
return <Game dict={dict} />;
11+
return <Game dict={dict} lang={params.lang} />;
1212
};
1313

1414
export default Page;

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"@/game/*": ["./app/[lang]/game/*"],
2424
"@/providers/*": ["./app/_providers/*"],
2525
"@/primitives/*": ["./app/_primitives/*"],
26-
"@/dictionaries": ["./app/[lang]/dictionaries.ts"]
26+
"@/dictionaries": ["./app/[lang]/dictionaries.ts"],
27+
"@/word-bank/*": ["./word-bank/*"]
2728
}
2829
},
2930
"include": [

word-bank/en.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[
2+
"Airport",
3+
"American football",
4+
"Amusement park",
5+
"Arepa",
6+
"Athletics",
7+
"Avatar",
8+
"Back to the Future",
9+
"Backpack",
10+
"Badminton",
11+
"Bank",
12+
"Basketball",
13+
"Beach",
14+
"Bear",
15+
"Bread",
16+
"Broom",
17+
"Bus stop",
18+
"Cat",
19+
"Cereal",
20+
"Charging cable",
21+
"Cheese",
22+
"Chocolate",
23+
"Clock",
24+
"Cycling",
25+
"Dog",
26+
"Dolphin",
27+
"E.T.",
28+
"Eagle",
29+
"Elephant",
30+
"Forrest Gump",
31+
"French fries",
32+
"Fried chicken",
33+
"Frog",
34+
"Fruit salad",
35+
"Gladiator",
36+
"Giraffe",
37+
"Golf",
38+
"Gym",
39+
"Hamburger",
40+
"Harry Potter",
41+
"Headphones",
42+
"Hockey",
43+
"Hospital",
44+
"Hotel",
45+
"Ice cream",
46+
"Inception",
47+
"Jaws",
48+
"Jurassic Park",
49+
"Kangaroo",
50+
"Key",
51+
"Lamp",
52+
"Library",
53+
"Lion",
54+
"Martial arts",
55+
"Mirror",
56+
"Monkey",
57+
"Movie theater",
58+
"Museum",
59+
"Notebook",
60+
"Owl",
61+
"Panda",
62+
"Park",
63+
"Pasta",
64+
"Pen",
65+
"Penguin",
66+
"Pharmacy",
67+
"Pillow",
68+
"Pizza",
69+
"Pulp Fiction",
70+
"Rabbit",
71+
"Remote control",
72+
"Restaurant",
73+
"Rocky",
74+
"Rugby",
75+
"Salad",
76+
"Sandwich",
77+
"School",
78+
"Scissors",
79+
"Shark",
80+
"Shrek",
81+
"Shoes",
82+
"Skiing",
83+
"Skateboarding",
84+
"Smoothie",
85+
"Snake",
86+
"Soccer",
87+
"Soup",
88+
"Spoon",
89+
"Stadium",
90+
"Star Wars",
91+
"Steak",
92+
"Supermarket",
93+
"Surfing",
94+
"Sushi",
95+
"Table tennis",
96+
"Taco",
97+
"Tennis",
98+
"The Avengers",
99+
"The Dark Knight",
100+
"The Godfather",
101+
"The Lion King",
102+
"The Matrix",
103+
"Tiger",
104+
"Titanic",
105+
"Toothbrush",
106+
"Towel",
107+
"Train station",
108+
"Umbrella",
109+
"University",
110+
"Volleyball",
111+
"Wallet",
112+
"Water bottle",
113+
"Whale",
114+
"Yogurt",
115+
"Zoo"
116+
]

word-bank/es.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[
2+
"Aeropuerto",
3+
"Fútbol americano",
4+
"Parque de diversiones",
5+
"Arepa",
6+
"Atletismo",
7+
"Avatar",
8+
"Volver al futuro",
9+
"Mochila",
10+
"Bádminton",
11+
"Banco",
12+
"Baloncesto",
13+
"Playa",
14+
"Oso",
15+
"Pan",
16+
"Escoba",
17+
"Parada de autobús",
18+
"Gato",
19+
"Cereal",
20+
"Cable de carga",
21+
"Queso",
22+
"Chocolate",
23+
"Reloj",
24+
"Ciclismo",
25+
"Perro",
26+
"Delfín",
27+
"E.T.",
28+
"Águila",
29+
"Elefante",
30+
"Forrest Gump",
31+
"Papas fritas",
32+
"Pollo frito",
33+
"Rana",
34+
"Ensalada de frutas",
35+
"Gladiador",
36+
"Jirafa",
37+
"Golf",
38+
"Gimnasio",
39+
"Hamburguesa",
40+
"Harry Potter",
41+
"Audífonos",
42+
"Hockey",
43+
"Hospital",
44+
"Hotel",
45+
"Helado",
46+
"El origen",
47+
"Tiburón",
48+
"Parque Jurásico",
49+
"Canguro",
50+
"Llave",
51+
"Lámpara",
52+
"Biblioteca",
53+
"León",
54+
"Artes marciales",
55+
"Espejo",
56+
"Mono",
57+
"Cine",
58+
"Museo",
59+
"Cuaderno",
60+
"Búho",
61+
"Panda",
62+
"Parque",
63+
"Pasta",
64+
"Bolígrafo",
65+
"Pingüino",
66+
"Farmacia",
67+
"Almohada",
68+
"Pizza",
69+
"Pulp Fiction",
70+
"Conejo",
71+
"Control remoto",
72+
"Restaurante",
73+
"Rocky",
74+
"Rugby",
75+
"Ensalada",
76+
"Sándwich",
77+
"Escuela",
78+
"Tijeras",
79+
"Tiburón",
80+
"Shrek",
81+
"Zapatos",
82+
"Esquí",
83+
"Patineta",
84+
"Batido",
85+
"Serpiente",
86+
"Fútbol",
87+
"Sopa",
88+
"Cuchara",
89+
"Estadio",
90+
"La guerra de las galaxias",
91+
"Bistec",
92+
"Supermercado",
93+
"Surf",
94+
"Sushi",
95+
"Tenis de mesa",
96+
"Taco",
97+
"Tenis",
98+
"Los Vengadores",
99+
"El caballero de la noche",
100+
"El padrino",
101+
"El rey león",
102+
"Matrix",
103+
"Tigre",
104+
"Titanic",
105+
"Cepillo de dientes",
106+
"Toalla",
107+
"Estación de tren",
108+
"Paraguas",
109+
"Universidad",
110+
"Voleibol",
111+
"Billetera",
112+
"Botella de agua",
113+
"Ballena",
114+
"Yogur",
115+
"Zoológico"
116+
]

0 commit comments

Comments
 (0)