diff --git a/src/TicTacToe.js b/src/TicTacToe.js index 06df2ff..b583c76 100644 --- a/src/TicTacToe.js +++ b/src/TicTacToe.js @@ -42,7 +42,7 @@ function SquareRow({ rowId, rows, clickHandler }) { function Map({ mapSize }) { // Config Here - const ticTacToeMaxMapSize = 6 + const ticTacToeMaxMapSize = 5 if (mapSize == undefined) { mapSize = 3; @@ -75,12 +75,13 @@ function Map({ mapSize }) { } updateMap(nextMap) setCurrentMove(currentMove + 1) - if (currentMove + 1 >= mapSize * mapSize){ - setNoWinner(true) - } - if (calculateWinner(row, column,nextMap)) { + let hasWinner = calculateWinner(row, column,nextMap) + if (hasWinner) { setWinner(nextMap[row][column]) } + if (currentMove + 1 >= mapSize * mapSize && !hasWinner){ + setNoWinner(true) + } } function calculateWinner(row, column,map) { @@ -156,7 +157,7 @@ function Map({ mapSize }) { } return ( -
{mapSize > ticTacToeMaxMapSize ? "五子棋" : "井字棋"}模式
现在是 {xIsNext ? "X" : "O"} 移动
{winner != null ? winner + "赢了" : ""}
+{winner != null ? winner + "赢了" : ""}
{noWinner ? "没有胜利者" : ""}
当前最大地图大小: {getMaxBoardSize()}
+