Changeset 3a783f2 for components/poker


Ignore:
Timestamp:
07/05/22 16:36:24 (2 years ago)
Author:
anastasovv <simon@…>
Branches:
main
Children:
189cd8f
Parents:
b13f93b
Message:

Finished poker and added ball to roulette

Location:
components/poker
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • components/poker/PokerHeader.jsx

    rb13f93b r3a783f2  
    2323    const styleState = useSelector(state => state.style);
    2424
    25     useEffect(() => async function() {
     25    useEffect(() => {
    2626        // display loading screen
    2727        dispatch(setStyle({
     
    3030        }));
    3131
    32         let interval = setInterval(() => {
    33             axios.get(`/api/poker?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
    34                 if (res.data?.success) {
    35                     dispatch(setPokerGame(res.data?.pokerGame))
    36                 }
    37             });
    38         }, 3000);
     32        let interval;
    3933
    4034        axios.get(`/api/poker?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => {
     
    5145                    displayLoadingScreen: false,
    5246                }))
     47
     48                interval = setInterval(() => {
     49                    axios.get(`/api/poker?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(newRes => {
     50                        if (newRes.data?.success) {
     51                            dispatch(setPokerGame(newRes.data?.pokerGame))
     52       
     53                            if (newRes.data?.pokerGame?.player?.credits !== playerState.player.credits && newRes.data?.pokerGame?.player?.credits > 0) {
     54                                dispatch(setPlayer({
     55                                    ...playerState.player,
     56                                    credits: newRes.data?.pokerGame?.player?.credits,
     57                                }))
     58                            }
     59                        }
     60                    });
     61                }, 2000);
    5362            }
    5463            else {
     
    6675            }
    6776        });
    68        
    69         return () => clearInterval(interval);
    70     }, [playerState.pokerGame.player.table])
     77    }, [])
     78
     79    function leaveTable() {
     80        axios.get(`/api/poker?action=leave_table&session_id=${localStorage.CAESSINO_SESSION_ID}`);
     81    }
    7182
    7283    return (
    7384        <header className="header">
    74             <Link href="/" passHref>
    75                 <h2>
    76                     <AiOutlineArrowLeft />
    77                 </h2>
    78             </Link>
     85            <div style={{display: 'flex', alignItems: 'center'}}>
     86                <Link href="/" passHref>
     87                    <h2>
     88                        <AiOutlineArrowLeft />
     89                    </h2>
     90                </Link>
     91                { playerState.pokerGame.player.table.length > 0 && <button style={{marginBottom: '4px', marginLeft: '32px', fontSize: '16px'}} className="tertiaryButton" onClick={() => leaveTable()}>Leave Table</button> }
     92            </div>
    7993            <nav>
    8094                <ul>
  • components/poker/PokerSections.jsx

    rb13f93b r3a783f2  
    99
    1010import { useSelector, useDispatch } from 'react-redux'
     11import Pot from './sections/Pot'
     12import RaiseModal from './sections/RaiseModal'
    1113
    1214const PokerSections = () => {
     
    2426          <CardsInTheMiddle/>
    2527
     28          <Pot/>
     29
    2630          <PlayButtons/>
     31
     32          <RaiseModal/>
    2733      </>
    2834    )
  • components/poker/sections/Messages.jsx

    rb13f93b r3a783f2  
    1717        turnMessage = `It\'s ${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName}\'s turn.`;
    1818
    19         if (playerState.pokerGame.table.lastBet > 0) {
    20             callMessage = `${playerState.pokerGame.table.players[playerState.pokerGame.table.turnIdx].displayName} must at least call $${playerState.pokerGame.table.lastBet}`;
     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)}`;
    2121        }
    2222    }
     
    2424    return (
    2525        <div className="pokerMessagesContainer">
    26             { playerState.pokerGame.table.started && <p>Round {playerState.pokerGame.table.round}/5{roundMessage}</p> }
     26            { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && 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> }
     27            { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && playerState.pokerGame.table.winners.length > 1 && <p>Game over - {playerState.pokerGame.table.winners.map(e=>e.displayName).join(", ")} drew!</p> }
     28            { playerState.pokerGame.table.started && playerState.pokerGame.table.ended && <p>New game will start soon.</p> }
     29
     30            { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>Round {playerState.pokerGame.table.round}/4{roundMessage}</p> }
    2731            { !playerState.pokerGame.table.started && <p>Waiting for coordinator {playerState.pokerGame.table.creator} to start the game.</p> }
    28             { playerState.pokerGame.table.started && <p>{turnMessage}</p> }
    29             { playerState.pokerGame.table.started && <p>{callMessage}</p> }
     32            { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{turnMessage}</p> }
     33            { playerState.pokerGame.table.started && !playerState.pokerGame.table.ended && <p>{callMessage}</p> }
    3034        </div>
    3135    )
  • components/poker/sections/PlayButtons.jsx

    rb13f93b r3a783f2  
    44
    55import axios from 'axios';
    6 import { setPokerGame } from '../../../redux/reducers/playerSlice';
     6import { setPoker } from '../../../redux/reducers/styleSlice';
    77
    88const PlayButtons = () => {
     
    1010
    1111  const playerState = useSelector(state => state.player);
     12  const styleState = useSelector(state => state.style);
    1213
    1314  function sitDown() {
     
    2021
    2122  const checkClass = playerState.pokerGame.table.lastBet === 0 ? 'secondaryButton' : 'tertiaryButton';
    22   const callClass = 'secondaryButton'
     23  const callClass = playerState.pokerGame.table.lastBet > 0 ? 'secondaryButton' : 'tertiaryButton'
    2324  const raiseClass = playerState.pokerGame.table.round >= 2 ? 'secondaryButton' : 'tertiaryButton';
    2425  const foldClass = 'secondaryButton';
     
    3334
    3435  function raise() {
    35     axios.get(`/api/poker?action=game_action&session_id=${localStorage.CAESSINO_SESSION_ID}&specificAction=raise&betAmount=0`);
     36    dispatch(setPoker({
     37        ...styleState.poker,
     38        displays: {
     39            ...styleState.poker.displays,
     40            raiseModal: true,
     41        },
     42    }))
    3643  }
    3744
     
    4047  }
    4148
    42   if (playerState.pokerGame.table.started && playerState.pokerGame.player.isSatDown) {
     49  if (playerState.pokerGame.table.started && playerState.pokerGame.player.isSatDown && parseInt(playerState.pokerGame.table.round) < 5) {
    4350    return (
    4451      <div className="pokerPlayButtonsContainer">
Note: See TracChangeset for help on using the changeset viewer.