1 | import React from 'react'
|
---|
2 |
|
---|
3 | import { useSelector } from 'react-redux'
|
---|
4 |
|
---|
5 | const Messages = () => {
|
---|
6 | const playerState = useSelector(state => state.player);
|
---|
7 | const styleState = useSelector(state => state.style);
|
---|
8 |
|
---|
9 | let roundMessage = '';
|
---|
10 | if (playerState.pokerGame.table.round === 1) {
|
---|
11 | roundMessage = ' - Everyone must call $20 before cards are dealt.';
|
---|
12 | }
|
---|
13 |
|
---|
14 | let turnMessage = '';
|
---|
15 | let callMessage = '';
|
---|
16 | if (playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx] !== undefined) {
|
---|
17 | turnMessage = `It\'s ${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName}\'s turn.`;
|
---|
18 |
|
---|
19 | if (parseInt(playerState.pokerGame.table.lastBet) > 0) {
|
---|
20 | callMessage = `${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName} must at least call $${Math.min(playerState.player.credits, playerState.pokerGame.table.lastBet)}`;
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | return (
|
---|
25 | <div className="pokerMessagesContainer">
|
---|
26 | { playerState.pokerGame.table.ended && playerState.pokerGame.table.onlyOnePlayerLeft && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} because everyone else folded! Congratulations.</p> }
|
---|
27 | { playerState.pokerGame.table.ended && !playerState.pokerGame.table.onlyOnePlayerLeft && playerState.pokerGame.table.winners.length === 1 && <p>Game over - {playerState.pokerGame.table.winners[0]?.displayName} won ${playerState.pokerGame.table.winners[0]?.wonAmount} with a {playerState.pokerGame.table.winners[0]?.hand?.hand} combination! Congratulations.</p> }
|
---|
28 | { playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length > 1 && <p>Game over - {playerState.pokerGame.table.winners.map(e=>e.displayName).join(", ")} drew!</p> }
|
---|
29 | { playerState.pokerGame.table.ended && <p>New game will start soon.</p> }
|
---|
30 |
|
---|
31 | { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Round {playerState.pokerGame.table.round}/4{roundMessage}</p> }
|
---|
32 | { !playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Waiting for coordinator {playerState.pokerGame.table.creator} to start the game.</p> }
|
---|
33 | { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{turnMessage}</p> }
|
---|
34 | { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{callMessage}</p> }
|
---|
35 | </div>
|
---|
36 | )
|
---|
37 | }
|
---|
38 |
|
---|
39 | export default Messages |
---|