@@ -158,11 +158,9 @@ function _() {
158
158
document . getElementById ( "time" ) . innerHTML = displayTime ( Math . floor ( ( new Date ( ) . getTime ( ) - timeStart ) / 1000 ) ) ;
159
159
} , 250 ) ;
160
160
161
- // dodgy way to play the sound while another is playing
162
- const sound1 = new Audio ( 'media/slide.wav' ) ;
163
- const sound2 = new Audio ( 'media/slide.wav' ) ;
164
- const sound3 = new Audio ( 'media/slide.wav' ) ;
165
- const sound4 = new Audio ( 'media/slide.wav' ) ;
161
+ const sound = new Howl ( {
162
+ src : [ 'media/slide.wav' ]
163
+ } ) ;
166
164
167
165
document . querySelectorAll ( ".tile" ) . forEach ( tile => {
168
166
tile . addEventListener ( "click" , ( ) => {
@@ -172,7 +170,7 @@ function _() {
172
170
173
171
if ( row < 3 ) {
174
172
if ( document . getElementById ( "row" + String ( row + 1 ) ) . children [ col ] . className . includes ( "blank" ) ) {
175
- sound1 . play ( ) ;
173
+ sound . play ( ) ;
176
174
tile . className += " down" ;
177
175
setTimeout ( ( ) => {
178
176
document . getElementById ( "row" + String ( row + 1 ) ) . children [ col ] . className = tile . className . replace ( " down" , "" ) ;
@@ -185,7 +183,7 @@ function _() {
185
183
}
186
184
} if ( row > 1 ) {
187
185
if ( document . getElementById ( "row" + String ( row - 1 ) ) . children [ col ] . className . includes ( "blank" ) ) {
188
- sound2 . play ( ) ;
186
+ sound . play ( ) ;
189
187
tile . className += " up" ;
190
188
setTimeout ( ( ) => {
191
189
document . getElementById ( "row" + String ( row - 1 ) ) . children [ col ] . className = tile . className . replace ( " up" , "" ) ;
@@ -198,7 +196,7 @@ function _() {
198
196
}
199
197
} if ( col < 2 ) {
200
198
if ( document . getElementById ( "row" + String ( row ) ) . children [ col + 1 ] . className . includes ( "blank" ) ) {
201
- sound3 . play ( ) ;
199
+ sound . play ( ) ;
202
200
tile . className += " right" ;
203
201
setTimeout ( ( ) => {
204
202
document . getElementById ( "row" + String ( row ) ) . children [ col + 1 ] . className = tile . className . replace ( " right" , "" ) ;
@@ -211,7 +209,7 @@ function _() {
211
209
}
212
210
} if ( col > 0 ) {
213
211
if ( document . getElementById ( "row" + String ( row ) ) . children [ col - 1 ] . className . includes ( "blank" ) ) {
214
- sound4 . play ( ) ;
212
+ sound . play ( ) ;
215
213
tile . className += " left" ;
216
214
setTimeout ( ( ) => {
217
215
document . getElementById ( "row" + String ( row ) ) . children [ col - 1 ] . className = tile . className . replace ( " left" , "" ) ;
0 commit comments