Compare commits

...

2 commits

Author SHA1 Message Date
ed6071a0ba Merge pull request 'feat: add balance when player wins with blackjack in first round' (!104) from feat/blackjack-win-on-start into main
All checks were successful
Release / Release (push) Successful in 1m12s
Reviewed-on: #104
Reviewed-by: Jan K9f <jan@kjan.email>
2025-03-27 13:34:38 +00:00
Phan Huy Tran
ffd651d74b 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
2025-03-27 14:18:03 +01: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,
}