Skip to content

Commit

Permalink
Merge pull request #7 from W0x3R/dev-page
Browse files Browse the repository at this point in the history
fix: fixed a problem with incorrect display of the game result when t…
  • Loading branch information
W0x3R authored Jan 14, 2024
2 parents dd36f0d + 761dc29 commit 7273726
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function cross(target) {
if (count % 2 === 0 && target.textContent === '') {
target.textContent = '◯'
target.classList.add('o')
count++
++count
}
}

function zero(target) {
if (count % 2 !== 0 && target.textContent === '') {
target.textContent = '✕'
target.classList.add('x')
count++
++count
}
}

Expand All @@ -43,6 +43,7 @@ function showWin() {

for (let i = 0; i < comboOfWin.length; i++) {
if (squareElements[comboOfWin[i][0]].classList.contains('x') && squareElements[comboOfWin[i][1]].classList.contains('x') && squareElements[comboOfWin[i][2]].classList.contains('x')) {
count = 0;
square.removeEventListener('click', init)
setTimeout(() => {
squareElements[comboOfWin[i][0]].classList.add('main__square-item_win')
Expand All @@ -52,18 +53,19 @@ function showWin() {
}, 250)
}
else if (squareElements[comboOfWin[i][0]].classList.contains('o') && squareElements[comboOfWin[i][1]].classList.contains('o') && squareElements[comboOfWin[i][2]].classList.contains('o')) {
count = 0;
square.removeEventListener('click', init)
setTimeout(() => {
squareElements[comboOfWin[i][0]].classList.add('main__square-item_win')
squareElements[comboOfWin[i][1]].classList.add('main__square-item_win')
squareElements[comboOfWin[i][2]].classList.add('main__square-item_win')
res.textContent = '0 WIN'
}, 250)

}
else if (count === 9) {
res.textContent = 'GAME DRAW'
square.removeEventListener('click', init)

}
}
}
Expand All @@ -80,3 +82,7 @@ function newGame() {

newGameButton.addEventListener('click', newGame)


setInterval(() => {
console.log(count)
}, 500)

0 comments on commit 7273726

Please sign in to comment.