Fix: Nowinner

This commit is contained in:
Kagura 2024-11-18 09:15:15 +08:00
parent 9a8505b0d9
commit 41e602c868
2 changed files with 12 additions and 1 deletions

View file

@ -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 }) {
</button>
</div>
<p className="text-xl text-center">{winner != null ? winner + "赢了" : ""} </p>
<p className="text-xl text-center">{noWinner ? "没有胜利者" : ""} </p>
</div>
);
}

View file

@ -9,7 +9,12 @@ import { BrowserRouter, Routes, Route } from "react-router-dom";
const root = createRoot(document.getElementById("root"));
root.render(
<StrictMode>
<BrowserRouter>
<BrowserRouter
future={{
v7_relativeSplatPath: true,
v7_startTransition: true,
}}
>
<Routes>
<Route path="/" element={<NameList />} />
<Route path="/tictactoe" element={<TicTacToe />} />