feat : add sounds
This commit is contained in:
@@ -40,17 +40,13 @@ export default function Board() {
|
||||
target: Square,
|
||||
piece: string
|
||||
): boolean => {
|
||||
try {
|
||||
const result = makeBoardMove({
|
||||
from: source,
|
||||
to: target,
|
||||
promotion: piece[1]?.toLowerCase() ?? "q",
|
||||
});
|
||||
const result = makeBoardMove({
|
||||
from: source,
|
||||
to: target,
|
||||
promotion: piece[1]?.toLowerCase() ?? "q",
|
||||
});
|
||||
|
||||
return !!result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return !!result;
|
||||
};
|
||||
|
||||
const handleSquareLeftClick = () => {
|
||||
|
||||
@@ -70,17 +70,14 @@ export default function Board() {
|
||||
piece: string
|
||||
): boolean => {
|
||||
if (!piece || piece[0] !== playerColor || !isGameInProgress) return false;
|
||||
try {
|
||||
const result = makeGameMove({
|
||||
from: source,
|
||||
to: target,
|
||||
promotion: piece[1]?.toLowerCase() ?? "q",
|
||||
});
|
||||
|
||||
return !!result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
const result = makeGameMove({
|
||||
from: source,
|
||||
to: target,
|
||||
promotion: piece[1]?.toLowerCase() ?? "q",
|
||||
});
|
||||
|
||||
return !!result;
|
||||
};
|
||||
|
||||
const isPieceDraggable = ({ piece }: { piece: string }): boolean => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
gameAtom,
|
||||
} from "../states";
|
||||
import { useChessActions } from "@/hooks/useChessActions";
|
||||
import { playGameStartSound } from "@/lib/sounds";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
@@ -49,6 +50,7 @@ export default function GameSettingsDialog({ open, onClose }: Props) {
|
||||
blackName:
|
||||
playerColor === Color.Black ? "You" : `Stockfish level ${skillLevel}`,
|
||||
});
|
||||
playGameStartSound();
|
||||
setIsGameInProgress(true);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user