From b1259b1f3ddb430803034d280a36f679bd0fc632 Mon Sep 17 00:00:00 2001 From: Hadeed Ahmad Date: Tue, 4 Jun 2024 20:13:49 +0400 Subject: [PATCH] Finish game only responsive left --- src/game.jsx | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/game.jsx b/src/game.jsx index 4721fc6..e1455cf 100644 --- a/src/game.jsx +++ b/src/game.jsx @@ -86,7 +86,7 @@ export default ({ players }) => { }; const [grid, updateGrid] = useImmer(Array(9).fill("")); - const [score, updateScore] = useImmer(initialScore); + const [scores, updateScores] = useImmer(initialScore); const [restartModal, setRestartModal] = useState(false); const [roundModal, setRoundModal] = useState(false); @@ -99,7 +99,8 @@ export default ({ players }) => { const winner = winningCombo.length > 0 ? grid[winningCombo[0]] : null; const gridFull = !grid.some((s) => s == ""); - const roundOver = winner || gridFull; + const roundOver = gridFull || winner; + const tied = gridFull && !winner; useEffect(() => { if (roundOver) { @@ -127,7 +128,7 @@ export default ({ players }) => { }, [grid]); const nextRound = () => { - updateScore((score) => { + updateScores((score) => { if (winner) { score[winner].value++; } else { @@ -178,10 +179,10 @@ export default ({ players }) => { @@ -208,12 +209,37 @@ export default ({ players }) => { setRoundModal(false)} > + {(() => { + if (tied) { + return ( +

Round tied

+ ); + } + + const HeadingSymbol = winner == "X" ? Cross : Oval; + const headingColor = + winner == "X" ? "text-blue-700" : "text-yellow-700"; + + return ( + <> +

+ {players[winner]} wins! +

+
+ +

Takes the round

+
+ + ); + })()}