11document . addEventListener ( 'DOMContentLoaded' , ( ) => {
22 // Get the game board element
33 const gameBoard = document . getElementById ( 'gameBoard' ) ;
4+ const startSound = document . getElementById ( 'startSound' ) ; // Start screen audio element
5+ const eatSound = document . getElementById ( 'eatSound' ) ; // Eat sound element
6+ const powerUpSound = document . getElementById ( 'powerUpSound' ) ; // Power-up sound element
47
58 // Initialize variables
69 const grid = [ ] ; // Array to hold the grid cells
@@ -124,6 +127,7 @@ document.addEventListener('DOMContentLoaded', () => {
124127 score += 10 ;
125128 totalPacDots -- ;
126129 document . getElementById ( 'scoreValue' ) . textContent = score ;
130+ eatSound . play ( ) ; // Play the eat sound
127131 console . log ( 'Score:' , score ) ;
128132
129133 checkForWin ( ) ;
@@ -132,6 +136,8 @@ document.addEventListener('DOMContentLoaded', () => {
132136 score += 50 ;
133137 totalPowerPellets -- ;
134138 document . getElementById ( 'scoreValue' ) . textContent = score ;
139+ eatSound . play ( ) ; // Play the eat sound
140+ powerUpSound . play ( ) ; // Play the power-up sound
135141 console . log ( 'Score:' , score ) ;
136142
137143 activatePowerPellet ( ) ;
@@ -159,6 +165,8 @@ document.addEventListener('DOMContentLoaded', () => {
159165 ghosts . forEach ( ghost => ghost . unscare ( ) ) ;
160166 // Restart the power-pellet spawn timer
161167 powerPelletSpawnTimer = setInterval ( turnPacDotIntoPowerPellet , 30000 ) ;
168+ powerUpSound . pause ( ) ; // Stop the power-up sound
169+ powerUpSound . currentTime = 0 ; // Reset the power-up sound
162170 } , 10000 ) ; // Power pellet effect lasts for 10 seconds
163171 } ;
164172
@@ -462,4 +470,6 @@ document.getElementById('startGameButton').addEventListener('click', () => {
462470 document . getElementById ( 'startGameOverlay' ) . style . display = 'none' ; // Hide the start overlay
463471 initializeGame ( ) ; // Initialize the game
464472} ) ;
473+ // Play the start sound when the start overlay is displayed
474+ startSound . play ( ) ;
465475} ) ;
0 commit comments