Compare commits
	
		
			2 Commits
		
	
	
		
			7c3404acb0
			...
			aec84dca5d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| aec84dca5d | |||
| 7082abcdf7 | 
| 
						 | 
				
			
			@ -34,8 +34,8 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
			team: Team.CONTRA,
 | 
			
		||||
			gamePoints: 0,
 | 
			
		||||
			finalCardScore: 0,
 | 
			
		||||
			foxesCaught: 1,
 | 
			
		||||
			wonLastTrickWithCharlie: true
 | 
			
		||||
			// foxesCaught: 1,
 | 
			
		||||
			// wonLastTrickWithCharlie: true
 | 
			
		||||
		});
 | 
			
		||||
		this.potentialPlayers.push({
 | 
			
		||||
			firebonkId: 2,
 | 
			
		||||
| 
						 | 
				
			
			@ -384,17 +384,18 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
	calculateCurrentScores(): void {
 | 
			
		||||
		let gameScore: number = 0;
 | 
			
		||||
 | 
			
		||||
		let winningTeamScore = this.getWinningTeamAndScore().score;
 | 
			
		||||
		let winningTeam = this.getWinningTeamAndScore().team;
 | 
			
		||||
		let unfulfilledAnnouncements = this.checkUnfulfilledAnnouncements(winningTeam, winningTeamScore);
 | 
			
		||||
		let isSoloPlay = false;
 | 
			
		||||
		let winningTeamScore = this.getWinningTeamAndScore().score;
 | 
			
		||||
		let unfulfilledAnnouncementPoints = this.checkUnfulfilledAnnouncements(winningTeam, winningTeamScore);
 | 
			
		||||
		let isSoloPlay = this.checkIfSolo();
 | 
			
		||||
 | 
			
		||||
		// We are going to calculate the points for the winning team and then set all players points accordingly
 | 
			
		||||
 | 
			
		||||
		if(!unfulfilledAnnouncements) {
 | 
			
		||||
		if (unfulfilledAnnouncementPoints === 0) {
 | 
			
		||||
			gameScore += this.calculateNormalScore(winningTeamScore, winningTeam);
 | 
			
		||||
		} else {
 | 
			
		||||
			// TODO method to calculate game score for unfulfilled announcements
 | 
			
		||||
			gameScore += unfulfilledAnnouncementPoints;
 | 
			
		||||
			winningTeam = winningTeam === Team.RE ? Team.CONTRA : Team.RE;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Double Score in case of announcement
 | 
			
		||||
| 
						 | 
				
			
			@ -406,15 +407,20 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		// Bonus points
 | 
			
		||||
		if(!isSoloPlay) {
 | 
			
		||||
		if (!isSoloPlay) {
 | 
			
		||||
			gameScore += this.getFinalFoxPoints(winningTeam);
 | 
			
		||||
			gameScore += this.getCharliePoints(winningTeam);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// TODO: Game score in case of a solo
 | 
			
		||||
		this.setGameScores(gameScore, winningTeam);
 | 
			
		||||
		this.setGameScores(gameScore, winningTeam, isSoloPlay);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Calculate the score according to card points and announcements in case of a "normal" game, so without unfulfilled announcements
 | 
			
		||||
	 * @param winningTeamScore
 | 
			
		||||
	 * @param winningTeam
 | 
			
		||||
	 * @private
 | 
			
		||||
	 */
 | 
			
		||||
	private calculateNormalScore(winningTeamScore: number, winningTeam: Team): number {
 | 
			
		||||
		let gameScore = 1; // 1 Point for Winning
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -502,10 +508,14 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
	 * @param score The score to set
 | 
			
		||||
	 * @param winningTeam The team that won
 | 
			
		||||
	 */
 | 
			
		||||
	setGameScores(score: number, winningTeam: Team) {
 | 
			
		||||
	setGameScores(score: number, winningTeam: Team, isSolo: boolean) {
 | 
			
		||||
		for (let player of this.actualPlayers) {
 | 
			
		||||
			if (player.team === winningTeam) {
 | 
			
		||||
				if(isSolo) {
 | 
			
		||||
					player.gamePoints = score * 3;
 | 
			
		||||
				} else {
 | 
			
		||||
					player.gamePoints = score;
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				player.gamePoints = -score;
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -557,8 +567,8 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
	 * @param winningTeam The winning team
 | 
			
		||||
	 */
 | 
			
		||||
	getCharliePoints(winningTeam: Team): number {
 | 
			
		||||
		for(let player of this.actualPlayers) {
 | 
			
		||||
			if(player.wonLastTrickWithCharlie) {
 | 
			
		||||
		for (let player of this.actualPlayers) {
 | 
			
		||||
			if (player.wonLastTrickWithCharlie) {
 | 
			
		||||
				return player.team === winningTeam ? 1 : -1;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -566,34 +576,60 @@ export class AddGameComponent implements OnInit {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Checks if the winning team has made announcements that have not been fulfilled
 | 
			
		||||
	 * Checks if the winning team has made announcements that have not been fulfilled.
 | 
			
		||||
	 * If so, returns the points that the "losing" team gets for these unfulfilled announcements
 | 
			
		||||
	 * @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;
 | 
			
		||||
	checkUnfulfilledAnnouncements(normalWinningTeam: Team, normalWinningTeamScore: number): number {
 | 
			
		||||
		let gamePoints = 0;
 | 
			
		||||
 | 
			
		||||
		if (normalWinningTeam === Team.RE) {
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_NINETY) && normalWinningTeamScore < 151) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.checkAnnouncementActive(announcements.Announcement.RE_NO_SIXTY) && normalWinningTeamScore < 181) {
 | 
			
		||||
				return true;
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_SIXTY) && normalWinningTeamScore < 181) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.checkAnnouncementActive(announcements.Announcement.RE_NO_THIRTY) && normalWinningTeamScore < 211) {
 | 
			
		||||
				return true;
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_THIRTY) && normalWinningTeamScore < 211) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if(normalWinningTeam === Team.CONTRA) {
 | 
			
		||||
			if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_NINETY) && normalWinningTeamScore < 151) {
 | 
			
		||||
				return true;
 | 
			
		||||
		if (normalWinningTeam === Team.CONTRA) {
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_NINETY) && normalWinningTeamScore < 151) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_SIXTY) && normalWinningTeamScore < 181) {
 | 
			
		||||
				return true;
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_SIXTY) && normalWinningTeamScore < 181) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_THIRTY) && normalWinningTeamScore < 211) {
 | 
			
		||||
				return true;
 | 
			
		||||
			if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_THIRTY) && normalWinningTeamScore < 211) {
 | 
			
		||||
				gamePoints++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
		return gamePoints;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *    _____       __
 | 
			
		||||
	 *   / ___/____  / /___
 | 
			
		||||
	 *   \__ \/ __ \/ / __ \
 | 
			
		||||
	 *  ___/ / /_/ / / /_/ /
 | 
			
		||||
	 * /____/\____/_/\____/
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Checks, according to the assigned Teams, if this is a solo play
 | 
			
		||||
	 */
 | 
			
		||||
	checkIfSolo(): boolean {
 | 
			
		||||
		let numberOfElders: number = 0;
 | 
			
		||||
 | 
			
		||||
		for(let player of this.actualPlayers) {
 | 
			
		||||
			if(player.team === Team.RE) {
 | 
			
		||||
				numberOfElders++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return numberOfElders === 1;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user