diff --git a/src/TicTacToe.js b/src/TicTacToe.js index b583c76..5ffa187 100644 --- a/src/TicTacToe.js +++ b/src/TicTacToe.js @@ -3,7 +3,7 @@ import { useLocation } from 'react-router-dom'; function Square({ row, column, value, clickHandler }) { let buttonClass = "" - switch (value){ + switch (value) { case "X": buttonClass = "bg-amber-200 " break; @@ -75,16 +75,16 @@ function Map({ mapSize }) { } updateMap(nextMap) setCurrentMove(currentMove + 1) - let hasWinner = calculateWinner(row, column,nextMap) + let hasWinner = calculateWinner(row, column, nextMap) if (hasWinner) { setWinner(nextMap[row][column]) } - if (currentMove + 1 >= mapSize * mapSize && !hasWinner){ + if (currentMove + 1 >= mapSize * mapSize && !hasWinner) { setNoWinner(true) } } - function calculateWinner(row, column,map) { + function calculateWinner(row, column, map) { const who = map[row][column]; // 当前玩家标记 const winNeed = mapSize > ticTacToeMaxMapSize ? 5 : mapSize; // 棋盘大小(>5五子棋) @@ -180,55 +180,55 @@ function getMaxBoardSize() { const screenWidth = window.innerWidth; const screenHeight = window.innerHeight; const squareSize = 34; - const otherWidthUse = 48*2; + const otherWidthUse = 48 * 2; const squaresHorizontally = Math.floor((screenWidth - otherWidthUse) / squareSize); const squaresVertically = Math.floor(screenHeight / squareSize); - if (squaresHorizontally > 20 && squaresVertically > 20){ + if (squaresHorizontally > 20 && squaresVertically > 20) { return 20 } - + return squaresHorizontally < squaresVertically ? squaresHorizontally : squaresVertically; } -export default function Game(){ +export default function Game() { const location = useLocation(); const params = new URLSearchParams(location.search); const useSize = params.get('mapSize'); - + let realSize = parseInt(useSize) - if (isNaN(realSize) || realSize < 3 || realSize > getMaxBoardSize()){ + if (isNaN(realSize) || realSize < 3 || realSize > getMaxBoardSize()) { realSize = 3 } - return( -
-
- -
-

当前最大地图大小: {getMaxBoardSize()}

-
- - -
+ return ( +
+
+ +
+

当前最大地图大小: {getMaxBoardSize()}

+
+ + +
+
+
-
-
) }