diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ae4db80..c2e8554 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,7 @@ import {HeaderComponent} from './components/header/header.component'; import {ProfileComponent} from './components/profile/profile.component'; import {AddGameComponent} from './components/add-game/add-game.component'; import {MatchHistoryComponent} from './pages/match-history/match-history.component'; +import {FormsModule} from '@angular/forms'; @NgModule({ declarations: [ @@ -24,7 +25,8 @@ import {MatchHistoryComponent} from './pages/match-history/match-history.compone ], imports: [ BrowserModule, - AppRoutingModule + AppRoutingModule, + FormsModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/components/add-game/add-game.component.html b/src/app/components/add-game/add-game.component.html index 25be637..8677307 100644 --- a/src/app/components/add-game/add-game.component.html +++ b/src/app/components/add-game/add-game.component.html @@ -3,18 +3,48 @@
-
{{player.firstName}}
+

Select the active players for the game:

+
{{player.firstName}}

Illegal amount of players!

- +
- +

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!

+
-
- +
+

Please enter the points that every player has collected:

+ + + + + + + + + + + + + + + + + +

{{this.actualPlayers[0].firstName}}

{{this.actualPlayers[1].firstName}}

{{this.actualPlayers[2].firstName}}

{{this.actualPlayers[3].firstName}}

+

Total score doesn't add up!

+
@@ -24,6 +54,8 @@
- +

+ {{player.firstName}}: {{calculateCurrentScore(player)}} +

diff --git a/src/app/components/add-game/add-game.component.scss b/src/app/components/add-game/add-game.component.scss index 06447c2..bd85815 100644 --- a/src/app/components/add-game/add-game.component.scss +++ b/src/app/components/add-game/add-game.component.scss @@ -2,6 +2,16 @@ #add-game { padding-top: $header_height; + display: grid; + grid-template-areas: 'entry entry scores'; +} + +#game-infos { + grid-area: entry; +} + +#scores { + grid-area: scores; } #which-players div { @@ -12,15 +22,15 @@ color: $text; } -.active-true { +.active-true, .elder-player-true { color: $active; } -.active-false { +.active-false, .elder-player-false { color: $inactive; } -#player-amount-warn { +#player-amount-warn, #announcement-warn, #team-warn, #score-warn { color: $warn; } @@ -31,3 +41,22 @@ .visible-true { display: inherit; } + +.togglebtn { + text-align: center; + max-width: 10em; + background-color: $button; + margin: .5em; +} + +.team-Re { + background-color: $secondary; +} + +.team-Contra { + background-color: $primary; +} + +table.point-entry td { + padding: .5em; +} diff --git a/src/app/components/add-game/add-game.component.ts b/src/app/components/add-game/add-game.component.ts index ffd9c66..079d0e3 100644 --- a/src/app/components/add-game/add-game.component.ts +++ b/src/app/components/add-game/add-game.component.ts @@ -1,5 +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', @@ -10,48 +12,78 @@ export class AddGameComponent implements OnInit { potentialPlayers: Player[] = []; actualPlayers: Player[] = []; + selectedAnnouncements: Announcement.Announcement[] = []; + currentPage: number = 0; constructor() { - this.potentialPlayers.push({ - firebonkId: 1, - uuid: 'abc-def-ghi-j', - firstName: 'Patrick' - }); - this.potentialPlayers.push({ - firebonkId: 2, - uuid: 'abc-def-ghi-k', - firstName: 'Julian' - }); - this.potentialPlayers.push({ - firebonkId: 3, - uuid: 'abc-def-ghi-l', - firstName: 'Yannick' - }); - this.potentialPlayers.push({ - firebonkId: 4, - uuid: 'abc-def-ghi-m', - firstName: 'Janina' - }); - this.potentialPlayers.push({ - firebonkId: 5, - uuid: 'abc-def-ghi-n', - firstName: 'Moritz' - }); - - this.actualPlayers.push(...this.potentialPlayers.slice(0,4)); + this.generateDemoData(); } ngOnInit(): void { } + /** + * Generates demo data to test the UI + */ + generateDemoData() { + this.potentialPlayers.push({ + firebonkId: 1, + uuid: 'abc-def-ghi-j', + firstName: 'Patrick', + team: Team.CONTRA + }); + this.potentialPlayers.push({ + firebonkId: 2, + uuid: 'abc-def-ghi-k', + firstName: 'Julian', + team: Team.CONTRA + }); + this.potentialPlayers.push({ + firebonkId: 3, + uuid: 'abc-def-ghi-l', + firstName: 'Yannick', + team: Team.CONTRA + }); + this.potentialPlayers.push({ + firebonkId: 4, + uuid: 'abc-def-ghi-m', + firstName: 'Janina', + team: Team.CONTRA + }); + this.potentialPlayers.push({ + firebonkId: 5, + uuid: 'abc-def-ghi-n', + firstName: 'Moritz', + team: Team.CONTRA + }); + + this.actualPlayers.push(...this.potentialPlayers.slice(0, 4)); + } + + /** + * Switches the entry mask UI to the next page + */ + switchToNextPage(): void { + this.currentPage++; + } + + /** + * ____ __ + * / __ \/ /___ ___ _____ __________ + * / /_/ / / __ `/ / / / _ \/ ___/ ___/ + * / ____/ / /_/ / /_/ / __/ / (__ ) + * /_/ /_/\__,_/\__, /\___/_/ /____/ + * /____/ + */ + /** * Toggles if the given player is should be an active player for the current game * @param player The player to toggle the activity for */ togglePlayer(player: Player): void { let index = this.actualPlayers.indexOf(player); - if(index !== -1){ + if (index !== -1) { this.actualPlayers.splice(index, 1); } else { this.actualPlayers.push(player); @@ -75,9 +107,179 @@ export class AddGameComponent implements OnInit { } /** - * Switches the entry mask UI to the next page + * Returns the names of the active players as a comma-separated string */ - switchToNextPage(): void { - this.currentPage++; + getPlayerNamesAsString(): string { + let playerNames = ''; + for (let player of this.actualPlayers) { + playerNames += player.firstName + ', '; + } + // Remove last ", " + return playerNames.substring(0, playerNames.length - 2); + } + + /** + * ___ __ + * / | ____ ____ ____ __ ______ ________ ____ ___ ___ ____ / /______ + * / /| | / __ \/ __ \/ __ \/ / / / __ \/ ___/ _ \/ __ `__ \/ _ \/ __ \/ __/ ___/ + * / ___ |/ / / / / / / /_/ / /_/ / / / / /__/ __/ / / / / / __/ / / / /_(__ ) + * /_/ |_/_/ /_/_/ /_/\____/\__,_/_/ /_/\___/\___/_/ /_/ /_/\___/_/ /_/\__/____/ + */ + + /** + * Toggles the activity status for the given announcement + * @param announcement The announcement to toggle activity for + */ + toggleAnnouncement(announcement: Announcement.Announcement): void { + let index = this.selectedAnnouncements.indexOf(announcement); + if (index !== -1) { + this.selectedAnnouncements.splice(index, 1); + } else { + this.selectedAnnouncements.push(announcement); + } + } + + /** + * Checks if the given announcement is already marked as selected + * @param announcement The announcement to check the status for + */ + isAnnouncementActive(announcement: Announcement.Announcement): boolean { + return this.selectedAnnouncements.indexOf(announcement) !== -1; + } + + /** + * Returns a list of all possible announcements + */ + getAllPossibleAnnouncements(): Announcement.Announcement[] { + return Announcement.getAllAnnouncementValues(); + } + + /** + * Checks, if the currently selected announcements are a valid set of announcements + */ + 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); + } + + /** + * _____ + * / ___/_________ ________ _____ + * \__ \/ ___/ __ \/ ___/ _ \/ ___/ + * ___/ / /__/ /_/ / / / __(__ ) + * /____/\___/\____/_/ \___/____/ + */ + + /** + * Checks if the sum of all points is exactly 240 + */ + totalScoreValid(): boolean { + let totalScore: number = 0; + for (let player of this.actualPlayers) { + totalScore += player.finalCardScore ?? 0; + } + + return totalScore === 240; + } + + /** + * ______ _____ + * / ____/___ _____ ___ ___ / ___/_________ ________ + * / / __/ __ `/ __ `__ \/ _ \ \__ \/ ___/ __ \/ ___/ _ \ + * / /_/ / /_/ / / / / / / __/ ___/ / /__/ /_/ / / / __/ + * \____/\__,_/_/ /_/ /_/\___/ /____/\___/\____/_/ \___/ + */ + + /** + * Calculates the game points for the given player + * @param player The player to calculate points for + */ + calculateCurrentScore(player: Player): number { + let gameScore: number = 0; + let teamScore = this.getTeamScore(player); + + // Won? If so, by how much? + if (teamScore > 210) { + gameScore += 4; + } else if (teamScore > 180) { + gameScore += 3; + } else if (teamScore > 150) { + gameScore += 2; + } else if (teamScore > 120) { + 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 + + return gameScore; + } + + /** + * Calculates the team card score of the given players team + * @param player The player to calculate the teams points for + */ + getTeamScore(player: Player): number { + let totalTeamScore: number = player.finalCardScore ?? 0; + + for (let otherPlayer of this.actualPlayers) { + if (otherPlayer !== player && otherPlayer.team === player.team) { + totalTeamScore += otherPlayer.finalCardScore ?? 0; + } + } + + return totalTeamScore; } } diff --git a/src/app/components/header/header.component.html b/src/app/components/header/header.component.html index b8eb750..43c4dc3 100644 --- a/src/app/components/header/header.component.html +++ b/src/app/components/header/header.component.html @@ -1,5 +1,5 @@