feat(blackjack): refresh user balance on game state change

This commit is contained in:
Jan-Marlon Leibl 2025-04-02 10:25:43 +02:00
parent 08b12d238e
commit e983b21e07
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
7 changed files with 48 additions and 19 deletions

View file

@ -82,8 +82,7 @@ export default class BlackjackComponent {
if (isGameOver) {
console.log('Game is over, state:', game.state);
this.refreshUserBalance();
this.userService.refreshCurrentUser();
this.showGameResult.set(true);
console.log('Game result dialog should be shown now');
}
@ -96,7 +95,7 @@ export default class BlackjackComponent {
this.blackjackService.startGame(bet).subscribe({
next: (game) => {
this.updateGameState(game);
this.refreshUserBalance();
this.userService.refreshCurrentUser();
this.isActionInProgress.set(false);
},
error: (error) => {
@ -115,6 +114,9 @@ export default class BlackjackComponent {
this.blackjackService.hit(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
if (game.state !== 'IN_PROGRESS') {
this.userService.refreshCurrentUser();
}
this.isActionInProgress.set(false);
},
error: (error) => {
@ -139,6 +141,7 @@ export default class BlackjackComponent {
this.blackjackService.stand(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
this.userService.refreshCurrentUser();
this.isActionInProgress.set(false);
},
error: (error) => {
@ -163,6 +166,7 @@ export default class BlackjackComponent {
this.blackjackService.doubleDown(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
this.userService.refreshCurrentUser();
this.isActionInProgress.set(false);
},
error: (error) => {

View file

@ -18,10 +18,6 @@ import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angula
<div class="card p-4">
<h3 class="section-heading text-xl mb-4">Spiel Informationen</h3>
<div class="space-y-4">
<div class="flex justify-between items-center">
<span class="text-text-secondary">Guthaben:</span>
<span class="text-emerald">{{ balance | currency: 'EUR' }}</span>
</div>
<div class="flex justify-between items-center">
<span class="text-text-secondary">Aktuelle Wette:</span>
<span [class]="currentBet > 0 ? 'text-accent-red' : 'text-text-secondary'">

View file

@ -86,7 +86,7 @@ export class GameResultComponent {
visible = false;
get isWin(): boolean {
return this.gameState === GameState.PLAYER_WON;
return this.gameState === GameState.PLAYER_WON || this.gameState === GameState.PLAYER_BLACKJACK;
}
get isLoss(): boolean {
@ -98,6 +98,7 @@ export class GameResultComponent {
}
getResultTitle(): string {
if (this.gameState === GameState.PLAYER_BLACKJACK) return 'Blackjack!';
if (this.isWin) return 'Gewonnen!';
if (this.isLoss) return 'Verloren!';
if (this.isDraw) return 'Unentschieden!';
@ -105,6 +106,7 @@ export class GameResultComponent {
}
getResultMessage(): string {
if (this.gameState === GameState.PLAYER_BLACKJACK) return 'Glückwunsch! Du hast mit einem Blackjack gewonnen!';
if (this.isWin) return 'Glückwunsch! Du hast diese Runde gewonnen.';
if (this.isLoss) return 'Schade! Du hast diese Runde verloren.';
if (this.isDraw) return 'Diese Runde endet unentschieden. Dein Einsatz wurde zurückgegeben.';
@ -112,6 +114,7 @@ export class GameResultComponent {
}
getResultClass(): string {
if (this.gameState === GameState.PLAYER_BLACKJACK) return 'text-emerald font-bold';
if (this.isWin) return 'text-emerald';
if (this.isLoss) return 'text-accent-red';
if (this.isDraw) return 'text-yellow-400';

View file

@ -3,4 +3,5 @@ export enum GameState {
IN_PROGRESS = 'IN_PROGRESS',
PLAYER_LOST = 'PLAYER_LOST',
DRAW = 'DRAW',
PLAYER_BLACKJACK = 'PLAYER_BLACKJACK',
}