From 163da80d099288f9ce98d0829c4256fc33645206 Mon Sep 17 00:00:00 2001 From: Hadeed Ahmad Date: Mon, 3 Jun 2024 22:11:17 +0400 Subject: [PATCH] Add ties --- src/game.jsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/game.jsx b/src/game.jsx index 2a3bc57..95b62ef 100644 --- a/src/game.jsx +++ b/src/game.jsx @@ -60,10 +60,20 @@ export default ({ players }) => { return () => clearTimeout(timeoutId); } - }, [winner]); - useEffect(() => { - if (cpuTurn && !winner && grid.filter((s) => s == "").length > 0) { + if (!grid.some((s) => s == "")) { + const timeoutId = setTimeout(() => { + updateScore((score) => { + score.ties++; + }); + + updateGrid(() => Array(9).fill("")); + }, 1000); + + return () => clearTimeout(timeoutId); + } + + if (cpuTurn) { const timeoutId = setTimeout(() => { updateGrid((grid) => { const free = Array.from({ length: 9 }, (_, i) => i).filter( @@ -77,7 +87,7 @@ export default ({ players }) => { return () => clearTimeout(timeoutId); } - }, [cpuTurn]); + }, [grid]); const renderSymbol = (symbol, index) => { if (symbol == "") { @@ -119,7 +129,7 @@ export default ({ players }) => {
logo
-
+

Turn

@@ -128,7 +138,7 @@ export default ({ players }) => {
@@ -179,12 +189,12 @@ export default ({ players }) => { className="center flex-row justify-around text-navy-700" method="dialog" > -