Compare commits

...

3 commits

Author SHA1 Message Date
f3414e77ca
player gets way to many cards and I dont know why pls help
All checks were successful
CI / Get Changed Files (pull_request) Successful in 6s
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 1m4s
2025-03-27 12:42:40 +01:00
40b717745d
fix(BlackJackGameController): improve game existence check 2025-03-27 12:30:01 +01:00
126681dfa4
feat(blackjack): implement hit action for blackjack game 2025-03-27 12:28:38 +01:00
3 changed files with 22 additions and 2 deletions

View file

@ -5,3 +5,8 @@ Content-Type: application/json
{
"betAmount": 1.01
}
###
POST http://localhost:8080/blackjack/52/hit
Authorization: Bearer {{token}}

View file

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@Slf4j
@ -35,11 +36,14 @@ public class BlackJackGameController {
UserEntity user = optionalUser.get();
BlackJackGameEntity game = blackJackService.getBlackJackGame(id);
if (game == null) {
if (game == null || !Objects.equals(game.getUserId(), user.getId())) {
return ResponseEntity.notFound().build();
}
// TODO validate that hit is a valid action
blackJackService.hit(game);
return ResponseEntity.ok(game);
}
@PostMapping("/blackjack/start")

View file

@ -5,6 +5,8 @@ import de.szut.casino.user.UserRepository;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
@ -48,6 +50,15 @@ public class BlackJackService {
return game;
}
public BlackJackGameEntity hit(BlackJackGameEntity game) {
CardEntity drawnCard = drawCardFromDeck(game);
List<CardEntity> playerCards = game.getPlayerCards();
playerCards.add(drawnCard);
blackJackGameRepository.save(game);
return game;
}
private void initializeDeck(BlackJackGameEntity game) {
for (Suit suit : Suit.values()) {
for (Rank rank : Rank.values()) {