aboutsummaryrefslogtreecommitdiff
path: root/front/pages/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'front/pages/index.tsx')
-rw-r--r--front/pages/index.tsx29
1 files changed, 19 insertions, 10 deletions
diff --git a/front/pages/index.tsx b/front/pages/index.tsx
index c77fc5c..4bb154d 100644
--- a/front/pages/index.tsx
+++ b/front/pages/index.tsx
@@ -8,7 +8,7 @@ import LoginForm from '../components/LoginForm';
interface GameState {
cards: Card[],
- players: {username: string, numCards: number, stackSize: number, rank: number}[],
+ players: {username: string, numCards: number, stackSize: number, flipped: Card[], rank: number}[],
lastPlayed: number,
lastPlayedPlayer: string | null,
playerTurn: string
@@ -213,13 +213,22 @@ export default function Game() {
<p>Stacks:</p>
{gameState.players.map((player, i) => (
<label key={player.username+': '+player.stackSize}>
- <button
- onClick={() => socket.emit('flip', i)}
- disabled={username !== gameState.lastPlayedPlayer}
- >
- Flip!
- </button>
- {' '+player.username+': '+player.stackSize+' cards '}
+ <div>
+ <button
+ onClick={() => socket.emit('flip', i)}
+ disabled={username !== gameState.lastPlayedPlayer || player.stackSize === 0}
+ >
+ Flip!
+ </button>
+ {' '+player.username+': '+player.stackSize+' cards '}
+ {player.flipped.map((card, i) => (
+ <label key={card.rank+' '+card.suit}>
+ <span style={{color: (card.suit === Suit.Hearts || card.suit === Suit.Diamonds ? 'red' : 'black')}}>
+ {' '+rankStrs[card.rank]+' '+suitChars[card.suit]}
+ </span>
+ </label>
+ ))}
+ </div>
</label>
))}
</div>
@@ -236,7 +245,7 @@ export default function Game() {
</li>
))}
</ul>
- {(gameState.lastPlayed ? `${gameState.lastPlayedPlayer}` : `${gameState.playerTurn}`) + ` lost! Now they must give up one of their cards!`}
+ {(gameState.lastPlayed > 0 ? `${gameState.lastPlayedPlayer}` : `${gameState.playerTurn}`) + ` lost! Now they must give up one of their cards!`}
<div>
<p>Your cards:</p>
{gameState.cards.map((card, i) => (
@@ -244,7 +253,7 @@ export default function Game() {
<div>
<button
onClick={() => socket.emit('giveup', i)}
- disabled={username !== (gameState.lastPlayed ? gameState.lastPlayedPlayer : gameState.playerTurn)}
+ disabled={username !== (gameState.lastPlayed > 0 ? gameState.lastPlayedPlayer : gameState.playerTurn)}
>
Give up this card!
</button>