feat: add balance when player wins gets blackjack in first round
All checks were successful
CI / Get Changed Files (pull_request) Successful in 30s
CI / eslint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 1m19s

This commit is contained in:
Phan Huy Tran 2025-03-27 14:18:03 +01:00
parent 4fa7b63b04
commit ffd651d74b
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,
}