From 6d2c750a58bfe261eb69f94201007890617ce20d Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Thu, 15 Sep 2022 13:41:08 +0200 Subject: [PATCH] Adding fox points to calculation --- .../components/add-game/add-game.component.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/app/components/add-game/add-game.component.ts b/src/app/components/add-game/add-game.component.ts index a7a7e17..6f7d7cb 100644 --- a/src/app/components/add-game/add-game.component.ts +++ b/src/app/components/add-game/add-game.component.ts @@ -33,7 +33,8 @@ export class AddGameComponent implements OnInit { firstName: 'Patrick', team: Team.CONTRA, gamePoints: 0, - finalCardScore: 0 + finalCardScore: 0, + foxesCaught: 1 }); this.potentialPlayers.push({ firebonkId: 2, @@ -430,6 +431,7 @@ export class AddGameComponent implements OnInit { } // TODO: Bonus points + gameScore += this.getFinalFoxPoints(winningTeam); // TODO: Check for announcements that have not been fulfilled! @@ -493,4 +495,43 @@ export class AddGameComponent implements OnInit { } } } + + /** + * Calculates the points that each team got by catching foxes + */ + calculateFoxPoints(): { re: number, contra: number } { + let reFoxesCaught: number = 0; + let contraFoxesCaught: number = 0; + + for(let player of this.actualPlayers) { + if(player.team === Team.RE) { + reFoxesCaught += player.foxesCaught ?? 0; + } else { + contraFoxesCaught += player.foxesCaught ?? 0; + } + } + + return { + re: reFoxesCaught, + contra: contraFoxesCaught + }; + } + + /** + * Calculates the final fox points for the winning team + * @param winningTeam The winning team + */ + getFinalFoxPoints(winningTeam: Team): number { + let finalPoints = 0; + + if(winningTeam === Team.RE) { + finalPoints += this.calculateFoxPoints().re; + finalPoints -= this.calculateFoxPoints().contra; + } else { + finalPoints += this.calculateFoxPoints().contra; + finalPoints -= this.calculateFoxPoints().re; + } + + return finalPoints; + } }