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; + } }