From cd5154a07aacdaed4acc200d1b658ebd2ef884ea Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Sat, 10 Sep 2022 22:36:21 +0200 Subject: [PATCH] Add text that tells the players exactly why the total points are wrong --- .../add-game/add-game.component.html | 4 ++-- .../components/add-game/add-game.component.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/components/add-game/add-game.component.html b/src/app/components/add-game/add-game.component.html index 1d7b720..7c07c7e 100644 --- a/src/app/components/add-game/add-game.component.html +++ b/src/app/components/add-game/add-game.component.html @@ -43,8 +43,8 @@ -

Total score doesn't add up!

- +

Total score doesn't add up ({{getScoreDifferenceText()}})

+
diff --git a/src/app/components/add-game/add-game.component.ts b/src/app/components/add-game/add-game.component.ts index 079d0e3..fe528e0 100644 --- a/src/app/components/add-game/add-game.component.ts +++ b/src/app/components/add-game/add-game.component.ts @@ -218,13 +218,27 @@ export class AddGameComponent implements OnInit { /** * Checks if the sum of all points is exactly 240 */ - totalScoreValid(): boolean { + calculatePointSum(): number { let totalScore: number = 0; for (let player of this.actualPlayers) { totalScore += player.finalCardScore ?? 0; } - return totalScore === 240; + return totalScore; + } + + /** + * Generates a string that explains if the total point sum is too low / too high + */ + getScoreDifferenceText(): string { + let difference = this.calculatePointSum() - 240; + + if(difference > 0) { + return difference + ' more than expected'; + } else { + difference *= -1; + return difference + ' less than expected'; + } } /**