diff --git a/src/Casino/Blackjack.tsx b/src/Casino/Blackjack.tsx index 9219775b1..c6c9a5b7a 100644 --- a/src/Casino/Blackjack.tsx +++ b/src/Casino/Blackjack.tsx @@ -217,30 +217,19 @@ export class Blackjack extends Game { }; finishGame = (result: Result): void => { - let gains = 0; - if (this.isPlayerWinResult(result)) { - gains = this.state.bet; - // We 2x the gains because we took away money at the start, so we need to give the original bet back. - this.win(this.props.p, 2 * gains); - } else if (result === Result.DealerWon) { - gains = -1 * this.state.bet; - this.win(this.props.p, 0); // We took away the bet at the start, don't need to take more - // Dont need to take money here since we already did it at the start - } else if (result === Result.Tie) { - this.win(this.props.p, this.state.bet); // Get the original bet back - } - + const gains = result === Result.DealerWon ? 0 : // We took away the bet at the start, don't need to take more + result === Result.Tie ? this.state.bet : // We took away the bet at the start, give it back + result === Result.PlayerWon ? 2 * this.state.bet : // Give back their bet plus their winnings + result === Result.PlayerWonByBlackjack ? 2.5 * this.state.bet : // Blackjack pays out 1.5x bet! + (() => { throw new Error(`Unexpected result: ${result}`); })(); // This can't happen, right? + this.win(this.props.p, gains); this.setState({ gameInProgress: false, result, - gains: this.state.gains + gains, + gains: this.state.gains + gains - this.state.bet, // Not updated upfront - only tracks the final outcome }); }; - isPlayerWinResult = (result: Result): boolean => { - return result === Result.PlayerWon || result === Result.PlayerWonByBlackjack; - }; - wagerOnChange = (event: React.ChangeEvent): void => { const { p } = this.props; const betInput = event.target.value; @@ -356,20 +345,20 @@ export class Blackjack extends Game { )} {/* Main game part. Displays both if the game is in progress OR if there's a result so you can see - * the cards that led to that result. */} + * the cards that led to that result. */} {(gameInProgress || result !== Result.Pending) && ( <> -
Player
+ Player {playerHand.cards.map((card, i) => ( ))} -
Value(s): 
- {playerHandValues.map((value, i) => ( -
{value}
- ))} + Count: { + playerHandValues.map((value, i) => {value}) + .reduce((prev, curr) => [prev, ' or ', curr]) + }
@@ -377,7 +366,7 @@ export class Blackjack extends Game { -
Dealer
+ Dealer {dealerHand.cards.map((card, i) => ( // Hide every card except the first while game is in progress
@@ -399,9 +388,10 @@ export class Blackjack extends Game { {/* Results from previous round */} {result !== Result.Pending && ( - {result} - {this.isPlayerWinResult(result) && } - {result === Result.DealerWon && } + {result}  + {result === Result.PlayerWon && } + {result === Result.PlayerWonByBlackjack && } + {result === Result.DealerWon && } )}