feat : add sounds

This commit is contained in:
GuillaumeSD
2024-03-20 04:57:37 +01:00
parent 32fc196e74
commit 9e497cb24b
15 changed files with 74 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ import { Button, CircularProgress, Grid, Typography } from "@mui/material";
import { useAtom, useAtomValue } from "jotai";
import { gameAtom, isGameInProgressAtom } from "./states";
import { useEffect } from "react";
import { playGameEndSound } from "@/lib/sounds";
export default function GameInProgress() {
const game = useAtomValue(gameAtom);
@@ -11,6 +12,11 @@ export default function GameInProgress() {
if (game.isGameOver()) setIsGameInProgress(false);
}, [game, setIsGameInProgress]);
const handleResign = () => {
playGameEndSound();
setIsGameInProgress(false);
};
if (!isGameInProgress) return null;
return (
@@ -42,7 +48,7 @@ export default function GameInProgress() {
xs={12}
gap={2}
>
<Button variant="outlined" onClick={() => setIsGameInProgress(false)}>
<Button variant="outlined" onClick={handleResign}>
Resign
</Button>
</Grid>