diff --git a/src/TicTacToe.js b/src/TicTacToe.js index 0a7006d..e50577b 100644 --- a/src/TicTacToe.js +++ b/src/TicTacToe.js @@ -53,6 +53,7 @@ function Map({ mapSize }) { const [currentMove, setCurrentMove] = useState(0); const xIsNext = currentMove % 2 == 0; const [winner, setWinner] = useState(null); + const [noWinner, setNoWinner] = useState(false); const [history, setHistory] = useState([Array(mapSize).fill(null) .map(() => Array(mapSize).fill(null))]) @@ -73,6 +74,9 @@ function Map({ mapSize }) { } updateMap(nextMap) setCurrentMove(currentMove + 1) + if (currentMove + 1 >= mapSize * mapSize){ + setNoWinner(true) + } if (calculateWinner(row, column,nextMap)) { setWinner(nextMap[row][column]) } @@ -146,6 +150,7 @@ function Map({ mapSize }) { setCurrentMove(currentMove - 1); setHistory(history.slice(0, -1)); setWinner(null); + setNoWinner(false); } } @@ -164,6 +169,7 @@ function Map({ mapSize }) {

{winner != null ? winner + "赢了" : ""}

+

{noWinner ? "没有胜利者" : ""}

); } diff --git a/src/index.js b/src/index.js index 30d6d3d..fab75ac 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,12 @@ import { BrowserRouter, Routes, Route } from "react-router-dom"; const root = createRoot(document.getElementById("root")); root.render( - + } /> } />