refactor: add blackjack state enum

This commit is contained in:
Phan Huy Tran 2025-03-27 12:08:57 +01:00
commit caa210a80e
3 changed files with 13 additions and 2 deletions

View file

@ -33,7 +33,8 @@ public class BlackJackGameEntity {
return user != null ? user.getId() : null; return user != null ? user.getId() : null;
} }
private String state; @Enumerated(EnumType.STRING)
private BlackJackState state;
private BigDecimal bet; private BigDecimal bet;
@OneToMany(mappedBy = "game", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "game", cascade = CascadeType.ALL, orphanRemoval = true)

View file

@ -23,7 +23,7 @@ public class BlackJackService {
BlackJackGameEntity game = new BlackJackGameEntity(); BlackJackGameEntity game = new BlackJackGameEntity();
game.setUser(user); game.setUser(user);
game.setBet(betAmount); game.setBet(betAmount);
game.setState("IN_PROGRESS"); game.setState(getState(game));
initializeDeck(game); initializeDeck(game);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -63,4 +63,8 @@ public class BlackJackService {
return game.getDeck().removeFirst(); return game.getDeck().removeFirst();
} }
private BlackJackState getState(BlackJackGameEntity game) {
return BlackJackState.IN_PROGRESS;
}
} }

View file

@ -0,0 +1,6 @@
package de.szut.casino.blackjack;
public enum BlackJackState {
PLAYER_WON,
IN_PROGRESS
}