井字棋游戏
```<!DOCTYPE html>
<html>
<head>
<title>井字棋游戏</title>
</head>
<body>
<h1>井字棋游戏</h1>
<div class="grid">
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
</div>
<button id="human">人类先手</button>
<button id="computer">电脑先手</button>
<script>
let squares = document.querySelectorAll(".square");
let human_button = document.getElementById("human");
let computer_button = document.getElementById("computer");
let current_player = "human";
human_button.addEventListener("click", function() {
current_player = "human";
human_move();
});
computer_button.addEventListener("click", function() {
current_player = "computer";
computer_move();
});
function human_move() {
let guess = prompt("请在格子上点击:");
if (guess === "topLeft") {
squares.classList.add("human");
} else if (guess === "topCenter") {
squares.classList.add("human");
} else if (guess === "topRight") {
squares.classList.add("human");
} else if (guess === "centerLeft") {
squares.classList.add("human");
} else if (guess === "center") {
squares.classList.add("human");
} else if (guess === "centerRight") {
squares.classList.add("human");
} else if (guess === "bottomLeft") {
squares
页:
[1]