Skip to content

Commit

Permalink
Add 2 eventListeners to select mode and restart button and function f…
Browse files Browse the repository at this point in the history
…or the game mode
  • Loading branch information
atchutchi committed May 16, 2023
1 parent 637febb commit 4849fbd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ let currentPlayer = "X";
for (let i = 1; i <= 9; i++) {
const cell = document.getElementById(`cell${i}`);
cell.addEventListener("click", handleCellClick);
}
}

// Add event listeners to the game mode selection buttons.
document.getElementById("playerVsPlayer").addEventListener("click", () => handleGameModeSelection("playerVsPlayer"));
document.getElementById("playerVsMachine").addEventListener("click", () => handleGameModeSelection("playerVsMachine"));

// Add an event listener to the Restart button to refresh the page.
document.getElementById("restartBtn").addEventListener("click", () => location.reload());

// Function to deal with game mode selection and game launch
function handleGameModeSelection(mode) {
gameMode = mode;
gameInProgress = true;
document.querySelector(".game-container").classList.add("active");
document.getElementById("restartBtn").classList.add("active");
}

0 comments on commit 4849fbd

Please sign in to comment.