feat(blackjack): add split functionality to the game
All checks were successful
All checks were successful
This commit is contained in:
parent
4a7c54eab8
commit
3ef5530e77
7 changed files with 410 additions and 276 deletions
|
@ -0,0 +1,31 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BettingService {
|
||||
constructor(private fb: FormBuilder) {}
|
||||
|
||||
createBetForm(): FormGroup {
|
||||
return this.fb.group({
|
||||
bet: ['', [Validators.required, Validators.min(1)]],
|
||||
});
|
||||
}
|
||||
|
||||
updateBetFormValidators(form: FormGroup, balance: number): void {
|
||||
form.reset();
|
||||
form
|
||||
.get('bet')
|
||||
?.setValidators([Validators.required, Validators.min(1), Validators.max(balance)]);
|
||||
form.get('bet')?.updateValueAndValidity();
|
||||
}
|
||||
|
||||
calculateBetAmount(balance: number, percentage: number): number {
|
||||
return Math.floor(balance * percentage * 100) / 100;
|
||||
}
|
||||
|
||||
isValidBet(betAmount: number, balance: number): boolean {
|
||||
return betAmount >= 1 && betAmount <= balance;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue