histogram width divide by mode, not total #2
13 changed files with 25 additions and 56 deletions
28
README.md
28
README.md
|
@ -1,30 +1,8 @@
|
|||
# Wordle Clone
|
||||
|
||||
- Go play the real Wordle [here](https://www.powerlanguage.co.uk/wordle/)
|
||||
- Read the story behind it [here](https://www.nytimes.com/2022/01/03/technology/wordle-word-game-creator.html)
|
||||
- Try a demo of this clone project [here](https://wordle.hannahmariepark.com)
|
||||
|
||||
_Inspiration:_
|
||||
This game is an open source clone of the immensely popular online word guessing game Wordle. Like many others all over the world, I saw the signature pattern of green, yellow, and white squares popping up all over social media and the web and had to check it out. After a few days of play, I decided it would be great for my learning to try to rebuild Wordle in React!
|
||||
|
||||
_Design Decisions:_
|
||||
I used a combination of React, Typescript, and Tailwind to build this Wordle Clone. When examining the original Wordle, I assumed the list might come from an external API or database, but after investigating in chrome dev tools I found that the list of words is simply stored in an array on the front end. I'm using the same list as the OG Wordle uses, but watch out for spoilers if you go find the file in this repo! The word match functionality is simple: the word array index increments each day from a fixed game epoch timestamp (only one puzzle per day!) roughly like so:
|
||||
|
||||
```
|
||||
WORDS[Math.floor((NOW_IN_MS - GAME_EPOCH_IN_MS) / ONE_DAY_IN_MS)]
|
||||
```
|
||||
|
||||
React enabled me to componentize the littlest parts of the game - keys and letter cells - and use them as the building blocks for the keyboard, word grid, and winning solution graphic. As for handling state, I used the built in useState and useEffect hooks to track guesses, whether the game is won, and to conditionally render popups.
|
||||
|
||||
In addition to other things, Typescript helped ensure type safety for the statuses of each guessed letter, which were used in many areas of the app and needed to be accurate for the game to work correctly.
|
||||
|
||||
I implemented Tailwind mostly because I wanted to learn how to use Tailwind CSS, but I also took advantage of [Tailwind UI](https://tailwindui.com/) with their [headless package](https://headlessui.dev/) to build the modals and notifications. This was such an easy way to build simple popups for how to play, winning the game, and invalid words.
|
||||
|
||||
_To Run Locally:_
|
||||
Clone the repository and perform the following command line actions:
|
||||
|
||||
```bash
|
||||
$ cd wordle
|
||||
$ cd game
|
||||
$ npm install
|
||||
$ npm run start
|
||||
```
|
||||
|
@ -32,8 +10,8 @@ $ npm run start
|
|||
_To build/run docker container:_
|
||||
|
||||
```bash
|
||||
$ docker build -t notwordle .
|
||||
$ docker run -d -p 3000:3000 notwordle
|
||||
$ docker build -t game .
|
||||
$ docker run -d -p 3000:3000 game
|
||||
```
|
||||
|
||||
open http://localhost:3000 in browser.
|
||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "wordle",
|
||||
"name": "game",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wordle",
|
||||
"name": "game",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@headlessui/react": "^1.4.2",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="Not Wordle" />
|
||||
<meta name="description" content="Game" />
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
|
@ -21,7 +21,7 @@
|
|||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>Not Wordle</title>
|
||||
<title>Game</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"short_name": "Not Wordle",
|
||||
"name": "Not Wordle",
|
||||
"short_name": "Game",
|
||||
"name": "Game",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import App from './App'
|
||||
import { WORDLE_TITLE } from './constants/strings'
|
||||
import { GAME_TITLE } from './constants/strings'
|
||||
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
|
@ -21,6 +21,6 @@ beforeEach(() => {
|
|||
|
||||
test('renders App component', () => {
|
||||
render(<App />)
|
||||
const linkElement = screen.getByText(WORDLE_TITLE)
|
||||
const linkElement = screen.getByText(GAME_TITLE)
|
||||
expect(linkElement).toBeInTheDocument()
|
||||
})
|
||||
|
|
|
@ -11,7 +11,7 @@ import { AboutModal } from './components/modals/AboutModal'
|
|||
import { InfoModal } from './components/modals/InfoModal'
|
||||
import { StatsModal } from './components/modals/StatsModal'
|
||||
import {
|
||||
WORDLE_TITLE,
|
||||
GAME_TITLE,
|
||||
WIN_MESSAGES,
|
||||
GAME_COPIED_MESSAGE,
|
||||
ABOUT_GAME_MESSAGE,
|
||||
|
@ -151,9 +151,7 @@ function App() {
|
|||
return (
|
||||
<div className="py-8 max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div className="flex w-80 mx-auto items-center mb-8 mt-12">
|
||||
<h1 className="text-xl grow font-bold dark:text-white">
|
||||
{WORDLE_TITLE}
|
||||
</h1>
|
||||
<h1 className="text-xl grow font-bold dark:text-white">{GAME_TITLE}</h1>
|
||||
<SunIcon
|
||||
className="h-6 w-6 cursor-pointer dark:stroke-white"
|
||||
onClick={() => handleDarkMode(!isDarkMode)}
|
||||
|
|
|
@ -13,7 +13,7 @@ export const Alert = ({ isOpen, message, variant = 'warning' }: Props) => {
|
|||
'fixed top-5 left-1/2 transform -translate-x-1/2 max-w-sm w-full shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 overflow-hidden',
|
||||
{
|
||||
'bg-rose-200': variant === 'warning',
|
||||
'bg-green-200 z-20': variant === 'success',
|
||||
'bg-blue-200 z-20': variant === 'success',
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ export const Cell = ({ value, status }: Props) => {
|
|||
'border-black dark:border-slate-100': value && !status,
|
||||
'bg-slate-400 dark:bg-slate-700 text-white border-slate-400 dark:border-slate-700':
|
||||
status === 'absent',
|
||||
'bg-green-500 text-white border-green-500': status === 'correct',
|
||||
'bg-yellow-500 dark:bg-yellow-700 text-white border-yellow-500 dark:border-yellow-700':
|
||||
'bg-blue-500 text-white border-blue-500': status === 'correct',
|
||||
'bg-orange-500 dark:bg-orange-700 text-white border-orange-500 dark:border-orange-700':
|
||||
status === 'present',
|
||||
'cell-animation': !!value,
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ export const Key = ({
|
|||
'bg-slate-200 dark:bg-slate-600 hover:bg-slate-300 active:bg-slate-400':
|
||||
!status,
|
||||
'bg-slate-400 text-white': status === 'absent',
|
||||
'bg-green-500 hover:bg-green-600 active:bg-green-700 text-white':
|
||||
'bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white':
|
||||
status === 'correct',
|
||||
'bg-yellow-500 hover:bg-yellow-600 active:bg-yellow-700 dark:bg-yellow-700 text-white':
|
||||
'bg-orange-500 hover:bg-orange-600 active:bg-orange-700 dark:bg-orange-700 text-white':
|
||||
status === 'present',
|
||||
}
|
||||
)
|
||||
|
|
|
@ -9,20 +9,13 @@ export const AboutModal = ({ isOpen, handleClose }: Props) => {
|
|||
return (
|
||||
<BaseModal title="About" isOpen={isOpen} handleClose={handleClose}>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-300">
|
||||
This is an open source clone of the game Wordle -{' '}
|
||||
This is an open source word guessing game -{' '}
|
||||
<a
|
||||
href="https://github.com/hannahcode/wordle"
|
||||
href="https://github.com/hannahcode/GAME"
|
||||
className="underline font-bold"
|
||||
>
|
||||
check out the code here
|
||||
</a>{' '}
|
||||
and{' '}
|
||||
<a
|
||||
href="https://www.powerlanguage.co.uk/wordle/"
|
||||
className="underline font-bold"
|
||||
>
|
||||
play the original here
|
||||
</a>
|
||||
</p>
|
||||
</BaseModal>
|
||||
)
|
||||
|
|
|
@ -10,8 +10,8 @@ export const InfoModal = ({ isOpen, handleClose }: Props) => {
|
|||
return (
|
||||
<BaseModal title="How to play" isOpen={isOpen} handleClose={handleClose}>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-300">
|
||||
Guess the WORDLE in 6 tries. After each guess, the color of the tiles
|
||||
will change to show how close your guess was to the word.
|
||||
Guess the word in 6 tries. After each guess, the color of the tiles will
|
||||
change to show how close your guess was to the word.
|
||||
</p>
|
||||
|
||||
<div className="flex justify-center mb-1 mt-4">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export const WORDLE_TITLE = 'Not Wordle'
|
||||
export const GAME_TITLE = 'GAME'
|
||||
|
||||
export const WIN_MESSAGES = ['Great Job!', 'Awesome', 'Well done!']
|
||||
export const GAME_COPIED_MESSAGE = 'Game copied to clipboard'
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { getGuessStatuses } from './statuses'
|
||||
import { solutionIndex } from './words'
|
||||
import { WORDLE_TITLE } from '../constants/strings'
|
||||
import { GAME_TITLE } from '../constants/strings'
|
||||
|
||||
export const shareStatus = (guesses: string[], lost: boolean) => {
|
||||
navigator.clipboard.writeText(
|
||||
`${WORDLE_TITLE} ${solutionIndex} ${lost ? 'X' : guesses.length}/6\n\n` +
|
||||
`${GAME_TITLE} ${solutionIndex} ${lost ? 'X' : guesses.length}/6\n\n` +
|
||||
generateEmojiGrid(guesses)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue