feat: add balance when player wins with blackjack in first round #104

Merged
ptran merged 1 commit from feat/blackjack-win-on-start into main 2025-03-27 13:34:39 +00:00
2 changed files with 11 additions and 4 deletions

View file

@ -42,8 +42,15 @@ public class BlackJackService {
dealerCard.setCardType(CardType.DEALER);
game.getDealerCards().add(dealerCard);
game.setState(getState(game));
user.setBalance(user.getBalance().subtract(betAmount));
BlackJackState state = getState(game);
if (state == BlackJackState.PLAYER_BLACKJACK) {
BigDecimal blackjackWinnings = betAmount.multiply(new BigDecimal("1.5"));
user.setBalance(user.getBalance().add(blackjackWinnings));
} else {
user.setBalance(user.getBalance().subtract(betAmount));
}
game.setState(state);
userRepository.save(user);
blackJackGameRepository.save(game);
@ -88,7 +95,7 @@ public class BlackJackService {
int playerHandValue = calculateHandValue(game.getPlayerCards());
if (playerHandValue == 21) {
return BlackJackState.PLAYER_WON;
return BlackJackState.PLAYER_BLACKJACK;
} else if (playerHandValue > 21) {
return BlackJackState.PLAYER_LOST;
}

View file

@ -1,7 +1,7 @@
package de.szut.casino.blackjack;
public enum BlackJackState {
PLAYER_WON,
IN_PROGRESS,
PLAYER_BLACKJACK,
PLAYER_LOST,
}