Skip to content

Commit

Permalink
Merge pull request #55 from Owlvernyte/flip-board-render
Browse files Browse the repository at this point in the history
feat: Add flip board
  • Loading branch information
fieztazica authored Oct 22, 2023
2 parents b6038ba + 3f01f7f commit 6ce2f2c
Showing 1 changed file with 72 additions and 70 deletions.
142 changes: 72 additions & 70 deletions app/(basic)/rooms/[id]/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,77 @@ function Game({ roomCode, accessToken, user }: GameProps) {
)
}

const squares = board.squares.map((row, i) =>
row.map((cell, j) => {
if (!cell) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
></Cell>
)
}

if (!isUserTurn) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<Piece
id={cell.id}
target={cell}
position={cell.coord}
title={'Cant move'}
disabled
draggable={false}
/>
</Cell>
)
}

if (board.isRedTurn === cell.isRed) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<DraggablePiece
id={cell.id}
target={cell}
position={cell.coord}
title={'Movable'}
/>
</Cell>
)
}

return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<Piece
id={cell.id}
target={cell}
position={cell.coord}
title={'Cant move'}
disabled
draggable={false}
/>
</Cell>
)
})
);

return (
<DndContext
onDragStart={handleDragStart}
Expand Down Expand Up @@ -363,76 +434,7 @@ function Game({ roomCode, accessToken, user }: GameProps) {
</div>
</div>
<Board>
{board.squares.map((row, i) =>
row.map((cell, j) => {
if (!cell) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
></Cell>
)
}

if (!isUserTurn) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<Piece
id={cell.id}
target={cell}
position={cell.coord}
title={'Cant move'}
disabled
draggable={false}
/>
</Cell>
)
}

if (board.isRedTurn === cell.isRed) {
return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<DraggablePiece
id={cell.id}
target={cell}
position={cell.coord}
title={'Movable'}
/>
</Cell>
)
}

return (
<Cell
key={`cell_${i}_${j}`}
id={`${i}_${j}`}
x={i}
y={j}
>
<Piece
id={cell.id}
target={cell}
position={cell.coord}
title={'Cant move'}
disabled
draggable={false}
/>
</Cell>
)
})
)}
{(board.isHostRed && isHost) || (!board.isHostRed && !isHost) ? squares : squares.reverse()}
</Board>
<div
id="right-area"
Expand Down

0 comments on commit 6ce2f2c

Please sign in to comment.