diff --git a/js/game.js b/js/game.js index db64f55..2c81ebc 100644 --- a/js/game.js +++ b/js/game.js @@ -48,28 +48,28 @@ class Game { onPlayerWin() { this.isGameover = true - bgMusic.pause(); - let winSound = new Audio('./sounds/win.mp3'); + let winSound = new Audio('../assets/sounds/win.mp3'); winSound.play(); const player = this.players.reduce((prev, current) => { return prev.filledBoxes > current.filledBoxes ? prev : current }); - setTimeout(() => { - let play = this.players[0].filledBoxes - - //Check for winner - if (this.players.every((p) => p.filledBoxes == play)) { - this.playerNameUI.parentElement.textContent = "Nobody wins" - this.playerTurnBgUI.classList.add("no-win") - this.playerTurnBgUI.style.background = "#eaeaea" - } else { - this.playerNameUI.parentElement.textContent = `${player.name} wins` - this.playerTurnBgUI.classList.add("win") - this.playerTurnBgUI.style.background = player.color - } - }, 500); + let play = this.players[0].filledBoxes + + //Check for winner + if (this.players.every((p) => p.filledBoxes == play)) { + this.playerNameUI.parentElement.textContent = "Nobody wins" + this.playerTurnBgUI.classList.add("no-win") + this.playerTurnBgUI.style.background = "#eaeaea" + } else { + this.playerNameUI.parentElement.textContent = `${player.name} wins` + this.playerTurnBgUI.classList.add("win") + this.playerTurnBgUI.style.background = player.color + } + + // Open the win overlay + document.getElementById("win-overlay").style.height = "100%"; } onPlayerSwitch() { @@ -183,10 +183,10 @@ document.addEventListener("DOMContentLoaded", () => { soundToggleBtn.addEventListener("click", () => { if (bgMusic.paused) { bgMusic.play(); - soundToggleBtn.innerText = "Sound Off"; + soundToggleBtn.innerText = "Sound On"; } else { bgMusic.pause(); - soundToggleBtn.innerText = "Sound On"; + soundToggleBtn.innerText = "Sound Off"; } }); }); diff --git a/pages/game.html b/pages/game.html index 077eeba..5a8e6b9 100644 --- a/pages/game.html +++ b/pages/game.html @@ -29,8 +29,9 @@ - -
+ + +
@@ -38,8 +39,9 @@
- -
+ +
+ + + +
+ + +
+ Go Back to Home + Play Again +
+
+