Skip to content

Commit

Permalink
add refresh button logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiGong-dev committed Jan 10, 2022
1 parent ab1e152 commit 386c56e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const WINNING_PATTERNS = [
// game board elements
const turnIndicator = document.getElementById('turn-indicator');
const indicatorLogo = turnIndicator.childNodes[1];
const restartButton = document.getElementById('restart-button');
const refreshButton = document.getElementById('restart-button');
const cellElements = document.querySelectorAll('[data-cell');
const board = document.getElementById('board');
const xWinsCount = document.getElementById('x-wins-count');
Expand Down Expand Up @@ -91,11 +91,29 @@ introNewGameVsPlayer.addEventListener('click', () => {
} else {
oWinsCountText.innerText = 'O (PLAYER)';
}
startGame()
startGame();
isGameStarted = true;
intro.classList.remove(SHOW);
});

refreshButton.addEventListener('click', () => {
if (isGameStarted) {
cellElements.forEach(cell => {
cell.classList.remove(X_CLASS);
cell.classList.remove(O_CLASS);
cell.removeEventListener('click', handleCellClick);
cell.addEventListener('click', handleCellClick, {
once: true
});
});
circleTurn = false;
if (indicatorLogo.classList[0] !== LOGO_X) {
indicatorLogo.classList.replace(LOGO_O, LOGO_X);
}
}

});

function startGame() {
circleTurn = false;
cellElements.forEach(cell => {
Expand All @@ -105,7 +123,7 @@ function startGame() {
cell.addEventListener('click', handleCellClick, {
once: true
});
})
});
winningMessage.classList.remove(SHOW);
}

Expand Down Expand Up @@ -137,7 +155,7 @@ function swapIndicatorLogo() {
} else {
indicatorLogo.classList.replace(LOGO_O, LOGO_X);
}

}

function swapTurns() {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<span class="turn-indicator__text">TURN</span>
</div>
<div class="restart-button" id="restart-button">
<a href=""><i class="fas fa-redo"></i></a>
<i class="fas fa-redo"></i>
</div>
</div>
<!-- game board main -->
Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ body {
justify-content: flex-end;
align-items: center;
}
.restart-button a {
.restart-button i {
text-decoration: none;
display: flex;
justify-content: center;
Expand Down

0 comments on commit 386c56e

Please sign in to comment.