generated from PrithvirajMazumder/react-tailwind-daisyui-template
-
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.
- Loading branch information
1 parent
e662b04
commit 15f0d32
Showing
9 changed files
with
136 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export interface IMedal { | ||
name: string | ||
emoji: string | ||
differenceFromOptimal: number | ||
} | ||
|
||
export const MEDALS: IMedal[] = [ | ||
{ | ||
name: 'Perfection', | ||
emoji: 'π', | ||
differenceFromOptimal: 0 | ||
}, | ||
{ | ||
name: 'Gold', | ||
emoji: 'π₯', | ||
differenceFromOptimal: 1 | ||
}, | ||
{ | ||
name: 'Silver', | ||
emoji: 'π₯', | ||
differenceFromOptimal: 2 | ||
}, | ||
{ | ||
name: 'Bronze', | ||
emoji: 'π₯', | ||
differenceFromOptimal: 3 | ||
} | ||
] | ||
|
||
export const NONE_MEDAL: IMedal = { | ||
name: 'No', | ||
emoji: 'π«€', | ||
differenceFromOptimal: -1 | ||
} |
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
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,43 @@ | ||
import { useMemo } from 'react' | ||
import { MEDALS, NONE_MEDAL } from '../../const/medals' | ||
import { generateSolution } from '../../util/solution/generateSolution' | ||
import { lettersForToday } from '../../util/lottery/letters' | ||
import { getMedal } from '../../util/results/getMedal' | ||
import { useAtomValue } from 'jotai' | ||
import { words } from '../../store/game' | ||
|
||
export const Medal = () => { | ||
const wordList = useAtomValue(words) | ||
|
||
const medal = getMedal(wordList.length) | ||
|
||
const perfectSolutionWordCount = useMemo(() => { | ||
return generateSolution(lettersForToday()).length | ||
}, []) | ||
|
||
return ( | ||
<div className="center card mt-4 w-full select-text bg-base-100 shadow-xl"> | ||
<div className="card-body flex flex-col items-center"> | ||
<h3 className="mb-2 text-xl font-bold">Medal</h3> | ||
<div className="flex flex-col items-center justify-center gap-5"> | ||
<div> | ||
<h2 className="text-7xl font-bold ">{medal.emoji}</h2> | ||
</div> | ||
|
||
<div className="text-md opacity-90"> | ||
{MEDALS.map((medal) => { | ||
return ( | ||
<p key={medal.name + '-medal'}> | ||
{medal.emoji} {medal.differenceFromOptimal + perfectSolutionWordCount} Words | ||
</p> | ||
) | ||
})} | ||
<p> | ||
{NONE_MEDAL.emoji} {perfectSolutionWordCount + 4}+ Words | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</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
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,16 @@ | ||
import { MEDALS, NONE_MEDAL } from '../../const/medals' | ||
import { lettersForToday } from '../lottery/letters' | ||
import { generateSolution } from '../solution/generateSolution' | ||
|
||
export const getMedal = (wordsUsed: number) => { | ||
const solutionWordsUsed = generateSolution(lettersForToday()).length | ||
const difference = Math.abs(solutionWordsUsed - wordsUsed) | ||
|
||
let medal = MEDALS.find((medal) => { | ||
return medal.differenceFromOptimal === difference | ||
}) | ||
if (!medal) { | ||
medal = NONE_MEDAL | ||
} | ||
return medal | ||
} |
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