feat: add double down feature to blackjack game

This commit is contained in:
Jan-Marlon Leibl 2025-03-27 15:40:26 +01:00
commit d2b22b561d
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
7 changed files with 190 additions and 61 deletions

View file

@ -60,10 +60,13 @@ export default class BlackjackComponent {
this.gameInProgress.set(game.state === 'IN_PROGRESS');
this.gameState.set(game.state);
// When game ends, make sure all dealer cards are visible
const isGameOver = game.state !== 'IN_PROGRESS';
this.dealerCards.set(
game.dealerCards.map((card, index) => ({
...card,
hidden: index === 1 && game.state === 'IN_PROGRESS',
hidden: !isGameOver && index === 1 && game.state === 'IN_PROGRESS',
}))
);
@ -74,11 +77,14 @@ export default class BlackjackComponent {
}))
);
if (game.state !== 'IN_PROGRESS') {
// Only refresh and show game result if the game has ended
if (isGameOver) {
console.log('Game is over, state:', game.state);
this.refreshUserBalance();
setTimeout(() => {
this.showGameResult.set(true);
}, 1000);
// Show result immediately without resetting first
this.showGameResult.set(true);
console.log('Game result dialog should be shown now');
}
}
@ -127,7 +133,26 @@ export default class BlackjackComponent {
});
}
onDoubleDown(): void {
if (!this.currentGameId()) return;
if (this.gameState() !== 'IN_PROGRESS' || this.playerCards().length !== 2) {
return;
}
this.blackjackService.doubleDown(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
},
error: (error) => {
console.error('Failed to double down:', error);
this.handleGameError(error);
},
});
}
onCloseGameResult(): void {
console.log('Closing game result dialog');
this.showGameResult.set(false);
}