نوجا
نوجا
getElementById('board');
const cells = document.querySelectorAll('.cell');
const message = document.getElementById('message');
const resetButton = document.getElementById('reset');
const winningConditions = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];
function handleCellClick(event) {
const clickedCell = event.target;
const clickedCellIndex = parseInt(clickedCell.getAttribute('data-index'));
boardState[clickedCellIndex] = currentPlayer;
clickedCell.textContent = currentPlayer;
checkWinner();
}
function checkWinner() {
for (let condition of winningConditions) {
const [a, b, c] = condition;
if (boardState[a] && boardState[a] === boardState[b] && boardState[a] ===
boardState[c]) {
message.textContent = ` الالعب${currentPlayer} ;`!فاز
gameActive = false;
return;
}
}
if (!boardState.includes('')) {
message.textContent = ';'!تعادل
gameActive = false;
return;
}
function resetGame() {
gameActive = true;
currentPlayer = 'X';
boardState = ['', '', '', '', '', '', '', '', ''];
message.textContent = '';
cells.forEach(cell => {
cell