From 74fdf72e0f4ede48085e8a98622424195d574a39 Mon Sep 17 00:00:00 2001 From: Straordinariu Date: Fri, 8 Oct 2021 17:37:28 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 7 ++ index.js | 163 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 140 insertions(+), 30 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..655f330 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Используйте IntelliSense, чтобы узнать о возможных атрибутах. + // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов. + // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/index.js b/index.js index 7553909..3da7780 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,23 @@ const CROSS = 'X'; const ZERO = 'O'; const EMPTY = ' '; - const container = document.getElementById('fieldWrapper'); - +let field = {}; +let fieldSize = 3; +let cellsRemaining = 9; +let gameIsOver = false; startGame(); addResetListener(); - -function startGame () { - renderGrid(3); +function startGame() { + let size = Number(prompt("Введите размер поля", 3)); + cellsRemaining = size ** 2; + gameIsOver = false; + renderGrid(size); + createField(size); + fieldSize = field[0].length; } - -function renderGrid (dimension) { +function renderGrid(dimension) { container.innerHTML = ''; - for (let i = 0; i < dimension; i++) { const row = document.createElement('tr'); for (let j = 0; j < dimension; j++) { @@ -25,42 +29,143 @@ function renderGrid (dimension) { container.appendChild(row); } } +function createField(dimension) { + field = Array.from(Array(dimension), () => new Array(dimension)); + for (let i = 0; i < dimension; i++) + for (let j = 0; j < dimension; j++) + field[i][j] = 0; +} +function checkWinConditions() { + let rowsSum = new Array(fieldSize).fill(0); + let diagonalsSum = new Array(2).fill(0); + for (let i = 0; i < fieldSize; i++) { + let lineSum = 0; + for (let j = 0; j < fieldSize; j++) { + lineSum += field[i][j]; + rowsSum[j] += field[i][j]; + + if (i === j) + diagonalsSum[0] += field[i][j]; + + if (i === fieldSize - j - 1) + diagonalsSum[1] += field[i][j]; + } + + gameIsOver = applyWinMessage(lineSum, [i, 0], [i, fieldSize - 1]); + + if (gameIsOver) break; + } + if (gameIsOver) return; + for (let i = 0; i < fieldSize; i++) { + gameIsOver = applyWinMessage(rowsSum[i], [0, i], [fieldSize - 1, i]); + if (gameIsOver) break; + } + if (gameIsOver) return; + for (let i = 0; i < fieldSize; i++) { + gameIsOver = applyWinMessage(diagonalsSum[i], + [0, i === 0 ? 0 : fieldSize - 1], [fieldSize - 1, i === 1 ? 0 : fieldSize - 1], true); + if (gameIsOver) break; + } + + if (!gameIsOver && cellsRemaining === 0) { + alert("Победила дружба") + gameIsOver = true; + } +} -function cellClickHandler (row, col) { - // Пиши код тут - console.log(`Clicked on cell: ${row}, ${col}`); +function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { + if (Math.abs(sum) == fieldSize) { + if (sum > 0) { + makeWinnerRed('X', firstPoint, secondPoint, isDiagonal); + alert(`Победили Крестики! \nXXXXXXXXXXXXXXXX`); + } + else { + makeWinnerRed('O', firstPoint, secondPoint, isDiagonal); + alert(`Победили Нолики! \n0000000000000000`); + } + return true; + + } + return false; +} + +function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) { + if (!isDiagonal) { + for (let i = firstPoint[0]; i <= secondPoint[0]; i++) + for (let j = firstPoint[1]; j <= secondPoint[1]; j++) + renderSymbolInCell(symbol, i, j, "red"); + } + else for (let i = 0; i < fieldSize; i++) { + renderSymbolInCell(symbol, i, firstPoint[1] === 0 ? i : fieldSize - i - 1, "red"); + } - /* Пользоваться методом для размещения символа в клетке так: - renderSymbolInCell(ZERO, row, col); - */ } -function renderSymbolInCell (symbol, row, col, color = '#333') { - const targetCell = findCell(row, col); +function cellClickHandler(row, col) { + if (!gameIsOver) { + if (field[row][col] === 0) { + renderSymbolInCell(CROSS, row, col); + field[row][col] = 1; + cellsRemaining--; + console.log(`Clicked on cell: ${row}, ${col}`); + + checkWinConditions(); + + if (!gameIsOver) { + makeBotMove(); + checkWinConditions(); + } + } + } +} + +function makeBotMove() { + let row = Math.floor(Math.random() * fieldSize); + let col = Math.floor(Math.random() * fieldSize); + + while (field[row][col] != 0) { + row = Math.floor(Math.random() * fieldSize); + col = Math.floor(Math.random() * fieldSize); + } + + renderSymbolInCell(ZERO, row, col); + field[row][col] = -1; + cellsRemaining--; + console.log(`Bot made move on cell: ${row}, ${col}`); +} + +function renderSymbolInCell(symbol, row, col, color = '#333') { + + + + + + + + + + + const targetCell = findCell(row, col); targetCell.textContent = symbol; targetCell.style.color = color; } - -function findCell (row, col) { +function findCell(row, col) { const targetRow = container.querySelectorAll('tr')[row]; return targetRow.querySelectorAll('td')[col]; } - -function addResetListener () { +function addResetListener() { const resetButton = document.getElementById('reset'); resetButton.addEventListener('click', resetClickHandler); } - -function resetClickHandler () { +function resetClickHandler() { + startGame(); console.log('reset!'); } - - /* Test Function */ /* Победа первого игрока */ -function testWin () { +function testWin() { clickOnCell(0, 2); clickOnCell(0, 0); clickOnCell(2, 0); @@ -69,9 +174,8 @@ function testWin () { clickOnCell(1, 2); clickOnCell(2, 1); } - /* Ничья */ -function testDraw () { +function testDraw() { clickOnCell(2, 0); clickOnCell(1, 0); clickOnCell(1, 1); @@ -83,7 +187,6 @@ function testDraw () { clickOnCell(2, 1); clickOnCell(2, 2); } - -function clickOnCell (row, col) { +function clickOnCell(row, col) { findCell(row, col).click(); -} +} \ No newline at end of file From 8fcbfd347aa564ea1647211273f201cc671fe735 Mon Sep 17 00:00:00 2001 From: Straordinariu Date: Wed, 13 Oct 2021 19:07:15 +0500 Subject: [PATCH 2/5] Update index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3da7780..e619507 100644 --- a/index.js +++ b/index.js @@ -77,11 +77,11 @@ function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { if (Math.abs(sum) == fieldSize) { if (sum > 0) { makeWinnerRed('X', firstPoint, secondPoint, isDiagonal); - alert(`Победили Крестики! \nXXXXXXXXXXXXXXXX`); + alert(`Победили Крестики!`); } else { makeWinnerRed('O', firstPoint, secondPoint, isDiagonal); - alert(`Победили Нолики! \n0000000000000000`); + alert(`Победили Нолики!`); } return true; From bf0b7b1a42fb01f73a6cc519af7d304abda7db0b Mon Sep 17 00:00:00 2001 From: Straordinariu <91519279+Straordinariu@users.noreply.github.com> Date: Wed, 13 Oct 2021 19:13:26 +0500 Subject: [PATCH 3/5] Delete index.js --- index.js | 192 ------------------------------------------------------- 1 file changed, 192 deletions(-) delete mode 100644 index.js diff --git a/index.js b/index.js deleted file mode 100644 index e619507..0000000 --- a/index.js +++ /dev/null @@ -1,192 +0,0 @@ -const CROSS = 'X'; -const ZERO = 'O'; -const EMPTY = ' '; -const container = document.getElementById('fieldWrapper'); -let field = {}; -let fieldSize = 3; -let cellsRemaining = 9; -let gameIsOver = false; -startGame(); -addResetListener(); -function startGame() { - let size = Number(prompt("Введите размер поля", 3)); - cellsRemaining = size ** 2; - gameIsOver = false; - renderGrid(size); - createField(size); - fieldSize = field[0].length; -} -function renderGrid(dimension) { - container.innerHTML = ''; - for (let i = 0; i < dimension; i++) { - const row = document.createElement('tr'); - for (let j = 0; j < dimension; j++) { - const cell = document.createElement('td'); - cell.textContent = EMPTY; - cell.addEventListener('click', () => cellClickHandler(i, j)); - row.appendChild(cell); - } - container.appendChild(row); - } -} -function createField(dimension) { - field = Array.from(Array(dimension), () => new Array(dimension)); - for (let i = 0; i < dimension; i++) - for (let j = 0; j < dimension; j++) - field[i][j] = 0; -} -function checkWinConditions() { - let rowsSum = new Array(fieldSize).fill(0); - let diagonalsSum = new Array(2).fill(0); - for (let i = 0; i < fieldSize; i++) { - let lineSum = 0; - for (let j = 0; j < fieldSize; j++) { - lineSum += field[i][j]; - rowsSum[j] += field[i][j]; - - if (i === j) - diagonalsSum[0] += field[i][j]; - - if (i === fieldSize - j - 1) - diagonalsSum[1] += field[i][j]; - } - - gameIsOver = applyWinMessage(lineSum, [i, 0], [i, fieldSize - 1]); - - if (gameIsOver) break; - } - if (gameIsOver) return; - for (let i = 0; i < fieldSize; i++) { - gameIsOver = applyWinMessage(rowsSum[i], [0, i], [fieldSize - 1, i]); - if (gameIsOver) break; - } - if (gameIsOver) return; - for (let i = 0; i < fieldSize; i++) { - gameIsOver = applyWinMessage(diagonalsSum[i], - [0, i === 0 ? 0 : fieldSize - 1], [fieldSize - 1, i === 1 ? 0 : fieldSize - 1], true); - if (gameIsOver) break; - } - - if (!gameIsOver && cellsRemaining === 0) { - alert("Победила дружба") - gameIsOver = true; - } -} - -function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { - if (Math.abs(sum) == fieldSize) { - if (sum > 0) { - makeWinnerRed('X', firstPoint, secondPoint, isDiagonal); - alert(`Победили Крестики!`); - } - else { - makeWinnerRed('O', firstPoint, secondPoint, isDiagonal); - alert(`Победили Нолики!`); - } - - return true; - - } - return false; -} - -function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) { - if (!isDiagonal) { - for (let i = firstPoint[0]; i <= secondPoint[0]; i++) - for (let j = firstPoint[1]; j <= secondPoint[1]; j++) - renderSymbolInCell(symbol, i, j, "red"); - } - else for (let i = 0; i < fieldSize; i++) { - renderSymbolInCell(symbol, i, firstPoint[1] === 0 ? i : fieldSize - i - 1, "red"); - } - -} - -function cellClickHandler(row, col) { - if (!gameIsOver) { - if (field[row][col] === 0) { - renderSymbolInCell(CROSS, row, col); - field[row][col] = 1; - cellsRemaining--; - - console.log(`Clicked on cell: ${row}, ${col}`); - - checkWinConditions(); - - if (!gameIsOver) { - makeBotMove(); - checkWinConditions(); - } - } - } -} - -function makeBotMove() { - let row = Math.floor(Math.random() * fieldSize); - let col = Math.floor(Math.random() * fieldSize); - - while (field[row][col] != 0) { - row = Math.floor(Math.random() * fieldSize); - col = Math.floor(Math.random() * fieldSize); - } - - renderSymbolInCell(ZERO, row, col); - field[row][col] = -1; - cellsRemaining--; - console.log(`Bot made move on cell: ${row}, ${col}`); -} - -function renderSymbolInCell(symbol, row, col, color = '#333') { - - - - - - - - - - - const targetCell = findCell(row, col); - targetCell.textContent = symbol; - targetCell.style.color = color; -} -function findCell(row, col) { - const targetRow = container.querySelectorAll('tr')[row]; - return targetRow.querySelectorAll('td')[col]; -} -function addResetListener() { - const resetButton = document.getElementById('reset'); - resetButton.addEventListener('click', resetClickHandler); -} -function resetClickHandler() { - startGame(); - console.log('reset!'); -} -/* Test Function */ -/* Победа первого игрока */ -function testWin() { - clickOnCell(0, 2); - clickOnCell(0, 0); - clickOnCell(2, 0); - clickOnCell(1, 1); - clickOnCell(2, 2); - clickOnCell(1, 2); - clickOnCell(2, 1); -} -/* Ничья */ -function testDraw() { - clickOnCell(2, 0); - clickOnCell(1, 0); - clickOnCell(1, 1); - clickOnCell(0, 0); - clickOnCell(1, 2); - clickOnCell(1, 2); - clickOnCell(0, 2); - clickOnCell(0, 1); - clickOnCell(2, 1); - clickOnCell(2, 2); -} -function clickOnCell(row, col) { - findCell(row, col).click(); -} \ No newline at end of file From 0fe34791e1a2d11033553776b22d930eb232575e Mon Sep 17 00:00:00 2001 From: Straordinariu Date: Wed, 13 Oct 2021 19:28:54 +0500 Subject: [PATCH 4/5] Create index.js --- index.js | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..bc97005 --- /dev/null +++ b/index.js @@ -0,0 +1,182 @@ +const CROSS = 'X'; +const ZERO = 'O'; +const EMPTY = ' '; +const container = document.getElementById('fieldWrapper'); +let field = {}; +let fieldSize = 3; +let cellsRemaining = 9; +let gameIsOver = false; +startGame(); +addResetListener(); +function startGame() { + let size = Number(prompt("Введите размер поля", 3)); + cellsRemaining = size ** 2; + gameIsOver = false; + renderGrid(size); + createField(size); + fieldSize = field[0].length; +} +function renderGrid(dimension) { + container.innerHTML = ''; + for (let i = 0; i < dimension; i++) { + const row = document.createElement('tr'); + for (let j = 0; j < dimension; j++) { + const cell = document.createElement('td'); + cell.textContent = EMPTY; + cell.addEventListener('click', () => cellClickHandler(i, j)); + row.appendChild(cell); + } + container.appendChild(row); + } +} +function createField(dimension) { + field = Array.from(Array(dimension), () => new Array(dimension)); + for (let i = 0; i < dimension; i++) + for (let j = 0; j < dimension; j++) + field[i][j] = 0; +} +function checkWinConditions() { + let rowsSum = new Array(fieldSize).fill(0); + let diagonalsSum = new Array(2).fill(0); + for (let i = 0; i < fieldSize; i++) { + let lineSum = 0; + for (let j = 0; j < fieldSize; j++) { + lineSum += field[i][j]; + rowsSum[j] += field[i][j]; + + if (i === j) + diagonalsSum[0] += field[i][j]; + + if (i === fieldSize - j - 1) + diagonalsSum[1] += field[i][j]; + } + + gameIsOver = applyWinMessage(lineSum, [i, 0], [i, fieldSize - 1]); + + if (gameIsOver) break; + } + if (gameIsOver) return; + for (let i = 0; i < fieldSize; i++) { + gameIsOver = applyWinMessage(rowsSum[i], [0, i], [fieldSize - 1, i]); + if (gameIsOver) break; + } + if (gameIsOver) return; + for (let i = 0; i < fieldSize; i++) { + gameIsOver = applyWinMessage(diagonalsSum[i], + [0, i === 0 ? 0 : fieldSize - 1], [fieldSize - 1, i === 1 ? 0 : fieldSize - 1], true); + if (gameIsOver) break; + } + + if (!gameIsOver && cellsRemaining === 0) { + alert("Победила дружба") + gameIsOver = true; + } +} + +function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { + if (Math.abs(sum) == fieldSize) { + if (sum > 0) { + makeWinnerRed('X', firstPoint, secondPoint, isDiagonal); + alert(`Победили Крестики!`); + } + else { + makeWinnerRed('O', firstPoint, secondPoint, isDiagonal); + alert(`Победили Нолики!`); + } + + return true; + + } + return false; +} + +function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) { + if (!isDiagonal) { + for (let i = firstPoint[0]; i <= secondPoint[0]; i++) + for (let j = firstPoint[1]; j <= secondPoint[1]; j++) + renderSymbolInCell(symbol, i, j, "red"); + } + else for (let i = 0; i < fieldSize; i++) { + renderSymbolInCell(symbol, i, firstPoint[1] === 0 ? i : fieldSize - i - 1, "red"); + } + +} + +function cellClickHandler(row, col) { + if (!gameIsOver) { + if (field[row][col] === 0) { + renderSymbolInCell(CROSS, row, col); + field[row][col] = 1; + cellsRemaining--; + + console.log(`Clicked on cell: ${row}, ${col}`); + + checkWinConditions(); + + if (!gameIsOver) { + makeBotMove(); + checkWinConditions(); + } + } + } +} + +function makeBotMove() { + let row = Math.floor(Math.random() * fieldSize); + let col = Math.floor(Math.random() * fieldSize); + + while (field[row][col] != 0) { + row = Math.floor(Math.random() * fieldSize); + col = Math.floor(Math.random() * fieldSize); + } + + renderSymbolInCell(ZERO, row, col); + field[row][col] = -1; + cellsRemaining--; + console.log(`Bot made move on cell: ${row}, ${col}`); +} + +function renderSymbolInCell(symbol, row, col, color = '#333') { + const targetCell = findCell(row, col); + targetCell.textContent = symbol; + targetCell.style.color = color; +} +function findCell(row, col) { + const targetRow = container.querySelectorAll('tr')[row]; + return targetRow.querySelectorAll('td')[col]; +} +function addResetListener() { + const resetButton = document.getElementById('reset'); + resetButton.addEventListener('click', resetClickHandler); +} +function resetClickHandler() { + startGame(); + console.log('reset!'); +} +/* Test Function */ +/* Победа первого игрока */ +function testWin() { + clickOnCell(0, 2); + clickOnCell(0, 0); + clickOnCell(2, 0); + clickOnCell(1, 1); + clickOnCell(2, 2); + clickOnCell(1, 2); + clickOnCell(2, 1); +} +/* Ничья */ +function testDraw() { + clickOnCell(2, 0); + clickOnCell(1, 0); + clickOnCell(1, 1); + clickOnCell(0, 0); + clickOnCell(1, 2); + clickOnCell(1, 2); + clickOnCell(0, 2); + clickOnCell(0, 1); + clickOnCell(2, 1); + clickOnCell(2, 2); +} +function clickOnCell(row, col) { + findCell(row, col).click(); +} \ No newline at end of file From beb34ecdc4a5689c5e4cb56a07598df3ac5d7af7 Mon Sep 17 00:00:00 2001 From: Straordinariu Date: Wed, 13 Oct 2021 19:59:32 +0500 Subject: [PATCH 5/5] Update index.js --- index.js | 81 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index bc97005..9c7b34d 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,8 @@ let cellsRemaining = 9; let gameIsOver = false; startGame(); addResetListener(); -function startGame() { +function startGame() +{ let size = Number(prompt("Введите размер поля", 3)); cellsRemaining = size ** 2; gameIsOver = false; @@ -16,7 +17,8 @@ function startGame() { createField(size); fieldSize = field[0].length; } -function renderGrid(dimension) { +function renderGrid(dimension) +{ container.innerHTML = ''; for (let i = 0; i < dimension; i++) { const row = document.createElement('tr'); @@ -29,18 +31,22 @@ function renderGrid(dimension) { container.appendChild(row); } } -function createField(dimension) { +function createField(dimension) +{ field = Array.from(Array(dimension), () => new Array(dimension)); for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) field[i][j] = 0; } -function checkWinConditions() { +function checkWinConditions() +{ let rowsSum = new Array(fieldSize).fill(0); let diagonalsSum = new Array(2).fill(0); - for (let i = 0; i < fieldSize; i++) { + for (let i = 0; i < fieldSize; i++) + { let lineSum = 0; - for (let j = 0; j < fieldSize; j++) { + for (let j = 0; j < fieldSize; j++) + { lineSum += field[i][j]; rowsSum[j] += field[i][j]; @@ -56,12 +62,14 @@ function checkWinConditions() { if (gameIsOver) break; } if (gameIsOver) return; - for (let i = 0; i < fieldSize; i++) { + for (let i = 0; i < fieldSize; i++) + { gameIsOver = applyWinMessage(rowsSum[i], [0, i], [fieldSize - 1, i]); if (gameIsOver) break; } if (gameIsOver) return; - for (let i = 0; i < fieldSize; i++) { + for (let i = 0; i < fieldSize; i++) + { gameIsOver = applyWinMessage(diagonalsSum[i], [0, i === 0 ? 0 : fieldSize - 1], [fieldSize - 1, i === 1 ? 0 : fieldSize - 1], true); if (gameIsOver) break; @@ -73,13 +81,17 @@ function checkWinConditions() { } } -function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { - if (Math.abs(sum) == fieldSize) { - if (sum > 0) { +function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) +{ + if (Math.abs(sum) == fieldSize) + { + if (sum > 0) + { makeWinnerRed('X', firstPoint, secondPoint, isDiagonal); alert(`Победили Крестики!`); } - else { + else + { makeWinnerRed('O', firstPoint, secondPoint, isDiagonal); alert(`Победили Нолики!`); } @@ -90,8 +102,10 @@ function applyWinMessage(sum, firstPoint, secondPoint, isDiagonal = false) { return false; } -function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) { - if (!isDiagonal) { +function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) +{ + if (!isDiagonal) + { for (let i = firstPoint[0]; i <= secondPoint[0]; i++) for (let j = firstPoint[1]; j <= secondPoint[1]; j++) renderSymbolInCell(symbol, i, j, "red"); @@ -102,9 +116,12 @@ function makeWinnerRed(symbol, firstPoint, secondPoint, isDiagonal = false) { } -function cellClickHandler(row, col) { - if (!gameIsOver) { - if (field[row][col] === 0) { +function cellClickHandler(row, col) +{ + if (!gameIsOver) + { + if (field[row][col] === 0) + { renderSymbolInCell(CROSS, row, col); field[row][col] = 1; cellsRemaining--; @@ -113,7 +130,8 @@ function cellClickHandler(row, col) { checkWinConditions(); - if (!gameIsOver) { + if (!gameIsOver) + { makeBotMove(); checkWinConditions(); } @@ -121,11 +139,13 @@ function cellClickHandler(row, col) { } } -function makeBotMove() { +function makeBotMove() +{ let row = Math.floor(Math.random() * fieldSize); let col = Math.floor(Math.random() * fieldSize); - while (field[row][col] != 0) { + while (field[row][col] != 0) + { row = Math.floor(Math.random() * fieldSize); col = Math.floor(Math.random() * fieldSize); } @@ -136,26 +156,31 @@ function makeBotMove() { console.log(`Bot made move on cell: ${row}, ${col}`); } -function renderSymbolInCell(symbol, row, col, color = '#333') { +function renderSymbolInCell(symbol, row, col, color = '#333') +{ const targetCell = findCell(row, col); targetCell.textContent = symbol; targetCell.style.color = color; } -function findCell(row, col) { +function findCell(row, col) +{ const targetRow = container.querySelectorAll('tr')[row]; return targetRow.querySelectorAll('td')[col]; } -function addResetListener() { +function addResetListener() +{ const resetButton = document.getElementById('reset'); resetButton.addEventListener('click', resetClickHandler); } -function resetClickHandler() { +function resetClickHandler() +{ startGame(); console.log('reset!'); } /* Test Function */ /* Победа первого игрока */ -function testWin() { +function testWin() +{ clickOnCell(0, 2); clickOnCell(0, 0); clickOnCell(2, 0); @@ -165,7 +190,8 @@ function testWin() { clickOnCell(2, 1); } /* Ничья */ -function testDraw() { +function testDraw() +{ clickOnCell(2, 0); clickOnCell(1, 0); clickOnCell(1, 1); @@ -177,6 +203,7 @@ function testDraw() { clickOnCell(2, 1); clickOnCell(2, 2); } -function clickOnCell(row, col) { +function clickOnCell(row, col) +{ findCell(row, col).click(); } \ No newline at end of file