feat: 1vs BOT

This commit is contained in:
shahdlala66
2026-04-19 01:06:13 +02:00
parent 5497997455
commit bc644c16e3
5 changed files with 201 additions and 4 deletions
@@ -15,6 +15,7 @@ import { GameApiService } from '../../services/game-api.service';
export class WelcomeComponent {
creating = false;
errorMessage = '';
showDifficultySelector = false;
constructor(
private readonly router: Router,
@@ -41,4 +42,31 @@ export class WelcomeComponent {
}
});
}
startVsBot(difficulty: 'easy' | 'medium' | 'hard'): void {
if (this.creating) {
return;
}
this.errorMessage = '';
this.creating = true;
this.showDifficultySelector = false;
this.gameApi
.createGameVsBot(difficulty)
.pipe(finalize(() => (this.creating = false)))
.subscribe({
next: (game) => {
void this.router.navigate(['/game', game.gameId]);
},
error: (error) => {
this.errorMessage = getErrorMessage(error, 'Unable to create a game against bot.');
}
});
}
toggleDifficultySelector(): void {
this.showDifficultySelector = !this.showDifficultySelector;
this.errorMessage = '';
}
}