Changeset 55701f0 for components/blackjack
- Timestamp:
- 07/16/22 11:18:24 (2 years ago)
- Branches:
- main
- Children:
- e007fcd
- Parents:
- 433e0c5
- Location:
- components/blackjack
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
components/blackjack/BlackjackHeader.jsx
r433e0c5 r55701f0 30 30 })); 31 31 32 dispatch(setBlackjack({ 33 ...styleState.blackjack, 34 inputControls: { 35 ...styleState.blackjack.inputControls, 36 initialBet: { 37 ...styleState.blackjack.inputControls.initialBet, 38 chosenCredits: parseInt(playerState.player.credits/2), 39 } 40 } 41 })); 42 32 let interval = null; 43 33 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 44 34 if (res.data?.success) { … … 48 38 session_id: res.data?.session_id, 49 39 credits: res.data?.credits, 50 }));51 52 dispatch(setBlackjackGame({53 ...playerState.blackjackGame,54 status: res.data?.status,55 playerCards: res.data?.playerCards,56 dealerCards: res.data?.dealerCards,57 40 })) 58 41 59 dispatch(setStyle({ 60 ...styleState.style, 61 displayLoadingScreen: false, 42 dispatch(setBlackjack({ 43 ...styleState.blackjack, 44 inputControls: { 45 ...styleState.blackjack.inputControls, 46 initialBet: { 47 ...styleState.blackjack.inputControls.initialBet, 48 chosenCredits: parseInt(playerState.player.credits/2), 49 }, 50 sideBet: { 51 ...styleState.blackjack.inputControls.sideBet, 52 chosenCredits: parseInt(playerState.player.credits/2), 53 } 54 }, 62 55 })) 63 56 64 if (parseInt(res.data?.status.toString().substr(1, 1)) == 5) { 65 dispatch(setBlackjack({ 66 ...styleState.blackjack, 67 inputControls: { 68 ...styleState.blackjack.inputControls, 69 initialBet: { 70 ...styleState.blackjack.inputControls.initialBet, 71 chosenCredits: parseInt(res.data?.initialBet), 72 }, 73 sideBet: { 74 ...styleState.blackjack.inputControls.sideBet, 75 chosenCredits: 0, 57 if (interval !== null) clearInterval(interval); 58 59 interval = setInterval(() => { 60 axios.get(`/api/blackjack?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(newRes => { 61 if (newRes.data?.success) { 62 dispatch(setBlackjackGame(newRes.data?.blackjackGame)) 63 64 if (newRes.data?.blackjackGame?.credits !== playerState.player.credits && parseInt(newRes.data?.blackjackGame?.credits) > 0) { 65 dispatch(setPlayer({ 66 ...playerState.player, 67 displayName: res.data?.displayName, 68 session_id: res.data?.session_id, 69 credits: newRes.data?.blackjackGame?.credits, 70 })) 76 71 } 77 }, 78 displays: { 79 ...styleState.blackjack.displays, 80 initialBet: false, 81 hitStand: true, 72 73 dispatch(setStyle({ 74 ...styleState.style, 75 displayLoadingScreen: false, 76 notification: { 77 ...styleState.style.notification, 78 show: false, 79 }, 80 lostConnectionInfo: { 81 show: false, 82 message: '' 83 }, 84 alert: (newRes.data?.blackjackGame?.status?.includes('_5_') && !newRes.data?.blackjackGame?.betOutcomeMessageShown) ? { 85 show: true, 86 title: newRes.data?.blackjackGame?.messageTitle, 87 subtitle: newRes.data?.blackjackGame?.messageDescription, 88 button: { 89 text: 'Play Again', 90 action: 'play_again', 91 } 92 } : (newRes.data?.blackjackGame?.status?.includes('_4_') && !newRes.data?.blackjackGame?.sideBetOutcomeMessageShown && newRes.data?.blackjackGame?.sideBet > 0) ? { 93 show: true, 94 title: newRes.data?.blackjackGame?.messageTitle, 95 subtitle: newRes.data?.blackjackGame?.messageDescription, 96 button: { 97 text: 'Continue', 98 action: 'continue_from_side_bet', 99 } 100 } : { 101 ...styleState.style.alert, 102 show: false, 103 }, 104 })) 82 105 } 83 })) 84 85 if (res.data?.outcome === 'player_busted') { 106 }).catch(error => { 86 107 dispatch(setStyle({ 87 108 ...styleState.style, 88 alert: { 109 displayLoadingScreen: false, 110 lostConnectionInfo: { 89 111 show: true, 90 title: 'You busted!', 91 subtitle: `You lost $${-1*res.data?.earnings}`, 92 button: { 93 text: 'Play again', 94 action: 'play_again', 95 } 112 message: 'Game will resume upon reconnection to the server.' 96 113 } 97 114 })) 98 } 99 else if (res.data?.outcome === 'dealer_busted') { 100 dispatch(setStyle({ 101 ...styleState.style, 102 alert: { 103 show: true, 104 title: 'Dealer busted!', 105 subtitle: `You won $${res.data?.earnings}`, 106 button: { 107 text: 'Play again', 108 action: 'play_again', 109 } 110 } 111 })) 112 } 113 else if (res.data?.outcome === 'player_won') { 114 dispatch(setStyle({ 115 ...styleState.style, 116 alert: { 117 show: true, 118 title: 'You won!', 119 subtitle: `You won $${res.data?.earnings}`, 120 button: { 121 text: 'Play again', 122 action: 'play_again', 123 } 124 } 125 })) 126 } 127 else if (res.data?.outcome === 'player_lost') { 128 dispatch(setStyle({ 129 ...styleState.style, 130 alert: { 131 show: true, 132 title: 'You lost!', 133 subtitle: `You lost $${-1*res.data?.earnings}`, 134 button: { 135 text: 'Play again', 136 action: 'play_again', 137 } 138 } 139 })) 140 } 141 else if (res.data?.outcome === 'draw') { 142 dispatch(setStyle({ 143 ...styleState.style, 144 alert: { 145 show: true, 146 title: 'Draw!', 147 subtitle: `You got your $${res.data?.earnings} back`, 148 button: { 149 text: 'Play again', 150 action: 'play_again', 151 } 152 } 153 })) 154 } 155 } 156 157 if (parseInt(res.data?.status.toString().substr(1, 1)) == 4) { 158 dispatch(setBlackjack({ 159 ...styleState.blackjack, 160 inputControls: { 161 ...styleState.blackjack.inputControls, 162 initialBet: { 163 ...styleState.blackjack.inputControls.initialBet, 164 chosenCredits: parseInt(res.data?.initialBet), 165 }, 166 sideBet: { 167 ...styleState.blackjack.inputControls.sideBet, 168 chosenCredits: 0, 169 } 170 }, 171 displays: { 172 ...styleState.blackjack.displays, 173 initialBet: false, 174 hitStand: true, 175 } 176 })) 177 } 178 179 if (parseInt(res.data?.status.toString().substr(1, 1)) == 3) { 180 dispatch(setBlackjack({ 181 ...styleState.blackjack, 182 inputControls: { 183 ...styleState.blackjack.inputControls, 184 initialBet: { 185 ...styleState.blackjack.inputControls.initialBet, 186 chosenCredits: parseInt(res.data?.initialBet), 187 }, 188 sideBet: { 189 ...styleState.blackjack.inputControls.sideBet, 190 chosenCredits: parseInt(res.data?.sideBet), 191 } 192 }, 193 displays: { 194 ...styleState.blackjack.displays, 195 initialBet: false, 196 hitStand: true, 197 } 198 })) 199 } 200 201 if (parseInt(res.data?.status.toString().substr(1, 1)) == 2) { 202 dispatch(setBlackjack({ 203 ...styleState.blackjack, 204 inputControls: { 205 ...styleState.blackjack.inputControls, 206 initialBet: { 207 ...styleState.blackjack.inputControls.initialBet, 208 chosenCredits: parseInt(res.data?.initialBet), 209 } 210 }, 211 displays: { 212 ...styleState.blackjack.displays, 213 initialBet: false, 214 sideBet: true, 215 } 216 })) 217 } 218 219 if (parseInt(res.data?.status.toString().substr(1, 1)) == 1) { 220 dispatch(setBlackjack({ 221 ...styleState.blackjack, 222 inputControls: { 223 ...styleState.blackjack.inputControls, 224 initialBet: { 225 ...styleState.blackjack.inputControls.initialBet, 226 chosenCredits: parseInt(res.data?.credits/2), 227 } 228 }, 229 })) 230 } 115 }); 116 }, 1000); 231 117 } 232 118 else { … … 244 130 } 245 131 }); 132 133 return () => { 134 if (interval !== null) clearInterval(interval); 135 }; 246 136 }, []); 247 137 -
components/blackjack/DisplayBet.jsx
r433e0c5 r55701f0 6 6 const playerState = useSelector(state => state.player); 7 7 const styleState = useSelector(state => state.style); 8 9 8 let display = parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 2 ? 'block' : 'none'; 10 let displaySideBet = ( parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 3 && parseInt( styleState.blackjack.inputControls.sideBet.chosenCredits) > 0) ? 'block' : 'none';9 let displaySideBet = ( parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 3 && parseInt(playerState.blackjackGame.sideBet) > 0 && !playerState.blackjackGame.sideBetOutcomeMessageShown ) ? 'block' : 'none'; 11 10 12 11 return ( 13 12 <div className="blackjackDisplayBet" style={{display: display}}> 14 <span>${ styleState.blackjack.inputControls.initialBet.chosenCredits}{displaySideBet === 'block' ? ` + $${styleState.blackjack.inputControls.sideBet.chosenCredits}` : ''}</span>13 <span>${playerState.blackjackGame.initialBet}{displaySideBet === 'block' ? ` + $${playerState.blackjackGame.sideBet}` : ''}</span> 15 14 </div> 16 15 ) -
components/blackjack/PlayButtons.jsx
r433e0c5 r55701f0 44 44 45 45 function placeInitialBetClicked() { 46 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(res => { 47 if (res.data?.success) { 48 dispatch(setBlackjackGame({ 49 ...playerState.blackjackGame, 50 status: res.data?.status, 51 })) 52 53 dispatch(setPlayer({ 54 ...playerState.player, 55 credits: res.data?.credits, 56 })) 57 58 dispatch(setBlackjack({ 59 ...styleState.blackjack, 60 displays: { 61 ...styleState.blackjack.displays, 62 initialBet: false, 63 sideBet: true, 64 } 65 })) 66 } 67 }); 46 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`); 68 47 } 69 48 … … 124 103 const texts = splitTexts(e.target.innerHTML); 125 104 126 dispatch(setBlackjackGame({ 127 ...playerState.blackjackGame, 128 sideBetName: sideBetName 129 })) 130 131 dispatch(setBlackjack({ 132 ...styleState.blackjack, 105 dispatch(setBlackjack({ 106 ...styleState.blackjack, 107 sideBetName: sideBetName, 133 108 displays: { 134 109 ...styleState.blackjack.displays, … … 145 120 146 121 function placeSideBetClicked() { 147 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${ playerState.blackjackGame.sideBetName}`).then(res => {122 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${styleState.blackjack.sideBetName}`).then(res => { 148 123 if (res.data?.success) { 149 dispatch(setBlackjackGame({150 ...playerState.blackjackGame,151 status: res.data?.status,152 }))153 154 dispatch(setPlayer({155 ...playerState.player,156 credits: res.data?.credits,157 }))158 159 124 dispatch(setBlackjack({ 160 125 ...styleState.blackjack, … … 162 127 ...styleState.blackjack.displays, 163 128 sideBetsChooseCreditsModal: false, 164 sideBet: false,165 hitStand: true,166 129 } 167 130 })) … … 181 144 sideBetsModal: false, 182 145 sideBetsChooseCreditsModal: false, 183 sideBet: false,184 hitStand: true,185 },186 inputControls: {187 ...styleState.blackjack.inputControls,188 sideBet: {189 ...styleState.blackjack.inputControls.sideBet,190 chosenCredits: 0,191 }192 146 }, 193 147 })) … … 199 153 200 154 function getCards() { 201 axios.get(`/api/blackjack?action=get_initial_cards&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 202 if (res.data?.success) { 203 dispatch(setBlackjackGame({ 204 ...playerState.blackjackGame, 205 status: res.data?.status, 206 playerCards: res.data?.playerCards, 207 dealerCards: res.data?.dealerCards, 208 })) 209 210 if (res.data?.sideBetOutcome !== '') { 211 if (res.data.sideBetOutcome === 'side_bet_won') { 212 dispatch(setBlackjackGame({ 213 ...playerState.blackjackGame, 214 credits: res.data?.credits, 215 })) 216 217 dispatch(setStyle({ 218 ...styleState.style, 219 alert: { 220 show: true, 221 title: 'You won the side bet!', 222 subtitle: `You won $${res.data?.sideBetEarnings}`, 223 button: { 224 text: 'Continue', 225 action: 'continue_from_side_bet', 226 } 227 } 228 })) 229 } 230 else if (res.data.sideBetOutcome === 'side_bet_lost') { 231 dispatch(setStyle({ 232 ...styleState.style, 233 alert: { 234 show: true, 235 title: 'You lost the side bet!', 236 subtitle: `You lost $${-1*res.data?.sideBetEarnings}`, 237 button: { 238 text: 'Continue', 239 action: 'continue_from_side_bet', 240 } 241 } 242 })) 243 } 244 } 245 } 246 }); 155 axios.get(`/api/blackjack?action=get_initial_cards&session_id=${localStorage.CAESSINO_SESSION_ID}`); 247 156 } 248 157 … … 282 191 283 192 function standClicked() { 284 axios.get(`/api/blackjack?action=stand&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 285 if (res.data?.success) { 286 dispatch(setBlackjackGame({ 287 ...playerState.blackjackGame, 288 status: res.data?.status, 289 playerCards: res.data?.playerCards, 290 dealerCards: res.data?.dealerCards, 291 })) 292 293 if (res.data?.status.toString().substr(1, 1) === '5') { // game_over 294 dispatch(setPlayer({ 295 ...playerState.player, 296 credits: res.data?.credits, 297 })) 298 299 if (res.data?.outcome === 'dealer_busted') { 300 dispatch(setStyle({ 301 ...styleState.style, 302 alert: { 303 show: true, 304 title: 'Dealer busted!', 305 subtitle: `You won $${res.data?.earnings}`, 306 button: { 307 text: 'Play again', 308 action: 'play_again', 309 } 310 } 311 })) 312 } 313 else if (res.data?.outcome === 'player_won') { 314 dispatch(setStyle({ 315 ...styleState.style, 316 alert: { 317 show: true, 318 title: 'You won!', 319 subtitle: `You won $${res.data?.earnings}`, 320 button: { 321 text: 'Play again', 322 action: 'play_again', 323 } 324 } 325 })) 326 } 327 else if (res.data?.outcome === 'player_lost') { 328 dispatch(setStyle({ 329 ...styleState.style, 330 alert: { 331 show: true, 332 title: 'You lost!', 333 subtitle: `You lost $${-1*res.data?.earnings}`, 334 button: { 335 text: 'Play again', 336 action: 'play_again', 337 } 338 } 339 })) 340 } 341 else if (res.data?.outcome === 'draw') { 342 dispatch(setStyle({ 343 ...styleState.style, 344 alert: { 345 show: true, 346 title: 'Draw!', 347 subtitle: `You got your $${res.data?.earnings} back`, 348 button: { 349 text: 'Play again', 350 action: 'play_again', 351 } 352 } 353 })) 354 } 355 } 356 } 357 }); 193 axios.get(`/api/blackjack?action=stand&session_id=${localStorage.CAESSINO_SESSION_ID}`); 358 194 } 359 195 360 196 return ( 361 197 <div className="blackjackButtons"> 362 <div className="blackjackInitialBet" style={{display: styleState.blackjack.displays.initialBet? 'flex' : 'none'}}>198 <div className="blackjackInitialBet" style={{display: playerState.blackjackGame.status.includes('_1_') ? 'flex' : 'none'}}> 363 199 <div> 364 200 <input type="range" className="primarySlider" min={0} max={playerState.player.credits} step={1} value={styleState.blackjack.inputControls.initialBet.chosenCredits} onChange={(e) => chooseCoins(e)} /> … … 369 205 <button className="primaryButton" onClick={() => placeInitialBetClicked()}>Place Initial Bet <GiTwoCoins style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 370 206 </div> 371 <div className="blackjackSideBet" style={{display: styleState.blackjack.displays.sideBet? 'flex' : 'none'}}>207 <div className="blackjackSideBet" style={{display: playerState.blackjackGame.status.includes('_2_') ? 'flex' : 'none'}}> 372 208 <button className="primaryButton" onClick={() => placeSideBetsClicked()}>Place Side Bets <GiTwoCoins style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 373 209 <button className="primaryButton" onClick={() => skipSideBetsClicked()}>Skip <GiReturnArrow style={{marginTop: '3px', marginBottom: '-3px', transform: 'rotateZ(-15deg)'}} /></button> 374 210 </div> 375 <div className="blackjackHitStand" style={{display: styleState.blackjack.displays.hitStand? 'flex' : 'none'}}>211 <div className="blackjackHitStand" style={{display: parseInt(playerState.blackjackGame.status.toString().substr(1, 1)) >= 3 ? 'flex' : 'none'}}> 376 212 <button className="primaryButton" onClick={() => hitClicked()}>Hit <GiCardDraw style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 377 213 <button className="primaryButton" onClick={() => standClicked()}>Stand <AiFillCheckCircle style={{marginTop: '3px', marginBottom: '-3px'}} /></button>
Note:
See TracChangeset
for help on using the changeset viewer.