Skip to content

Commit

Permalink
Adding Sound Effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
13Sharad committed Oct 28, 2024
1 parent 06065e6 commit 6bde90b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions paras/src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './App.css';
import Sparkle from './Sparkle'; // If Sparkle is not used, you can remove this import.
import { Link } from 'react-router-dom';
const initialBoard = Array(9).fill(null);
import winSoundFile from './win-sound1.wav';

const App = () => {
const [board, setBoard] = useState(initialBoard);
Expand All @@ -17,6 +18,8 @@ const App = () => {
const [highestScorePlayerO, setHighestScorePlayerO] = useState(0);
const [gameMode, setGameMode] = useState(null);

const winSound = new Audio(winSoundFile);

// Handle click on a cell
const handleCellClick = (index) => {
if (board[index] || winner || draw) return;
Expand All @@ -40,6 +43,11 @@ const App = () => {
if (board[a] === player && board[b] === player && board[c] === player) {
setWinner(player);
updateScoreAndHighestScore(player);
try {
winSound.play(); // Play sound on win
} catch (error) {
console.error("Failed to play win sound:", error);
}
return;
}
}
Expand Down
Binary file added paras/src/win-sound1.wav
Binary file not shown.

0 comments on commit 6bde90b

Please sign in to comment.