Compare commits
5 commits
6e4353d2bc
...
1265510037
Author | SHA1 | Date | |
---|---|---|---|
1265510037 | |||
4fa7b63b04 | |||
4b4de32e1d | |||
|
4764c12909 | ||
e9a8267208 |
4 changed files with 12 additions and 3 deletions
|
@ -7,6 +7,6 @@ Content-Type: application/json
|
|||
}
|
||||
|
||||
###
|
||||
POST http://localhost:8080/blackjack/103/hit
|
||||
POST http://localhost:8080/blackjack/202/hit
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
|
|
|
@ -40,6 +40,12 @@ public class BlackJackGameController {
|
|||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||
Map<String, String> errorResponse = new HashMap<>();
|
||||
errorResponse.put("error", "Invalid state");
|
||||
return ResponseEntity.badRequest().body(errorResponse);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(blackJackService.hit(game));
|
||||
}
|
||||
|
||||
|
|
|
@ -89,12 +89,14 @@ public class BlackJackService {
|
|||
|
||||
if (playerHandValue == 21) {
|
||||
return BlackJackState.PLAYER_WON;
|
||||
} else if (playerHandValue > 21) {
|
||||
return BlackJackState.PLAYER_LOST;
|
||||
}
|
||||
|
||||
return BlackJackState.IN_PROGRESS;
|
||||
}
|
||||
|
||||
public int calculateHandValue(List<CardEntity> hand) {
|
||||
private int calculateHandValue(List<CardEntity> hand) {
|
||||
int sum = 0;
|
||||
int aceCount = 0;
|
||||
for (CardEntity card : hand) {
|
||||
|
|
|
@ -2,5 +2,6 @@ package de.szut.casino.blackjack;
|
|||
|
||||
public enum BlackJackState {
|
||||
PLAYER_WON,
|
||||
IN_PROGRESS
|
||||
IN_PROGRESS,
|
||||
PLAYER_LOST,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue