style(blackjack): format code for better readability

This commit is contained in:
Jan-Marlon Leibl 2025-03-27 15:47:16 +01:00
commit deac128935
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
9 changed files with 139 additions and 121 deletions

View file

@ -42,7 +42,7 @@ export default class BlackjackComponent {
gameInProgress = signal(false);
gameState = signal<string>('IN_PROGRESS');
showGameResult = signal(false);
// Add loading state trackers
isActionInProgress = signal(false);
currentAction = signal<string>('');
@ -66,7 +66,7 @@ export default class BlackjackComponent {
// 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,
@ -85,7 +85,7 @@ export default class BlackjackComponent {
if (isGameOver) {
console.log('Game is over, state:', game.state);
this.refreshUserBalance();
// Show result immediately without resetting first
this.showGameResult.set(true);
console.log('Game result dialog should be shown now');
@ -95,7 +95,7 @@ export default class BlackjackComponent {
onNewGame(bet: number): void {
this.isActionInProgress.set(true);
this.currentAction.set('Spiel wird gestartet...');
this.blackjackService.startGame(bet).subscribe({
next: (game) => {
this.updateGameState(game);
@ -114,7 +114,7 @@ export default class BlackjackComponent {
this.isActionInProgress.set(true);
this.currentAction.set('Karte wird gezogen...');
this.blackjackService.hit(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
@ -130,7 +130,7 @@ export default class BlackjackComponent {
onStand(): void {
if (!this.currentGameId() || this.isActionInProgress()) return;
if (this.gameState() !== 'IN_PROGRESS') {
console.log('Cannot stand: game is not in progress');
return;
@ -138,7 +138,7 @@ export default class BlackjackComponent {
this.isActionInProgress.set(true);
this.currentAction.set('Dealer zieht Karten...');
this.blackjackService.stand(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
@ -154,7 +154,7 @@ export default class BlackjackComponent {
onDoubleDown(): void {
if (!this.currentGameId() || this.isActionInProgress()) return;
if (this.gameState() !== 'IN_PROGRESS' || this.playerCards().length !== 2) {
console.log('Cannot double down: game is not in progress or more than 2 cards');
return;
@ -162,7 +162,7 @@ export default class BlackjackComponent {
this.isActionInProgress.set(true);
this.currentAction.set('Einsatz wird verdoppelt...');
this.blackjackService.doubleDown(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
@ -181,20 +181,19 @@ export default class BlackjackComponent {
this.showGameResult.set(false);
}
private handleGameError(error: any): void {
private handleGameError(error: HttpErrorResponse): void {
if (error instanceof HttpErrorResponse) {
if (error.status === 400 && error.error?.error === 'Invalid state') {
this.gameInProgress.set(false);
this.refreshUserBalance();
}
else if (error.status === 500) {
} else if (error.status === 500) {
console.log('Server error occurred. The game may have been updated in another session.');
this.gameInProgress.set(false);
this.refreshUserBalance();
if (this.currentGameId()) {
this.refreshGameState(this.currentGameId()!);
}
@ -209,7 +208,7 @@ export default class BlackjackComponent {
},
error: (err) => {
console.error('Failed to refresh game state:', err);
}
},
});
}