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
kuv2707 authored and asmit27rai committed Jun 28, 2024
1 parent e87b337 commit e22f88e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ export function getCardImageName(card: UNOCard): string {
} else {
return `${getColorAbbreviation(card.color)}${card.value}`;
}
}
}
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-[12px]"
style={{ marginLeft: '-8px' }}
>
{player.cards.length}
</div>
<div
className="player-name font-[Kavoon] mb-2 text-[14px] text-black bg-gray-400 rounded-lg shadow-md"
style={{ marginLeft: '-8px' }}
>
{player.name}
</div>
</div>
);
};

export default Player;
29 changes: 6 additions & 23 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useNavigate } from 'react-router-dom';
import { triggerEvent } from '../channel';
import { useAuth } from '../contexts/AuthContext';
import { useToast } from '../library/toast/toast-context';
import Player from '../library/Player';

function Game() {
const { gameState } = useGameContext();
Expand Down Expand Up @@ -192,10 +193,6 @@ function Game() {
{ top: '75%', left: '85%', transform: 'translate(-50%, -50%)' },
];

const cardStyles = {
filter: 'brightness(1)',
};

if (!gameState) {
return (
<div className="bg-gray-800 h-screen text-white text-5xl font-kavoon text-center">
Expand All @@ -212,26 +209,12 @@ function Game() {
</div>
{/* 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,
...(index === gameState.currentPlayerIndex && {
...cardStyles,
filter: 'brightness(1.5)',
}),
}}
>
<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 e22f88e

Please sign in to comment.