我正在用html + css + js编写简单的井字游戏。我对一个功能有疑问,该功能应该在我的游戏板上的位置1中写一个“ X”。当我单击位置0时,可以看到我的O形弯,但X形弯不起作用。
var gameBoard;
const user = "O";
const ai = "X";
const win = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[6, 4, 2]
]
const box = document.querySelectorAll('.box');
startGame();
function startGame() {
document.querySelector(".koniec").getElementsByClassName.display = "none";
gameBoard = Array.from(Array(9).keys());
for (var i = 0; i < box.length; i++) {
box[i].innerText = '';
box[i].style.removeProperty('background-color');
box[i].addEventListener('click', turnClick, false);
}
}
function turnClick(square) {
turn(square.target.id, user)
}
function turn(squareId, player) {
gameBoard[squareId] = player;
document.getElementById(squareId).innerText = player;
console.log(gameBoard[0]);
}
function aiTurn(gameBoard) {
if(gameBoard[0]=="O"){
turn(1, ai);
}
console.log("asdasd");
}