Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
ed6071a0ba | |||
|
ffd651d74b |
2 changed files with 11 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
public enum BlackJackState {
|
||||
PLAYER_WON,
|
||||
IN_PROGRESS,
|
||||
PLAYER_BLACKJACK,
|
||||
PLAYER_LOST,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue