Play audio on game other

This commit is contained in:
Pierre HUBERT 2020-03-23 18:33:33 +01:00
parent c87382a891
commit 7cf478e35e
3 changed files with 13 additions and 0 deletions

BIN
assets/gameOver.mp3 Normal file

Binary file not shown.

View File

@ -43,6 +43,7 @@ body {
list-style: none;
line-height: 30px;
padding: 0px;
margin: 50px;
}
a {

View File

@ -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 = "#";
}