Compare commits
1 commit
3f9ddc35df
...
d7ed661679
Author | SHA1 | Date | |
---|---|---|---|
d7ed661679 |
4 changed files with 3 additions and 12 deletions
|
@ -7,6 +7,6 @@ Content-Type: application/json
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
###
|
||||||
POST http://localhost:8080/blackjack/202/hit
|
POST http://localhost:8080/blackjack/103/hit
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,6 @@ public class BlackJackGameController {
|
||||||
return ResponseEntity.notFound().build();
|
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));
|
return ResponseEntity.ok(blackJackService.hit(game));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,14 +89,12 @@ public class BlackJackService {
|
||||||
|
|
||||||
if (playerHandValue == 21) {
|
if (playerHandValue == 21) {
|
||||||
return BlackJackState.PLAYER_WON;
|
return BlackJackState.PLAYER_WON;
|
||||||
} else if (playerHandValue > 21) {
|
|
||||||
return BlackJackState.PLAYER_LOST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return BlackJackState.IN_PROGRESS;
|
return BlackJackState.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateHandValue(List<CardEntity> hand) {
|
public int calculateHandValue(List<CardEntity> hand) {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int aceCount = 0;
|
int aceCount = 0;
|
||||||
for (CardEntity card : hand) {
|
for (CardEntity card : hand) {
|
||||||
|
|
|
@ -2,6 +2,5 @@ package de.szut.casino.blackjack;
|
||||||
|
|
||||||
public enum BlackJackState {
|
public enum BlackJackState {
|
||||||
PLAYER_WON,
|
PLAYER_WON,
|
||||||
IN_PROGRESS,
|
IN_PROGRESS
|
||||||
PLAYER_LOST,
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue