From 529849fabcfafaac573de22b1aa550c3df5b898e Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Mon, 19 Jul 2021 19:55:20 +0530 Subject: Implemented an alternative for alert() so now it works on more browsers --- src/components/Grid.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/components/Grid.tsx') 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> setScoreO: Dispatch> + setMessage: Dispatch> + setShowMessage: Dispatch> } const Grid: React.FC = (props) => { @@ -62,13 +64,13 @@ const Grid: React.FC = (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(() => { -- cgit v1.2.3