Play audio on game other
This commit is contained in:
parent
c87382a891
commit
7cf478e35e
BIN
assets/gameOver.mp3
Normal file
BIN
assets/gameOver.mp3
Normal file
Binary file not shown.
@ -43,6 +43,7 @@ body {
|
||||
list-style: none;
|
||||
line-height: 30px;
|
||||
padding: 0px;
|
||||
margin: 50px;
|
||||
}
|
||||
|
||||
a {
|
||||
|
12
script.js
12
script.js
@ -51,6 +51,17 @@ function randInt(min, max) {
|
||||
return Math.floor((Math.random()*max) + min)
|
||||
}
|
||||
|
||||
/**
|
||||
* Play an audio file
|
||||
*
|
||||
* @param {String} url The URL of the audio file to play
|
||||
*/
|
||||
function playAudio(url) {
|
||||
const audio = document.createElement("audio");
|
||||
audio.src = url
|
||||
audio.play();
|
||||
}
|
||||
|
||||
// Get elements
|
||||
const startScreen = byId("startScreen")
|
||||
const gameScreen = byId("gameScreen")
|
||||
@ -275,6 +286,7 @@ async function startGame(gameID) {
|
||||
* Call this function once the user loose the game
|
||||
*/
|
||||
function gameOver() {
|
||||
playAudio("assets/gameOver.mp3");
|
||||
alert("Game over !!!");
|
||||
location.href = "#";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user