Skip to content

Commit

Permalink
add #playMusic
Browse files Browse the repository at this point in the history
  • Loading branch information
aandre6891 committed Jul 12, 2023
1 parent c9c3e4e commit fe5e95a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Binary file added media/tetris-soundtrack.mp3
Binary file not shown.
20 changes: 19 additions & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class Game {
// The playLoop runs the game
// Instantiate a turn-cycle loop, that breaks to allow the game to swap players
async playLoop(test) {
this.playMusic();
let turnInProgress = false;
let timer = 100; // time between ticks in ms
let timer = 10000; // time between ticks in ms

while (!turnInProgress) {
turnInProgress = true;
Expand Down Expand Up @@ -188,6 +189,23 @@ class Game {
return grid;
}

playMusic() {
const music = new Audio('media/tetris-soundtrack.mp3');
music.loop = true;
music.volume = 0.1;

document.addEventListener("click", function() { // unmute and play the music if the user clicks anywhere in the Document
music.muted = false;
music.play();
});
console.log("playMusic() returned");

document.addEventListener("keydown", function() { // unmute and play the music if the user presses any button
music.muted = false;
music.play();
});
}

async #delay(time) {
await new Promise(resolve => setTimeout(resolve, time));
}
Expand Down

0 comments on commit fe5e95a

Please sign in to comment.