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 }) => {
Turn
@@ -128,7 +138,7 @@ export default ({ players }) => {