diff --git a/assets/gameOver.mp3 b/assets/gameOver.mp3 new file mode 100644 index 0000000..4b83826 Binary files /dev/null and b/assets/gameOver.mp3 differ diff --git a/assets/style.css b/assets/style.css index 89dd03d..cb83d83 100644 --- a/assets/style.css +++ b/assets/style.css @@ -43,6 +43,7 @@ body { list-style: none; line-height: 30px; padding: 0px; + margin: 50px; } a { diff --git a/script.js b/script.js index 4255ed5..8ba325c 100644 --- a/script.js +++ b/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 = "#"; }