Compare commits
4 Commits
e41a07411e
...
6d2c750a58
Author | SHA1 | Date | |
---|---|---|---|
6d2c750a58 | |||
7f436ae0b8 | |||
753e490c29 | |||
051657ef65 |
|
@ -28,19 +28,19 @@
|
||||||
<table class="point-entry">
|
<table class="point-entry">
|
||||||
<tr *ngIf="this.actualPlayers[0]">
|
<tr *ngIf="this.actualPlayers[0]">
|
||||||
<td><p>{{this.actualPlayers[0].firstName}}</p></td>
|
<td><p>{{this.actualPlayers[0].firstName}}</p></td>
|
||||||
<td><input type="number" [(ngModel)]="this.actualPlayers[0].finalCardScore"/></td>
|
<td><input type="number" [(ngModel)]="this.actualPlayers[0].finalCardScore" (change)="this.calculateCurrentScores()"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr *ngIf="this.actualPlayers[1]">
|
<tr *ngIf="this.actualPlayers[1]">
|
||||||
<td><p>{{this.actualPlayers[1].firstName}}</p></td>
|
<td><p>{{this.actualPlayers[1].firstName}}</p></td>
|
||||||
<td><input type="number" [(ngModel)]="this.actualPlayers[1].finalCardScore"/></td>
|
<td><input type="number" [(ngModel)]="this.actualPlayers[1].finalCardScore" (change)="this.calculateCurrentScores()"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr *ngIf="this.actualPlayers[2]">
|
<tr *ngIf="this.actualPlayers[2]">
|
||||||
<td><p>{{this.actualPlayers[2].firstName}}</p></td>
|
<td><p>{{this.actualPlayers[2].firstName}}</p></td>
|
||||||
<td><input type="number" [(ngModel)]="this.actualPlayers[2].finalCardScore"/></td>
|
<td><input type="number" [(ngModel)]="this.actualPlayers[2].finalCardScore" (change)="this.calculateCurrentScores()"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr *ngIf="this.actualPlayers[3]">
|
<tr *ngIf="this.actualPlayers[3]">
|
||||||
<td><p>{{this.actualPlayers[3].firstName}}</p></td>
|
<td><p>{{this.actualPlayers[3].firstName}}</p></td>
|
||||||
<td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore"/></td>
|
<td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore" (change)="this.calculateCurrentScores()"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<p id="score-warn" *ngIf="calculatePointSum() !== 240">Total score doesn't add up ({{getScoreDifferenceText()}})</p>
|
<p id="score-warn" *ngIf="calculatePointSum() !== 240">Total score doesn't add up ({{getScoreDifferenceText()}})</p>
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="scores">
|
<div id="scores">
|
||||||
<p class="team-{{player.team}}" *ngFor="let player of actualPlayers">
|
<p class="team-{{player.team}}" *ngFor="let player of actualPlayers">
|
||||||
{{player.firstName}}: {{calculateCurrentScore(player)}}
|
{{player.firstName}}: {{player.gamePoints}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -31,31 +31,42 @@ export class AddGameComponent implements OnInit {
|
||||||
firebonkId: 1,
|
firebonkId: 1,
|
||||||
uuid: 'abc-def-ghi-j',
|
uuid: 'abc-def-ghi-j',
|
||||||
firstName: 'Patrick',
|
firstName: 'Patrick',
|
||||||
team: Team.CONTRA
|
team: Team.CONTRA,
|
||||||
|
gamePoints: 0,
|
||||||
|
finalCardScore: 0,
|
||||||
|
foxesCaught: 1
|
||||||
});
|
});
|
||||||
this.potentialPlayers.push({
|
this.potentialPlayers.push({
|
||||||
firebonkId: 2,
|
firebonkId: 2,
|
||||||
uuid: 'abc-def-ghi-k',
|
uuid: 'abc-def-ghi-k',
|
||||||
firstName: 'Julian',
|
firstName: 'Julian',
|
||||||
team: Team.CONTRA
|
team: Team.CONTRA,
|
||||||
|
gamePoints: 0,
|
||||||
|
finalCardScore: 0
|
||||||
});
|
});
|
||||||
this.potentialPlayers.push({
|
this.potentialPlayers.push({
|
||||||
firebonkId: 3,
|
firebonkId: 3,
|
||||||
uuid: 'abc-def-ghi-l',
|
uuid: 'abc-def-ghi-l',
|
||||||
firstName: 'Yannick',
|
firstName: 'Yannick',
|
||||||
team: Team.CONTRA
|
team: Team.CONTRA,
|
||||||
|
gamePoints: 0,
|
||||||
|
finalCardScore: 0
|
||||||
});
|
});
|
||||||
this.potentialPlayers.push({
|
this.potentialPlayers.push({
|
||||||
firebonkId: 4,
|
firebonkId: 4,
|
||||||
uuid: 'abc-def-ghi-m',
|
uuid: 'abc-def-ghi-m',
|
||||||
firstName: 'Janina',
|
firstName: 'Janina',
|
||||||
team: Team.CONTRA
|
team: Team.CONTRA,
|
||||||
|
gamePoints: 0,
|
||||||
|
finalCardScore: 0
|
||||||
});
|
});
|
||||||
this.potentialPlayers.push({
|
this.potentialPlayers.push({
|
||||||
firebonkId: 5,
|
firebonkId: 5,
|
||||||
uuid: 'abc-def-ghi-n',
|
uuid: 'abc-def-ghi-n',
|
||||||
firstName: 'Moritz',
|
firstName: 'Moritz',
|
||||||
team: Team.CONTRA
|
team: Team.CONTRA,
|
||||||
|
gamePoints: 0,
|
||||||
|
finalCardScore: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
this.actualPlayers.push(...this.potentialPlayers.slice(0, 4));
|
this.actualPlayers.push(...this.potentialPlayers.slice(0, 4));
|
||||||
|
@ -65,6 +76,10 @@ export class AddGameComponent implements OnInit {
|
||||||
* Switches the entry mask UI to the next page
|
* Switches the entry mask UI to the next page
|
||||||
*/
|
*/
|
||||||
switchToNextPage(): void {
|
switchToNextPage(): void {
|
||||||
|
if (this.currentPage >= 4) {
|
||||||
|
this.calculateCurrentScores();
|
||||||
|
}
|
||||||
|
|
||||||
this.currentPage++;
|
this.currentPage++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,10 +277,22 @@ export class AddGameComponent implements OnInit {
|
||||||
return announcements.checkValidity(this.selectedAnnouncements);
|
return announcements.checkValidity(this.selectedAnnouncements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the two highest announcements for this game (one for RE, one for CONTRA, if applicable)
|
||||||
|
*/
|
||||||
getHighestAnnouncements(): string {
|
getHighestAnnouncements(): string {
|
||||||
return announcements.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
return announcements.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given announcement has been selected
|
||||||
|
* @param announcement The announcement to check
|
||||||
|
*/
|
||||||
|
checkAnnouncementActive(announcement: announcements.Announcement): boolean {
|
||||||
|
let index = this.selectedAnnouncements.indexOf(announcement);
|
||||||
|
return index !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ______
|
* ______
|
||||||
* /_ __/__ ____ _____ ___ _____
|
* /_ __/__ ____ _____ ___ _____
|
||||||
|
@ -351,35 +378,64 @@ export class AddGameComponent implements OnInit {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the game points for the given player
|
* Calculates the game points for all players
|
||||||
* @param player The player to calculate points for
|
|
||||||
*/
|
*/
|
||||||
calculateCurrentScore(player: Player): number {
|
calculateCurrentScores(): void {
|
||||||
let gameScore: number = 0;
|
let gameScore: number = 0;
|
||||||
let teamScore = this.getTeamScore(player);
|
let winningTeamScore = this.getWinningTeamAndScore().score;
|
||||||
|
let winningTeam = this.getWinningTeamAndScore().team;
|
||||||
|
|
||||||
// Won? If so, by how much?
|
// We are going to calculate the points for the winning team and then set all players points accordingly
|
||||||
if (teamScore > 210) {
|
|
||||||
gameScore += 4;
|
gameScore = 1; // 1 Point for Winning
|
||||||
} else if (teamScore > 180) {
|
|
||||||
|
// Won by how much?
|
||||||
|
if (winningTeamScore > 210) {
|
||||||
gameScore += 3;
|
gameScore += 3;
|
||||||
} else if (teamScore > 150) {
|
} else if (winningTeamScore > 180) {
|
||||||
gameScore += 2;
|
gameScore += 2;
|
||||||
} else if (teamScore > 120) {
|
} else if (winningTeamScore > 150) {
|
||||||
gameScore += 1;
|
gameScore += 1;
|
||||||
} else if (teamScore < 30) {
|
|
||||||
gameScore -= 4;
|
|
||||||
} else if (teamScore < 60) {
|
|
||||||
gameScore -= 3;
|
|
||||||
} else if (teamScore < 90) {
|
|
||||||
gameScore -= 2;
|
|
||||||
} else {
|
|
||||||
gameScore -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Announcements etc
|
// Announcements
|
||||||
|
if (winningTeam === Team.RE) {
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_NINETY) && winningTeamScore > 150) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_SIXTY) && winningTeamScore > 180) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_THIRTY) && winningTeamScore > 210) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (winningTeam === Team.CONTRA) {
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_NINETY) && winningTeamScore > 150) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_SIXTY) && winningTeamScore > 180) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_THIRTY) && winningTeamScore > 210) {
|
||||||
|
gameScore += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return gameScore;
|
// Double Score in case of announcement
|
||||||
|
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);
|
||||||
|
|
||||||
|
// TODO: Check for announcements that have not been fulfilled!
|
||||||
|
|
||||||
|
this.setGameScores(gameScore, winningTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -397,4 +453,85 @@ export class AddGameComponent implements OnInit {
|
||||||
|
|
||||||
return totalTeamScore;
|
return totalTeamScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates which team won and returns the Team Name and the achieved score
|
||||||
|
*/
|
||||||
|
getWinningTeamAndScore(): { team: Team, score: number } {
|
||||||
|
let elderPoints: number = 0;
|
||||||
|
let otherPoints: number = 0;
|
||||||
|
|
||||||
|
for (let player of this.actualPlayers) {
|
||||||
|
if (player.team === Team.RE) {
|
||||||
|
elderPoints += player.finalCardScore ?? 0;
|
||||||
|
} else {
|
||||||
|
otherPoints += player.finalCardScore ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elderPoints > otherPoints) {
|
||||||
|
return {
|
||||||
|
team: Team.RE,
|
||||||
|
score: elderPoints
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
team: Team.CONTRA,
|
||||||
|
score: otherPoints
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the game scores for all players
|
||||||
|
* @param score The score to set
|
||||||
|
* @param winningTeam The team that won
|
||||||
|
*/
|
||||||
|
setGameScores(score: number, winningTeam: Team) {
|
||||||
|
for (let player of this.actualPlayers) {
|
||||||
|
if (player.team === winningTeam) {
|
||||||
|
player.gamePoints = score;
|
||||||
|
} else {
|
||||||
|
player.gamePoints = -score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,12 @@ export enum Announcement {
|
||||||
export function getAllAnnouncementValues(): Announcement[] {
|
export function getAllAnnouncementValues(): Announcement[] {
|
||||||
return [
|
return [
|
||||||
Announcement.RE,
|
Announcement.RE,
|
||||||
Announcement.CONTRA,
|
|
||||||
Announcement.RE_NO_NINETY,
|
Announcement.RE_NO_NINETY,
|
||||||
Announcement.CONTRA_NO_NINETY,
|
|
||||||
Announcement.RE_NO_SIXTY,
|
Announcement.RE_NO_SIXTY,
|
||||||
Announcement.CONTRA_NO_SIXTY,
|
|
||||||
Announcement.RE_NO_THIRTY,
|
Announcement.RE_NO_THIRTY,
|
||||||
|
Announcement.CONTRA,
|
||||||
|
Announcement.CONTRA_NO_NINETY,
|
||||||
|
Announcement.CONTRA_NO_SIXTY,
|
||||||
Announcement.CONTRA_NO_THIRTY
|
Announcement.CONTRA_NO_THIRTY
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ export function getAllAnnouncementValues(): Announcement[] {
|
||||||
/**
|
/**
|
||||||
* Checks if the selected announcements are a valid set of announcements.
|
* Checks if the selected announcements are a valid set of announcements.
|
||||||
* E.g.: If RE_NO_NINETY is newly selected, RE also has to be selected
|
* E.g.: If RE_NO_NINETY is newly selected, RE also has to be selected
|
||||||
* @param alreadySelected
|
* @param selectedAnnouncements The list of selected announcements
|
||||||
* @param newSelected
|
|
||||||
*/
|
*/
|
||||||
export function checkValidity(selectedAnnouncements: Announcement[]): boolean {
|
export function checkValidity(selectedAnnouncements: Announcement[]): boolean {
|
||||||
// First check all "RE" Announcements
|
// First check all "RE" Announcements
|
||||||
|
@ -70,6 +69,10 @@ export function checkValidity(selectedAnnouncements: Announcement[]): boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the names of the two highest announcements from the given list, one for RE and one for CONTRA if applicable
|
||||||
|
* @param selectedAnnouncements The list of announcements to check
|
||||||
|
*/
|
||||||
export function returnTwoHighestAnnouncements(selectedAnnouncements: Announcement[]): string {
|
export function returnTwoHighestAnnouncements(selectedAnnouncements: Announcement[]): string {
|
||||||
let finalString: string = '';
|
let finalString: string = '';
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import {Solo} from './enums/solo';
|
||||||
export interface Game {
|
export interface Game {
|
||||||
gameId: number;
|
gameId: number;
|
||||||
players: Player[];
|
players: Player[];
|
||||||
foxesCaught: number;
|
|
||||||
announcements: Announcement[];
|
|
||||||
solo?: Solo;
|
solo?: Solo;
|
||||||
againstTheElders: boolean;
|
againstTheElders: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@ export interface Player {
|
||||||
firebonkId: number;
|
firebonkId: number;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
finalCardScore?: number;
|
finalCardScore: number;
|
||||||
gamePoints?: number;
|
gamePoints: number;
|
||||||
hadMarriage?: boolean;
|
hadMarriage?: boolean;
|
||||||
hadTrumpHandoff?: boolean;
|
hadTrumpHandoff?: boolean;
|
||||||
team?: Team;
|
team?: Team;
|
||||||
|
foxesCaught?: number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user