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
				
			
		
		
	
	
		
	
		
			All checks were successful
		
		
	
	Release / Release (push) Successful in 1m12s
				
			Reviewed-on: #104 Reviewed-by: Jan K9f <jan@kjan.email>
This commit is contained in:
		
				commit
				
					
						ed6071a0ba
					
				
			
		
					 2 changed files with 11 additions and 4 deletions
				
			
		| 
						 | 
					@ -42,8 +42,15 @@ public class BlackJackService {
 | 
				
			||||||
        dealerCard.setCardType(CardType.DEALER);
 | 
					        dealerCard.setCardType(CardType.DEALER);
 | 
				
			||||||
        game.getDealerCards().add(dealerCard);
 | 
					        game.getDealerCards().add(dealerCard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        game.setState(getState(game));
 | 
					        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));
 | 
					            user.setBalance(user.getBalance().subtract(betAmount));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        game.setState(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        userRepository.save(user);
 | 
					        userRepository.save(user);
 | 
				
			||||||
        blackJackGameRepository.save(game);
 | 
					        blackJackGameRepository.save(game);
 | 
				
			||||||
| 
						 | 
					@ -88,7 +95,7 @@ public class BlackJackService {
 | 
				
			||||||
        int playerHandValue = calculateHandValue(game.getPlayerCards());
 | 
					        int playerHandValue = calculateHandValue(game.getPlayerCards());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (playerHandValue == 21) {
 | 
					        if (playerHandValue == 21) {
 | 
				
			||||||
            return BlackJackState.PLAYER_WON;
 | 
					            return BlackJackState.PLAYER_BLACKJACK;
 | 
				
			||||||
        } else if (playerHandValue > 21) {
 | 
					        } else if (playerHandValue > 21) {
 | 
				
			||||||
            return BlackJackState.PLAYER_LOST;
 | 
					            return BlackJackState.PLAYER_LOST;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
package de.szut.casino.blackjack;
 | 
					package de.szut.casino.blackjack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public enum BlackJackState {
 | 
					public enum BlackJackState {
 | 
				
			||||||
    PLAYER_WON,
 | 
					 | 
				
			||||||
    IN_PROGRESS,
 | 
					    IN_PROGRESS,
 | 
				
			||||||
 | 
					    PLAYER_BLACKJACK,
 | 
				
			||||||
    PLAYER_LOST,
 | 
					    PLAYER_LOST,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue