Skip to content

Commit

Permalink
Fix Player Move During Machine's Turn
Browse files Browse the repository at this point in the history
  • Loading branch information
atchutchi committed May 25, 2023
1 parent 1339d10 commit af836f3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ function handleCellClick(event) {
currentPlayer = currentPlayer === "X" ? "O" : "X";
if (gameMode === "playerVsMachine" && currentPlayer === "O") {
setTimeout(computerMove, 1000); // Wait for 1 seconds before the computer makes its move
for (let i = 1; i <= 9; i++) {
document.getElementById(`cell${i}`).removeEventListener("click", handleCellClick);
}
}
}
}
Expand Down Expand Up @@ -152,6 +155,9 @@ function computerMove() {
// If no one won as of yet, the current player is changed.
currentPlayer = currentPlayer === "X" ? "O" : "X";
}
for (let i = 1; i <= 9; i++) {
document.getElementById(`cell${i}`).addEventListener("click", handleCellClick);
}
}

// Function to determine whether a player won
Expand Down

0 comments on commit af836f3

Please sign in to comment.