Skip to content

Commit

Permalink
Frontend: Display Player names along with cards
Browse files Browse the repository at this point in the history
1. The Player component was refactored to separate JSX for rendering player cards.

2. Highlighting functionality was added to indicate the current player's turn.

3. Player names were styled to appear in a white box with black text.

4. Brightness adjustment was applied to highlight the active player.

Fixes #158
  • Loading branch information
asmit27rai committed Jun 27, 2024
1 parent a82e26f commit f6af5de
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
48 changes: 48 additions & 0 deletions frontend/src/library/Player.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';

interface Player {
name: string;
cards: { length: number };
}

interface PlayerProps {
player: Player;
highlighted: boolean;
positionStyle: React.CSSProperties;
}

const Player: React.FC<PlayerProps> = ({
player,
highlighted,
positionStyle,
}) => {
return (
<div
className="absolute flex flex-col items-center justify-center bg-player-icon-bg"
style={{
...positionStyle,
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
width: '70px',
height: '80px',
zIndex: 2,
filter: highlighted ? 'brightness(1.5)' : 'none',
}}
>
<div
className="player-cards font-[Kavoon] text-gray-900 mt-[96px] text-[10px]"
style={{ marginLeft: '-8px' }}
>
{player.cards.length}
</div>
<div
className="player-name font-[Kavoon] mb-2 text-[14px] text-black bg-white rounded-lg shadow-md"
style={{ marginLeft: '-8px' }}
>
{player.name}
</div>
</div>
);
};

export default Player;
21 changes: 6 additions & 15 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IoSettings } from 'react-icons/io5';
import { useNavigate } from 'react-router-dom';
import { triggerEvent } from '../channel';
import { useAuth } from '../contexts/AuthContext';
import Player from '../library/Player';

function Game() {
const { gameState } = useGameContext();
Expand Down Expand Up @@ -192,22 +193,12 @@ function Game() {
<div className="relative w-full max-w-6xl h-[75vh]">
{/* Players */}
{gameState.players.slice(0, 6).map((player, index) => (
<div
<Player
key={index}
className="absolute flex flex-col items-center justify-center bg-player-icon-bg"
style={{
...playerPositions[index],
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
width: '70px',
height: '80px',
zIndex: 2,
}}
>
<div className="player-cards text-black mt-[61px]">
{player.cards.length}
</div>
</div>
player={player}
highlighted={index === gameState.currentPlayerIndex}
positionStyle={playerPositions[index]}
/>
))}

{/* Center Deck and UNO Button */}
Expand Down

0 comments on commit f6af5de

Please sign in to comment.