Refactor point calculation so we can add an additional method in case of unfulfilled annoumcements
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-09-16 10:01:50 +02:00
parent e8165727de
commit 7c3404acb0
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE

View File

@ -34,7 +34,8 @@ export class AddGameComponent implements OnInit {
team: Team.CONTRA, team: Team.CONTRA,
gamePoints: 0, gamePoints: 0,
finalCardScore: 0, finalCardScore: 0,
foxesCaught: 1 foxesCaught: 1,
wonLastTrickWithCharlie: true
}); });
this.potentialPlayers.push({ this.potentialPlayers.push({
firebonkId: 2, firebonkId: 2,
@ -382,12 +383,40 @@ export class AddGameComponent implements OnInit {
*/ */
calculateCurrentScores(): void { calculateCurrentScores(): void {
let gameScore: number = 0; let gameScore: number = 0;
let winningTeamScore = this.getWinningTeamAndScore().score; let winningTeamScore = this.getWinningTeamAndScore().score;
let winningTeam = this.getWinningTeamAndScore().team; let winningTeam = this.getWinningTeamAndScore().team;
let unfulfilledAnnouncements = this.checkUnfulfilledAnnouncements(winningTeam, winningTeamScore);
let isSoloPlay = false;
// We are going to calculate the points for the winning team and then set all players points accordingly // We are going to calculate the points for the winning team and then set all players points accordingly
gameScore = 1; // 1 Point for Winning if(!unfulfilledAnnouncements) {
gameScore += this.calculateNormalScore(winningTeamScore, winningTeam);
} else {
// TODO method to calculate game score for unfulfilled announcements
}
// Double Score in case of announcement
if (this.checkAnnouncementActive(announcements.Announcement.RE)) {
gameScore *= 2;
}
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA)) {
gameScore *= 2;
}
// Bonus points
if(!isSoloPlay) {
gameScore += this.getFinalFoxPoints(winningTeam);
gameScore += this.getCharliePoints(winningTeam);
}
// TODO: Game score in case of a solo
this.setGameScores(gameScore, winningTeam);
}
private calculateNormalScore(winningTeamScore: number, winningTeam: Team): number {
let gameScore = 1; // 1 Point for Winning
// Won by how much? // Won by how much?
if (winningTeamScore > 210) { if (winningTeamScore > 210) {
@ -422,21 +451,7 @@ export class AddGameComponent implements OnInit {
} }
} }
// Double Score in case of announcement return gameScore;
if (winningTeam === Team.RE && this.checkAnnouncementActive(announcements.Announcement.RE)) {
gameScore *= 2;
}
if (winningTeam === Team.CONTRA && this.checkAnnouncementActive(announcements.Announcement.CONTRA)) {
gameScore *= 2;
}
// TODO: Bonus points
gameScore += this.getFinalFoxPoints(winningTeam);
gameScore += this.getCharliePoints(winningTeam);
// TODO: Check for announcements that have not been fulfilled!
this.setGameScores(gameScore, winningTeam);
} }
/** /**
@ -549,4 +564,36 @@ export class AddGameComponent implements OnInit {
} }
return 0; return 0;
} }
/**
* Checks if the winning team has made announcements that have not been fulfilled
* @param normalWinningTeam The team that would have won under normal circumstances
* @param normalWinningTeamScore The card score of said team
*/
checkUnfulfilledAnnouncements(normalWinningTeam: Team, normalWinningTeamScore: number): boolean {
if(normalWinningTeam === Team.RE) {
if(this.checkAnnouncementActive(announcements.Announcement.RE_NO_NINETY) && normalWinningTeamScore < 151) {
return true;
}
if(this.checkAnnouncementActive(announcements.Announcement.RE_NO_SIXTY) && normalWinningTeamScore < 181) {
return true;
}
if(this.checkAnnouncementActive(announcements.Announcement.RE_NO_THIRTY) && normalWinningTeamScore < 211) {
return true;
}
}
if(normalWinningTeam === Team.CONTRA) {
if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_NINETY) && normalWinningTeamScore < 151) {
return true;
}
if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_SIXTY) && normalWinningTeamScore < 181) {
return true;
}
if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_THIRTY) && normalWinningTeamScore < 211) {
return true;
}
}
return false;
}
} }