aboutsummaryrefslogtreecommitdiff
path: root/src/components/Grid.tsx
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-21 19:43:33 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-21 19:43:33 +0530
commit87e3e6bf66dc18a324417e05043874792749a8c5 (patch)
tree92948b725b200a0e0f7d8574934a1b4d45b6f11b /src/components/Grid.tsx
parent2219ac3e3db3ead7cb9b8ef88726225b1754d6f3 (diff)
Fixed styling and add prompt for player
Diffstat (limited to 'src/components/Grid.tsx')
-rw-r--r--src/components/Grid.tsx9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx
index 23ab194..30bab11 100644
--- a/src/components/Grid.tsx
+++ b/src/components/Grid.tsx
@@ -21,6 +21,8 @@ import Box from './Box';
import './style.css';
interface Props {
+ turn: number
+ setTurn: Dispatch<SetStateAction<number>>
scoreX: number
scoreO: number
setScoreX: Dispatch<SetStateAction<number>>
@@ -32,11 +34,11 @@ interface Props {
const Grid: React.FC<Props> = (props) => {
// 0 is O, 1 is X, 2 is blank
const [board, setBoard] = useState<number[]>([2,2,2,2,2,2,2,2,2]);
- const [turn, setTurn] = useState<number>(1);
+ const turn = props.turn;
const getBoard = (index: number) => {
setBoard(board.slice(0, index).concat(turn).concat(board.slice(index+1, 9)));
- setTurn(turn === 1 ? 0 : 1)
+ props.setTurn(turn === 1 ? 0 : 1)
}
const allEqual = (arr: number[]) =>
@@ -64,6 +66,7 @@ const Grid: React.FC<Props> = (props) => {
? props.setScoreX(props.scoreX + 1)
: props.setScoreO(props.scoreO + 1));
setBoard([2,2,2,2,2,2,2,2,2]);
+ winner < 2 && props.setTurn(winner); // set turn to prev. winner
}
useEffect(() => {
@@ -77,7 +80,7 @@ const Grid: React.FC<Props> = (props) => {
});
return (
- <div className="Grid">
+ <div className="Grid">
{
board.map(
(i, index) =>