diff --git a/src/app/components/add-game/add-game.component.html b/src/app/components/add-game/add-game.component.html index 5b48448..5ec16b8 100644 --- a/src/app/components/add-game/add-game.component.html +++ b/src/app/components/add-game/add-game.component.html @@ -9,13 +9,19 @@
+

Players: {{getPlayerNamesAsString()}}

Select the announcements for this game:

{{announcement.toString()}}

Illegal set of announcements!

- +

Players: {{getPlayerNamesAsString()}}

+

Highest Announcements: {{getHighestAnnouncements()}}

+

Please select the elder(s):

+
{{player.firstName}}
+

Illegal game teams!

+
diff --git a/src/app/components/add-game/add-game.component.scss b/src/app/components/add-game/add-game.component.scss index 89272cd..22c8b0a 100644 --- a/src/app/components/add-game/add-game.component.scss +++ b/src/app/components/add-game/add-game.component.scss @@ -20,7 +20,7 @@ color: $inactive; } -#player-amount-warn { +#player-amount-warn, #announcement-warn, #team-warn { color: $warn; } @@ -32,6 +32,10 @@ display: inherit; } -#announcement-warn { - color: $warn; +.elder-player-false { + color: $inactive; +} + +.elder-player-true { + color: $active; } diff --git a/src/app/components/add-game/add-game.component.ts b/src/app/components/add-game/add-game.component.ts index 2ce39ed..e9af485 100644 --- a/src/app/components/add-game/add-game.component.ts +++ b/src/app/components/add-game/add-game.component.ts @@ -1,6 +1,7 @@ import {Component, OnInit} from '@angular/core'; import {Player} from '../../models/doppelkopf/player'; import * as Announcement from '../../models/doppelkopf/enums/announcement'; +import {Team} from '../../models/doppelkopf/enums/team'; @Component({ selector: 'app-add-game', @@ -100,6 +101,18 @@ export class AddGameComponent implements OnInit { return this.actualPlayers.length !== 4; } + /** + * Returns the names of the active players as a comma-separated string + */ + getPlayerNamesAsString(): string { + let playerNames = ''; + for(let player of this.actualPlayers) { + playerNames += player.firstName + ', '; + } + // Remove last ", " + return playerNames.substring(0, playerNames.length-2); + } + /** * ___ __ * / | ____ ____ ____ __ ______ ________ ____ ___ ___ ____ / /______ @@ -142,4 +155,50 @@ export class AddGameComponent implements OnInit { checkAnnouncementsValid(): boolean { return Announcement.checkValidity(this.selectedAnnouncements); } + + getHighestAnnouncements(): string { + return Announcement.returnTwoHighestAnnouncements(this.selectedAnnouncements); + } + + /** + * ______ + * /_ __/__ ____ _____ ___ _____ + * / / / _ \/ __ `/ __ `__ \/ ___/ + * / / / __/ /_/ / / / / / (__ ) + * /_/ \___/\__,_/_/ /_/ /_/____/ + */ + + /** + * Toggles the players team + * @param player The player to toggle the team for + */ + toggleElderPlayer(player: Player): void { + if(player.team === Team.RE) { + player.team = Team.CONTRA; + } else { + player.team = Team.RE; + } + } + + /** + * Checks if the player is an elder + * @param player The player to check + */ + isPlayerElder(player: Player): boolean { + return player.team === Team.RE; + } + + /** + * Checks if the current team assignment is valid + */ + checkValidTeamAssignment(): boolean { + let numberOfElderPlayers: number = 0; + for(let player of this.actualPlayers) { + if(player.team === Team.RE) { + numberOfElderPlayers++; + } + } + + return !(numberOfElderPlayers !== 1 && numberOfElderPlayers !== 2); + } } diff --git a/src/app/models/doppelkopf/enums/announcement.ts b/src/app/models/doppelkopf/enums/announcement.ts index 659f651..194a743 100644 --- a/src/app/models/doppelkopf/enums/announcement.ts +++ b/src/app/models/doppelkopf/enums/announcement.ts @@ -69,3 +69,43 @@ export function checkValidity(selectedAnnouncements: Announcement[]): boolean { // all fine, return true return true } + +export function returnTwoHighestAnnouncements(selectedAnnouncements: Announcement[]): string { + let finalString: string = ''; + + // First check "RE" announcements + if(selectedAnnouncements.indexOf(Announcement.RE_NO_THIRTY) !== -1) { + finalString += Announcement.RE_NO_THIRTY; + } else if (selectedAnnouncements.indexOf(Announcement.RE_NO_SIXTY) !== -1) { + finalString += Announcement.RE_NO_SIXTY; + } else if (selectedAnnouncements.indexOf(Announcement.RE_NO_NINETY) !== -1) { + finalString += Announcement.RE_NO_NINETY; + } else if (selectedAnnouncements.indexOf(Announcement.RE) !== -1) { + finalString += Announcement.RE; + } + + // If there was a "RE" announcement, add a ", " so we can list the CONTRA announcement properly + if(finalString !== '') { + finalString += ', '; + } + + // Now check "CONTRA" + if(selectedAnnouncements.indexOf(Announcement.CONTRA_NO_THIRTY) !== -1) { + finalString += Announcement.CONTRA_NO_THIRTY; + } else if (selectedAnnouncements.indexOf(Announcement.CONTRA_NO_SIXTY) !== -1) { + finalString += Announcement.CONTRA_NO_SIXTY; + } else if (selectedAnnouncements.indexOf(Announcement.CONTRA_NO_NINETY) !== -1) { + finalString += Announcement.CONTRA_NO_NINETY; + } else if (selectedAnnouncements.indexOf(Announcement.CONTRA) !== -1) { + finalString += Announcement.CONTRA; + } else { + // Remove the last two chars from the finalString (", ") + finalString = finalString.substring(0, finalString.length-2); + } + + if(finalString === '') { + finalString = 'None'; + } + + return finalString; +} diff --git a/src/app/models/doppelkopf/enums/team.ts b/src/app/models/doppelkopf/enums/team.ts index 3604fb2..9bc7ae7 100644 --- a/src/app/models/doppelkopf/enums/team.ts +++ b/src/app/models/doppelkopf/enums/team.ts @@ -1,4 +1,4 @@ export enum Team { RE = 0, - KONTRA = 1 + CONTRA = 1 }