+
{{ getResultTitle() }}
{{ getResultMessage() }}
-
-
+
+
Einsatz:
{{ amount }} €
-
-
{{ isDraw ? 'Zurückgegeben:' : (isWin ? 'Gewonnen:' : 'Verloren:') }}
-
+ {{ isDraw ? 'Zurückgegeben:' : isWin ? 'Gewonnen:' : 'Verloren:' }}
+
+
{{ isLoss ? '-' : '+' }}{{ amount }} €
-
-
Gesamt:
-
+ Gesamt:
+
+
- {{ isWin ? '+' : (isLoss ? '-' : '') }}{{ amount }} €
+ {{ isWin ? '+' : isLoss ? '-' : '' }}{{ amount }} €
-
-
@@ -67,68 +61,66 @@ import { animate, style, transition, trigger } from '@angular/animations';
trigger('fadeInOut', [
transition(':enter', [
style({ opacity: 0 }),
- animate('150ms ease-out', style({ opacity: 1 }))
+ animate('150ms ease-out', style({ opacity: 1 })),
]),
- transition(':leave', [
- animate('150ms ease-in', style({ opacity: 0 }))
- ])
+ transition(':leave', [animate('150ms ease-in', style({ opacity: 0 }))]),
]),
trigger('cardAnimation', [
transition(':enter', [
style({ opacity: 0, transform: 'scale(0.95)' }),
- animate('200ms ease-out', style({ opacity: 1, transform: 'scale(1)' }))
- ])
- ])
- ]
+ animate('200ms ease-out', style({ opacity: 1, transform: 'scale(1)' })),
+ ]),
+ ]),
+ ],
})
export class GameResultComponent {
- @Input() gameState: string = '';
- @Input() amount: number = 0;
+ @Input() gameState = '';
+ @Input() amount = 0;
@Input() set show(value: boolean) {
console.log('GameResultComponent show input changed:', value, 'gameState:', this.gameState);
this.visible = value;
}
-
- @Output() close = new EventEmitter
();
-
+
+ @Output() gameResultClosed = new EventEmitter();
+
visible = false;
-
+
get isWin(): boolean {
return this.gameState === 'PLAYER_WON';
}
-
+
get isLoss(): boolean {
return this.gameState === 'PLAYER_LOST';
}
-
+
get isDraw(): boolean {
return this.gameState === 'DRAW';
}
-
+
getResultTitle(): string {
if (this.isWin) return 'Gewonnen!';
if (this.isLoss) return 'Verloren!';
if (this.isDraw) return 'Unentschieden!';
return '';
}
-
+
getResultMessage(): string {
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.';
return '';
}
-
+
getResultClass(): string {
if (this.isWin) return 'text-emerald';
if (this.isLoss) return 'text-accent-red';
if (this.isDraw) return 'text-yellow-400';
return '';
}
-
+
closeDialog(): void {
this.visible = false;
- this.close.emit();
+ this.gameResultClosed.emit();
console.log('Dialog closed by user');
}
}
diff --git a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
index 2b27fee..33bf547 100644
--- a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
@@ -37,30 +37,30 @@ import { Card } from '../../models/blackjack.model';
export class PlayerHandComponent implements OnChanges {
@Input() cards: Card[] = [];
cardsWithState: (Card & { isNew: boolean; id: string })[] = [];
-
+
private lastCardCount = 0;
-
+
ngOnChanges(changes: SimpleChanges): void {
if (changes['cards']) {
this.updateCardsWithState();
}
}
-
+
private updateCardsWithState(): void {
const newCards = this.cards.length > this.lastCardCount;
-
+
this.cardsWithState = this.cards.map((card, index) => {
// Consider a card new if it's added after the initial state and is the latest card
const isNew = newCards && index >= this.lastCardCount;
-
+
return {
...card,
isNew,
// Generate a unique ID to help Angular track the cards
- id: `${card.suit}-${card.rank}-${index}`
+ id: `${card.suit}-${card.rank}-${index}`,
};
});
-
+
this.lastCardCount = this.cards.length;
}
}
diff --git a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts
index e006bd4..662ddc6 100644
--- a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts
@@ -1,4 +1,12 @@
-import { ChangeDetectionStrategy, Component, Input, AfterViewInit, ElementRef, OnChanges, SimpleChanges } from '@angular/core';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ Input,
+ AfterViewInit,
+ ElementRef,
+ OnChanges,
+ SimpleChanges,
+} from '@angular/core';
import { CommonModule } from '@angular/common';
import { suitSymbols, Suit } from '../../models/blackjack.model';
import { gsap } from 'gsap';
@@ -14,7 +22,9 @@ import { gsap } from 'gsap';
[class]="hidden ? 'bg-red-800' : 'bg-white'"
>
@if (!hidden) {
- {{ getDisplayRank(rank) }}
+ {{
+ getDisplayRank(rank)
+ }}
}
@if (!hidden) {
}
@if (!hidden) {
- {{
- getDisplayRank(rank)
- }}
+ {{ getDisplayRank(rank) }}
}
`,
- styles: [`
- .card-element {
- transform-style: preserve-3d;
- backface-visibility: hidden;
- }
- `],
+ styles: [
+ `
+ .card-element {
+ transform-style: preserve-3d;
+ backface-visibility: hidden;
+ }
+ `,
+ ],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PlayingCardComponent implements AfterViewInit, OnChanges {
@Input({ required: true }) rank!: string;
@Input({ required: true }) suit!: Suit;
@Input({ required: true }) hidden!: boolean;
- @Input() isNew: boolean = false;
+ @Input() isNew = false;
constructor(private elementRef: ElementRef) {}
@@ -66,31 +80,31 @@ export class PlayingCardComponent implements AfterViewInit, OnChanges {
const cardElement = this.elementRef.nativeElement.querySelector('.card-element');
gsap.fromTo(
cardElement,
- {
- y: -100,
+ {
+ y: -100,
opacity: 0,
rotation: -10,
- scale: 0.7
+ scale: 0.7,
},
- {
- y: 0,
+ {
+ y: 0,
opacity: 1,
rotation: 0,
scale: 1,
- duration: 0.5,
- ease: 'power2.out'
+ duration: 0.5,
+ ease: 'power2.out',
}
);
}
private animateCardFlip(): void {
const cardElement = this.elementRef.nativeElement.querySelector('.card-element');
- gsap.to(cardElement, {
- rotationY: 180,
+ gsap.to(cardElement, {
+ rotationY: 180,
duration: 0.3,
onComplete: () => {
gsap.set(cardElement, { rotationY: 0 });
- }
+ },
});
}
From 05322e3d8309edcb29f8aabcb6b6ac8c72d0ac2a Mon Sep 17 00:00:00 2001
From: Jan-Marlon Leibl
Date: Thu, 27 Mar 2025 15:50:34 +0100
Subject: [PATCH 07/41] refactor(blackjack): remove unnecessary comments and
clean code
---
.../src/app/feature/game/blackjack/blackjack.component.html | 1 -
.../src/app/feature/game/blackjack/blackjack.component.ts | 4 ----
.../blackjack/components/dealer-hand/dealer-hand.component.ts | 2 --
.../blackjack/components/player-hand/player-hand.component.ts | 2 --
4 files changed, 9 deletions(-)
diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.html b/frontend/src/app/feature/game/blackjack/blackjack.component.html
index 1a6b8d3..c47d2f6 100644
--- a/frontend/src/app/feature/game/blackjack/blackjack.component.html
+++ b/frontend/src/app/feature/game/blackjack/blackjack.component.html
@@ -6,7 +6,6 @@
-
@if (isActionInProgress()) {
('IN_PROGRESS');
showGameResult = signal(false);
- // Add loading state trackers
isActionInProgress = signal(false);
currentAction = signal
('');
@@ -64,7 +63,6 @@ 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(
@@ -81,12 +79,10 @@ export default class BlackjackComponent {
}))
);
- // Only refresh and show game result if the game has ended
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');
}
diff --git a/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts b/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts
index 6d77f60..50ff0cf 100644
--- a/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts
@@ -48,13 +48,11 @@ export class DealerHandComponent implements OnChanges {
const newCards = this.cards.length > this.lastCardCount;
this.cardsWithState = this.cards.map((card, index) => {
- // Consider a card new if it's added after the initial state and is the latest card
const isNew = newCards && index >= this.lastCardCount;
return {
...card,
isNew,
- // Generate a unique ID to help Angular track the cards
id: `${card.suit}-${card.rank}-${index}`,
};
});
diff --git a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
index 33bf547..d47114f 100644
--- a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts
@@ -50,13 +50,11 @@ export class PlayerHandComponent implements OnChanges {
const newCards = this.cards.length > this.lastCardCount;
this.cardsWithState = this.cards.map((card, index) => {
- // Consider a card new if it's added after the initial state and is the latest card
const isNew = newCards && index >= this.lastCardCount;
return {
...card,
isNew,
- // Generate a unique ID to help Angular track the cards
id: `${card.suit}-${card.rank}-${index}`,
};
});
From 732d475a8452ea043dce02da30af56a83c17776e Mon Sep 17 00:00:00 2001
From: Jan-Marlon Leibl
Date: Wed, 2 Apr 2025 09:06:44 +0200
Subject: [PATCH 08/41] feat: add game state enum and refactor game components
---
.../casino/blackjack/BlackJackGameEntity.java | 4 -
.../de/szut/casino/blackjack/CardEntity.java | 4 -
frontend/src/app/enum/gameState.ts | 6 ++
.../game/blackjack/blackjack.component.html | 2 +-
.../game/blackjack/blackjack.component.ts | 15 ++--
.../game-controls/game-controls.component.ts | 82 +++----------------
.../game-result/game-result.component.css | 1 -
.../game-result/game-result.component.spec.ts | 22 -----
.../game-result/game-result.component.ts | 10 +--
.../services/game-controls.service.ts | 74 +++++++++++++++++
10 files changed, 105 insertions(+), 115 deletions(-)
create mode 100644 frontend/src/app/enum/gameState.ts
delete mode 100644 frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.css
delete mode 100644 frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.spec.ts
create mode 100644 frontend/src/app/feature/game/blackjack/services/game-controls.service.ts
diff --git a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java
index 0dbfcc0..4f22c9d 100644
--- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java
+++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java
@@ -24,10 +24,6 @@ public class BlackJackGameEntity {
@GeneratedValue
private Long id;
- @Version
- @JsonIgnore
- private Long version;
-
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
@JsonIgnore
diff --git a/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java b/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java
index 27d09d6..5520b58 100644
--- a/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java
+++ b/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java
@@ -19,10 +19,6 @@ public class CardEntity {
@JsonIgnore
private Long id;
- @Version
- @JsonIgnore
- private Long version;
-
@ManyToOne
@JoinColumn(name = "game_id", nullable = false)
@JsonBackReference
diff --git a/frontend/src/app/enum/gameState.ts b/frontend/src/app/enum/gameState.ts
new file mode 100644
index 0000000..b07bf85
--- /dev/null
+++ b/frontend/src/app/enum/gameState.ts
@@ -0,0 +1,6 @@
+export enum GameState {
+ PLAYER_WON = 'PLAYER_WON',
+ IN_PROGRESS = 'IN_PROGRESS',
+ PLAYER_LOST = 'PLAYER_LOST',
+ DRAW = 'DRAW',
+}
\ No newline at end of file
diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.html b/frontend/src/app/feature/game/blackjack/blackjack.component.html
index c47d2f6..887aeeb 100644
--- a/frontend/src/app/feature/game/blackjack/blackjack.component.html
+++ b/frontend/src/app/feature/game/blackjack/blackjack.component.html
@@ -49,5 +49,5 @@
[gameState]="gameState()"
[amount]="currentBet()"
[show]="showGameResult()"
- (close)="onCloseGameResult()"
+ (gameResultClosed)="onCloseGameResult()"
>
diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.ts b/frontend/src/app/feature/game/blackjack/blackjack.component.ts
index 5b5ad42..621cbf5 100644
--- a/frontend/src/app/feature/game/blackjack/blackjack.component.ts
+++ b/frontend/src/app/feature/game/blackjack/blackjack.component.ts
@@ -12,6 +12,7 @@ import { Card, BlackjackGame } from './models/blackjack.model';
import { BlackjackService } from './services/blackjack.service';
import { HttpErrorResponse } from '@angular/common/http';
import { GameResultComponent } from './components/game-result/game-result.component';
+import { GameState } from '../../../enum/gameState';
@Component({
selector: 'app-blackjack',
@@ -40,7 +41,7 @@ export default class BlackjackComponent {
balance = signal(0);
currentGameId = signal(undefined);
gameInProgress = signal(false);
- gameState = signal('IN_PROGRESS');
+ gameState = signal(GameState.IN_PROGRESS);
showGameResult = signal(false);
isActionInProgress = signal(false);
@@ -60,15 +61,15 @@ export default class BlackjackComponent {
console.log('Game state update:', game);
this.currentGameId.set(game.id);
this.currentBet.set(game.bet);
- this.gameInProgress.set(game.state === 'IN_PROGRESS');
- this.gameState.set(game.state);
+ this.gameInProgress.set(game.state === GameState.IN_PROGRESS);
+ this.gameState.set(game.state as GameState);
- const isGameOver = game.state !== 'IN_PROGRESS';
+ const isGameOver = game.state !== GameState.IN_PROGRESS;
this.dealerCards.set(
game.dealerCards.map((card, index) => ({
...card,
- hidden: !isGameOver && index === 1 && game.state === 'IN_PROGRESS',
+ hidden: !isGameOver && index === 1 && game.state === GameState.IN_PROGRESS,
}))
);
@@ -127,7 +128,7 @@ export default class BlackjackComponent {
onStand(): void {
if (!this.currentGameId() || this.isActionInProgress()) return;
- if (this.gameState() !== 'IN_PROGRESS') {
+ if (this.gameState() !== GameState.IN_PROGRESS) {
console.log('Cannot stand: game is not in progress');
return;
}
@@ -151,7 +152,7 @@ export default class BlackjackComponent {
onDoubleDown(): void {
if (!this.currentGameId() || this.isActionInProgress()) return;
- if (this.gameState() !== 'IN_PROGRESS' || this.playerCards().length !== 2) {
+ if (this.gameState() !== GameState.IN_PROGRESS || this.playerCards().length !== 2) {
console.log('Cannot double down: game is not in progress or more than 2 cards');
return;
}
diff --git a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
index 9922309..00a8eca 100644
--- a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
@@ -1,6 +1,8 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Card } from '../../models/blackjack.model';
+import { GameState } from '../../../../../enum/gameState';
+import { GameControlsService } from '../../services/game-controls.service';
@Component({
selector: 'app-game-controls',
@@ -11,10 +13,10 @@ import { Card } from '../../models/blackjack.model';
- Deine Punkte: {{ calculateHandValue(playerCards) }}
+ Deine Punkte: {{ gameControlsService.calculateHandValue(playerCards) }}
- Status: {{ getStatusText(gameState) }}
+ Status: {{ gameControlsService.getStatusText(gameState) }}
@@ -22,7 +24,7 @@ import { Card } from '../../models/blackjack.model';
Ziehen
@@ -37,7 +39,7 @@ import { Card } from '../../models/blackjack.model';
Halten
@@ -52,7 +54,7 @@ import { Card } from '../../models/blackjack.model';
Verdoppeln
@@ -79,77 +81,15 @@ import { Card } from '../../models/blackjack.model';
})
export class GameControlsComponent {
@Input() playerCards: Card[] = [];
- @Input() gameState = 'IN_PROGRESS';
- @Input() isActionInProgress = false;
+ @Input() gameState: GameState = GameState.IN_PROGRESS;
+ @Input() isActionInProgress: boolean = false;
@Output() hit = new EventEmitter();
@Output() stand = new EventEmitter();
@Output() doubleDown = new EventEmitter();
@Output() leave = new EventEmitter();
- calculateHandValue(cards: Card[]): number {
- let sum = 0;
- let aceCount = 0;
+ protected readonly GameState = GameState;
- const rankValues: Record = {
- TWO: 2,
- THREE: 3,
- FOUR: 4,
- FIVE: 5,
- SIX: 6,
- SEVEN: 7,
- EIGHT: 8,
- NINE: 9,
- TEN: 10,
- JACK: 10,
- QUEEN: 10,
- KING: 10,
- ACE: 11,
- };
-
- for (const card of cards) {
- if (!card.hidden) {
- const value = rankValues[card.rank] || 0;
- sum += value;
- if (card.rank === 'ACE') {
- aceCount++;
- }
- }
- }
-
- while (sum > 21 && aceCount > 0) {
- sum -= 10;
- aceCount--;
- }
-
- return sum;
- }
-
- getStatusText(state: string): string {
- switch (state) {
- case 'IN_PROGRESS':
- return 'Spiel läuft';
- case 'PLAYER_WON':
- return 'Gewonnen!';
- case 'PLAYER_LOST':
- return 'Verloren!';
- case 'DRAW':
- return 'Unentschieden!';
- default:
- return state;
- }
- }
-
- getStatusClass(state: string): string {
- switch (state) {
- case 'PLAYER_WON':
- return 'text-emerald';
- case 'PLAYER_LOST':
- return 'text-accent-red';
- case 'DRAW':
- return 'text-yellow-400';
- default:
- return 'text-white';
- }
- }
+ constructor(protected gameControlsService: GameControlsService) {}
}
diff --git a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.css b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.css
deleted file mode 100644
index 5c8977f..0000000
--- a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.css
+++ /dev/null
@@ -1 +0,0 @@
-/* No custom styles needed */
diff --git a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.spec.ts b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.spec.ts
deleted file mode 100644
index 81ac70d..0000000
--- a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.spec.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-
-import { GameResultComponent } from './game-result.component';
-
-describe('GameResultComponent', () => {
- let component: GameResultComponent;
- let fixture: ComponentFixture;
-
- beforeEach(async () => {
- await TestBed.configureTestingModule({
- imports: [GameResultComponent],
- }).compileComponents();
-
- fixture = TestBed.createComponent(GameResultComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
diff --git a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts
index e84a7ce..4b63e59 100644
--- a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts
@@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, Input, Output, EventEmitter } from '@angular/core';
import { CommonModule, CurrencyPipe } from '@angular/common';
import { animate, style, transition, trigger } from '@angular/animations';
+import { GameState } from '../../../../../enum/gameState';
@Component({
selector: 'app-game-result',
@@ -55,7 +56,6 @@ import { animate, style, transition, trigger } from '@angular/animations';
`,
- styleUrls: ['./game-result.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('fadeInOut', [
@@ -74,7 +74,7 @@ import { animate, style, transition, trigger } from '@angular/animations';
],
})
export class GameResultComponent {
- @Input() gameState = '';
+ @Input() gameState: GameState = GameState.IN_PROGRESS;
@Input() amount = 0;
@Input() set show(value: boolean) {
console.log('GameResultComponent show input changed:', value, 'gameState:', this.gameState);
@@ -86,15 +86,15 @@ export class GameResultComponent {
visible = false;
get isWin(): boolean {
- return this.gameState === 'PLAYER_WON';
+ return this.gameState === GameState.PLAYER_WON;
}
get isLoss(): boolean {
- return this.gameState === 'PLAYER_LOST';
+ return this.gameState === GameState.PLAYER_LOST;
}
get isDraw(): boolean {
- return this.gameState === 'DRAW';
+ return this.gameState === GameState.DRAW;
}
getResultTitle(): string {
diff --git a/frontend/src/app/feature/game/blackjack/services/game-controls.service.ts b/frontend/src/app/feature/game/blackjack/services/game-controls.service.ts
new file mode 100644
index 0000000..ecd294d
--- /dev/null
+++ b/frontend/src/app/feature/game/blackjack/services/game-controls.service.ts
@@ -0,0 +1,74 @@
+import { Injectable } from '@angular/core';
+import { Card } from '../models/blackjack.model';
+import { GameState } from '../../../../enum/gameState';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class GameControlsService {
+ calculateHandValue(cards: Card[]): number {
+ let sum = 0;
+ let aceCount = 0;
+
+ const rankValues: Record = {
+ TWO: 2,
+ THREE: 3,
+ FOUR: 4,
+ FIVE: 5,
+ SIX: 6,
+ SEVEN: 7,
+ EIGHT: 8,
+ NINE: 9,
+ TEN: 10,
+ JACK: 10,
+ QUEEN: 10,
+ KING: 10,
+ ACE: 11,
+ };
+
+ for (const card of cards) {
+ if (!card.hidden) {
+ const value = rankValues[card.rank] || 0;
+ sum += value;
+ if (card.rank === 'ACE') {
+ aceCount++;
+ }
+ }
+ }
+
+ while (sum > 21 && aceCount > 0) {
+ sum -= 10;
+ aceCount--;
+ }
+
+ return sum;
+ }
+
+ getStatusText(state: GameState): string {
+ switch (state) {
+ case GameState.IN_PROGRESS:
+ return 'Spiel läuft';
+ case GameState.PLAYER_WON:
+ return 'Gewonnen!';
+ case GameState.PLAYER_LOST:
+ return 'Verloren!';
+ case GameState.DRAW:
+ return 'Unentschieden!';
+ default:
+ return state;
+ }
+ }
+
+ getStatusClass(state: GameState): string {
+ switch (state) {
+ case GameState.PLAYER_WON:
+ return 'text-emerald';
+ case GameState.PLAYER_LOST:
+ return 'text-accent-red';
+ case GameState.DRAW:
+ return 'text-yellow-400';
+ default:
+ return 'text-white';
+ }
+ }
+}
\ No newline at end of file
From f1c70f5f2c4d1809fdb45fbfdf3a4f75f6acd2bd Mon Sep 17 00:00:00 2001
From: Jan-Marlon Leibl
Date: Wed, 2 Apr 2025 09:08:04 +0200
Subject: [PATCH 09/41] style: format code and add missing newlines
---
frontend/src/app/enum/gameState.ts | 2 +-
.../game-controls/game-controls.component.ts | 11 ++++++++---
.../game/blackjack/services/game-controls.service.ts | 4 ++--
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/frontend/src/app/enum/gameState.ts b/frontend/src/app/enum/gameState.ts
index b07bf85..69e3ddf 100644
--- a/frontend/src/app/enum/gameState.ts
+++ b/frontend/src/app/enum/gameState.ts
@@ -3,4 +3,4 @@ export enum GameState {
IN_PROGRESS = 'IN_PROGRESS',
PLAYER_LOST = 'PLAYER_LOST',
DRAW = 'DRAW',
-}
\ No newline at end of file
+}
diff --git a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
index 00a8eca..7572376 100644
--- a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
@@ -16,7 +16,10 @@ import { GameControlsService } from '../../services/game-controls.service';
Deine Punkte: {{ gameControlsService.calculateHandValue(playerCards) }}