Skip to content

Commit

Permalink
Update sounds.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit30swgoh authored Sep 26, 2024
1 parent 668bd07 commit f5ea176
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions 26.9-backgammon/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ const sounds = {
invalidMove: new Audio('assets/sounds/invalid-move.mp3'),
win: new Audio('assets/sounds/win.mp3'),

playSound: function (sound) {
switch (sound) {
case 'dice':
this.diceRoll.play();
break;
case 'move':
this.pieceMove.play();
break;
case 'invalid':
this.invalidMove.play();
break;
case 'win':
this.win.play();
break;
// Play the sound corresponding to the given type
playSound: function (type) {
const soundMap = {
'dice': this.diceRoll,
'move': this.pieceMove,
'invalid': this.invalidMove,
'win': this.win
};

// Play the appropriate sound if the type exists
if (soundMap[type]) {
soundMap[type].play();
}
}
};

0 comments on commit f5ea176

Please sign in to comment.