From 94470768154b24a56f33186d2fa855d57553ba22 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Mon, 23 Oct 2023 10:13:08 +0700 Subject: [PATCH] turned game table with viewer side --- app/(basic)/rooms/[id]/Game.tsx | 134 ++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/app/(basic)/rooms/[id]/Game.tsx b/app/(basic)/rooms/[id]/Game.tsx index cefc799..a81141e 100644 --- a/app/(basic)/rooms/[id]/Game.tsx +++ b/app/(basic)/rooms/[id]/Game.tsx @@ -100,6 +100,10 @@ function Game({ roomCode, accessToken, user }: GameProps) { return false })() + const isBoardReversed: boolean = !(!isPlayer + ? !board.isHostRed + : (board.isHostRed && isHost) || (!board.isHostRed && !isHost)) + useEffect(() => { connection.on('error', (e) => { console.log('ws error', e) @@ -328,27 +332,60 @@ function Game({ roomCode, accessToken, user }: GameProps) { ) } - const squares = board.squares.map((row, i) => - row.map((cell, j) => { - if (!cell) { - return ( - - ) - } + const RenderedSquares = () => { + const squares = board.squares.map((row, i) => + row.map((cell, j) => { + if (!cell) { + return ( + + ) + } + + if (!isUserTurn) { + return ( + + + + ) + } + + if (board.isRedTurn === cell.isRed) { + return ( + + + + ) + } - if (!isUserTurn) { return ( - + ) - } - - if (board.isRedTurn === cell.isRed) { - return ( - - - - ) - } + }) + ) - return ( - - - - ) - }) - ); + return isBoardReversed + ? squares.map((row) => row.reverse()).reverse() + : squares + } return ( - {(board.isHostRed && isHost) || (!board.isHostRed && !isHost) ? squares : squares.reverse()} +
)}