- You can enjoy Hangman with random English word.
- Play in Here
- Check your Node.js version (>= 18)
git clone https://github.com/chogyejin/hangman-en.git
cd hangman-en
andnpm i
- Set
.env
file in root directory withAPI_URL
andAPI_KEY
(See here API Ninjas.) npm run dev
ornpm run build && npm run start -- -p [your port number]
- react: 18.2.0
- next: 13.5.6 (Pages Router)
- typescript: 4.9.3
- @emotion/react: 11.11.1
- @emotion/styled: 11.11.0
- axios: 1.6.2
- vitest: 1.0.3
- msw: 2.2.0
hangman-en
├─ pages
│ ├─ api
│ │ └─ randomword.ts
│ ├─ 404.tsx
│ ├─ _app.tsx
│ ├─ game.tsx
│ └─ index.tsx
└─ src
├─ __tests__
│ ├─ GamePage.test.tsx
│ └─ HomePage.test.tsx
├─ components
│ ├─ Button.tsx
│ ├─ Dropdown.tsx
│ ├─ GameBoard.tsx
│ ├─ HangManCanvas.tsx
│ ├─ Keyboard.tsx
│ ├─ KeyboardList.tsx
│ ├─ Letter.tsx
│ ├─ Loading.tsx
│ └─ Retry.tsx
├─ constants
│ └─ index.ts
├─ hooks
│ ├─ useClickOutside.ts
│ ├─ useGuessing.ts
│ └─ useWord.ts
├─ lib
│ ├─ api
│ │ └─ getRandomword.ts
│ ├─ axios
│ │ └─ index.ts
│ └─ utils
│ ├─ capitalize.ts
│ ├─ draw.ts
│ ├─ gameType.ts
│ ├─ propertNoun.ts
│ └─ range.ts
├─ mocks
│ ├─ handlers.ts
│ └─ server.ts
├─ styles
│ └─ globalStyles.ts
└─ types.ts
- React function component(Typescript)
- Font: Spoqa Han Sans Neo
- reset CSS(globalStyles in
_app.tsx
) - styled components by emotion
-
Free random API provided by API Ninjas
- In the previous API specification, a string was returned, but now a parameter called
limit
has been added(default 1) and an array of strings is returned.
- In the previous API specification, a string was returned, but now a parameter called
-
By default API key is exposed in request headers(
x-api-key
), we can hide my own API key using Next.js's API Routes -
Proper nouns are so hard to guess, so check the response and re-request by axios instance`s intercepter.
useWord
: fetch word and returnword
,isLoading
andrefetch
useGuessing
: manage currentguessing word
,result
andreset
function.useClickOutside
: addevent listener
that hashandler
for click
- In
HangmanCanvas
component, getting closer to the wrong count, draw hangman(refer to here) - When you reach the certain wrong count(8), game is over
- custom
404.tsx
- If the query string is incorrect when the user accesses the game page by manipulating the url, screen moves to the 404 page through
getServersideprops
in pages/game.tsx.
- Integration tests for pages with Vitest and React Testing Library
- Mock a API with MSW