21 lines
720 B
JavaScript
21 lines
720 B
JavaScript
/* Modern Tic Tac Toe JavaScript file
|
|
* Copyright (c) David, 2024. */
|
|
|
|
// Get DOM elementsconst gridContainer = document.getElementById('board');
|
|
const squareButtons = Array.from(document.querySelectorAll('#board button'));
|
|
|
|
class Game {
|
|
constructor() {
|
|
this.board = [
|
|
[], [], []
|
|
];
|
|
this.gameOver = false;
|
|
this.currentPlayer = '';
|
|
this.movesCount = 0;
|
|
// Initialize game board squares
|
|
squareButtons.forEach(
|
|
(btn, idx) => (
|
|
btn.addEventListener('click', () => { if(this.moveIsValid(idx))
|
|
this.updateBoard({cell:btn,squareIndex:idx,mark:'X'});
|
|
else alert("Game is over");}
|
|
))))}} |