Skip to content

Commit

Permalink
feat: show score + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
willuhmjs committed Nov 30, 2023
1 parent 07ea090 commit 233f319
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/lib/GameMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import words from '../data/words';
import Fa from 'svelte-fa';
import { faShuffle, faFaceLaughBeam, faFaceSadCry } from '@fortawesome/free-solid-svg-icons';
import { gameStats } from "./gameState";
import { gameStats, type GameStat } from "./gameState";
const getButtonColor = (difficulty: 'easy' | 'medium' | 'hard' | 'expert') => {
switch (difficulty) {
case 'easy':
Expand All @@ -17,9 +17,27 @@
return '#808080';
}
};
export const calculatePoints = (gameStat: GameStat): number => {
switch (gameStat.hintsLeft) {
case 4:
return 1000;
case 3:
return 750;
case 2:
return 500;
case 1:
return 250;
case 0:
return 100;
default:
return 0;
}
};
</script>

<div class="wrapper">
<h2 style="margin-top: 0!important;">score: {$gameStats.reduce((acc, stat) => acc + calculatePoints(stat), 0)}</h2>
<a class="button randombutton" href={`/random`}
><Fa style="width: 100%" icon={faShuffle} /></a
>
Expand All @@ -35,9 +53,9 @@
>
<b>#{reverseIndex + 1}</b>
<span style="text-align: right">{#if userWordStat}
{#if userWordStat.hintsLeft > 0}
{#if userWordStat.hintsLeft >= 0}
<Fa fw=true icon={faFaceLaughBeam} />
{:else if userWordStat.hintsLeft === 0}
{:else if userWordStat.hintsLeft === -1}
<Fa fw=true icon={faFaceSadCry} />
{/if}
{/if} {word.difficulty}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Hints.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
...$gameStats,
{
word,
hintsLeft: hintnumber
hintsLeft: $won ? hintnumber : -1
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
...$gameStats,
{
word,
hintsLeft: 0
hintsLeft: -1
}
];
}
Expand Down

0 comments on commit 233f319

Please sign in to comment.