-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/subvisual/wordle3 into rs/a…
…dd-gamespace-component
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import './alphabet.css' | ||
|
||
export function Alphabet({ playerAlphabet }) { | ||
const alphabetStates = playerAlphabet?.map(({ state }) => state.toString()) || [] | ||
|
||
/** | ||
* colorMap maps the different states of a letter to a CSS color. | ||
* The states are: 0 = miss ; 1 = exists ; 2 = hit ; 3 = discarded | ||
*/ | ||
const colorMap = { | ||
'0': 'var(--gray)', | ||
'1': 'var(--yellow)', | ||
'2': 'var(--green)', | ||
'3': 'var(--dark-gray)', | ||
} | ||
|
||
/** | ||
* qwertyLayout is an array of the letters in the QWERTY layout. | ||
* It is used to generate the grid of letters. | ||
*/ | ||
const qwertyLayout = [ | ||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', | ||
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', | ||
'Z', 'X', 'C', 'V', 'B', 'N', 'M', | ||
] | ||
|
||
return ( | ||
<div className="alphabet"> | ||
{qwertyLayout.map((char, index) => ( | ||
<p | ||
key={index} | ||
style={{ backgroundColor: alphabetStates && colorMap[alphabetStates[index]] || 'var(--gray)' }} | ||
> | ||
{char} | ||
</p> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.alphabet { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 5px; | ||
justify-content: center; | ||
margin: 20px auto; | ||
max-width: 40%; | ||
} | ||
|
||
.alphabet p { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border-radius: 5px; | ||
width: 30px; | ||
height: 40px; | ||
margin: 0; | ||
} |