diff options
author | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-07-19 19:55:20 +0530 |
---|---|---|
committer | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-07-19 19:55:20 +0530 |
commit | 529849fabcfafaac573de22b1aa550c3df5b898e (patch) | |
tree | ff0a53cfac96c8c1d05c755e7fe5feda7554d90f /src/components/Grid.tsx | |
parent | 919da0bb7ef807a5c79f0eb95c45044420e6b80a (diff) |
Implemented an alternative for alert() so now it works on more browsers
Diffstat (limited to 'src/components/Grid.tsx')
-rw-r--r-- | src/components/Grid.tsx | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx index 1e06ea6..97448b0 100644 --- a/src/components/Grid.tsx +++ b/src/components/Grid.tsx @@ -25,6 +25,8 @@ interface Props { scoreO: number setScoreX: Dispatch<SetStateAction<number>> setScoreO: Dispatch<SetStateAction<number>> + setMessage: Dispatch<SetStateAction<string>> + setShowMessage: Dispatch<SetStateAction<boolean>> } const Grid: React.FC<Props> = (props) => { @@ -62,13 +64,13 @@ const Grid: React.FC<Props> = (props) => { const endGame = (winner: number) => { const gameWinner = winner < 2 ? (winner === 1 ? "X" : "O") : "Draw"; - // clean up before alerting + props.setMessage(`WINNER: ${gameWinner}`); + props.setShowMessage(true); + gameWinner === "Draw" || gameWinner === "X" + ? props.setScoreX(props.scoreX + 1) + : props.setScoreO(props.scoreO + 1); setBoard([2,2,2,2,2,2,2,2,2]); setWinner(2); - gameWinner === "Draw" || gameWinner === "X" - ? props.setScoreX(props.scoreX + 1) - : props.setScoreO(props.scoreO + 1) - alert(`WINNER: ${gameWinner}`) } useEffect(() => { |