style(blackjack): format code for better readability
This commit is contained in:
parent
acdbea5a99
commit
deac128935
9 changed files with 139 additions and 121 deletions
|
@ -10,7 +10,9 @@ import { Card } from '../../models/blackjack.model';
|
|||
<div class="flex flex-col gap-4">
|
||||
<div class="flex justify-center text-lg mb-5">
|
||||
<div class="card p-4">
|
||||
<div class="text-emerald font-bold mb-1">Deine Punkte: {{ calculateHandValue(playerCards) }}</div>
|
||||
<div class="text-emerald font-bold mb-1">
|
||||
Deine Punkte: {{ calculateHandValue(playerCards) }}
|
||||
</div>
|
||||
<div class="text-text-secondary">
|
||||
Status: <span [class]="getStatusClass(gameState)">{{ getStatusText(gameState) }}</span>
|
||||
</div>
|
||||
|
@ -26,7 +28,9 @@ import { Card } from '../../models/blackjack.model';
|
|||
<span [class.invisible]="isActionInProgress">Ziehen</span>
|
||||
@if (isActionInProgress) {
|
||||
<div class="absolute inset-0 flex items-center justify-center">
|
||||
<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
}
|
||||
</button>
|
||||
|
@ -39,7 +43,9 @@ import { Card } from '../../models/blackjack.model';
|
|||
<span [class.invisible]="isActionInProgress">Halten</span>
|
||||
@if (isActionInProgress) {
|
||||
<div class="absolute inset-0 flex items-center justify-center">
|
||||
<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
}
|
||||
</button>
|
||||
|
@ -52,7 +58,9 @@ import { Card } from '../../models/blackjack.model';
|
|||
<span [class.invisible]="isActionInProgress">Verdoppeln</span>
|
||||
@if (isActionInProgress) {
|
||||
<div class="absolute inset-0 flex items-center justify-center">
|
||||
<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"
|
||||
></div>
|
||||
</div>
|
||||
}
|
||||
</button>
|
||||
|
@ -71,9 +79,9 @@ import { Card } from '../../models/blackjack.model';
|
|||
})
|
||||
export class GameControlsComponent {
|
||||
@Input() playerCards: Card[] = [];
|
||||
@Input() gameState: string = 'IN_PROGRESS';
|
||||
@Input() isActionInProgress: boolean = false;
|
||||
|
||||
@Input() gameState = 'IN_PROGRESS';
|
||||
@Input() isActionInProgress = false;
|
||||
|
||||
@Output() hit = new EventEmitter<void>();
|
||||
@Output() stand = new EventEmitter<void>();
|
||||
@Output() doubleDown = new EventEmitter<void>();
|
||||
|
@ -82,7 +90,7 @@ export class GameControlsComponent {
|
|||
calculateHandValue(cards: Card[]): number {
|
||||
let sum = 0;
|
||||
let aceCount = 0;
|
||||
|
||||
|
||||
const rankValues: Record<string, number> = {
|
||||
TWO: 2,
|
||||
THREE: 3,
|
||||
|
@ -96,9 +104,9 @@ export class GameControlsComponent {
|
|||
JACK: 10,
|
||||
QUEEN: 10,
|
||||
KING: 10,
|
||||
ACE: 11
|
||||
ACE: 11,
|
||||
};
|
||||
|
||||
|
||||
for (const card of cards) {
|
||||
if (!card.hidden) {
|
||||
const value = rankValues[card.rank] || 0;
|
||||
|
@ -108,12 +116,12 @@ export class GameControlsComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while (sum > 21 && aceCount > 0) {
|
||||
sum -= 10;
|
||||
aceCount--;
|
||||
}
|
||||
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue