Compare commits
2 Commits
ae45cc78a1
...
e41a07411e
Author | SHA1 | Date | |
---|---|---|---|
e41a07411e | |||
cd5154a07a |
|
@ -43,8 +43,8 @@
|
|||
<td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p id="score-warn" *ngIf="!totalScoreValid()">Total score doesn't add up!</p>
|
||||
<button (click)="switchToNextPage()" [disabled]="!totalScoreValid()">Next</button>
|
||||
<p id="score-warn" *ngIf="calculatePointSum() !== 240">Total score doesn't add up ({{getScoreDifferenceText()}})</p>
|
||||
<button (click)="switchToNextPage()" [disabled]="!calculatePointSum()">Next</button>
|
||||
</div>
|
||||
<div id="which-solo" class="visible-{{this.currentPage === 4}}">
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {Component, OnInit} from '@angular/core';
|
||||
import {Player} from '../../models/doppelkopf/player';
|
||||
import * as Announcement from '../../models/doppelkopf/enums/announcement';
|
||||
import * as announcements from '../../models/doppelkopf/enums/announcement';
|
||||
import {Team} from '../../models/doppelkopf/enums/team';
|
||||
|
||||
@Component({
|
||||
|
@ -12,7 +12,7 @@ export class AddGameComponent implements OnInit {
|
|||
potentialPlayers: Player[] = [];
|
||||
actualPlayers: Player[] = [];
|
||||
|
||||
selectedAnnouncements: Announcement.Announcement[] = [];
|
||||
selectedAnnouncements: announcements.Announcement[] = [];
|
||||
|
||||
currentPage: number = 0;
|
||||
|
||||
|
@ -127,15 +127,116 @@ export class AddGameComponent implements OnInit {
|
|||
*/
|
||||
|
||||
/**
|
||||
* Toggles the activity status for the given announcement
|
||||
* Toggles the activity status for the given announcement and also activates / deactivates other announcements
|
||||
* to conform to the rules.
|
||||
* @param announcement The announcement to toggle activity for
|
||||
*/
|
||||
toggleAnnouncement(announcement: Announcement.Announcement): void {
|
||||
toggleAnnouncement(announcement: announcements.Announcement): void {
|
||||
let index = this.selectedAnnouncements.indexOf(announcement);
|
||||
if (index !== -1) {
|
||||
this.selectedAnnouncements.splice(index, 1);
|
||||
this.deactivateLowerAnnouncements(announcement);
|
||||
} else {
|
||||
this.selectedAnnouncements.push(announcement);
|
||||
this.activateHigherAnnouncements(announcement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates all lower announcements. E.g.: When RE is deactivated, RE_NO_NINETY and all lower also get deactivated
|
||||
* @param announcement The announcement that has been deactivated
|
||||
*/
|
||||
deactivateLowerAnnouncements(announcement: announcements.Announcement) {
|
||||
// First for RE
|
||||
switch(announcement) {
|
||||
case announcements.Announcement.RE:
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_NINETY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
|
||||
break;
|
||||
case announcements.Announcement.RE_NO_NINETY:
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
|
||||
break;
|
||||
case announcements.Announcement.RE_NO_SIXTY:
|
||||
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
|
||||
break;
|
||||
}
|
||||
|
||||
// Now for CONTRA
|
||||
switch(announcement) {
|
||||
case announcements.Announcement.CONTRA:
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
|
||||
break;
|
||||
case announcements.Announcement.CONTRA_NO_NINETY:
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
|
||||
break;
|
||||
case announcements.Announcement.CONTRA_NO_SIXTY:
|
||||
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates the given announcement if it is active
|
||||
* @param announcement The announcement to deactivate
|
||||
*/
|
||||
deactivateAnnouncement(announcement: announcements.Announcement) {
|
||||
let index = this.selectedAnnouncements.indexOf(announcement);
|
||||
if (index !== -1) {
|
||||
this.selectedAnnouncements.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates all higher announcements. E.g.: When RE_NO_NINETY is activated, RE also gets activated
|
||||
* @param announcement The announcement that has been activated
|
||||
*/
|
||||
activateHigherAnnouncements(announcement: announcements.Announcement) {
|
||||
// First for RE
|
||||
switch(announcement) {
|
||||
case announcements.Announcement.RE_NO_THIRTY:
|
||||
this.activateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
|
||||
this.activateAnnouncement(announcements.Announcement.RE_NO_NINETY);
|
||||
this.activateAnnouncement(announcements.Announcement.RE);
|
||||
break;
|
||||
case announcements.Announcement.RE_NO_SIXTY:
|
||||
this.activateAnnouncement(announcements.Announcement.RE_NO_NINETY);
|
||||
this.activateAnnouncement(announcements.Announcement.RE);
|
||||
break;
|
||||
case announcements.Announcement.RE_NO_NINETY:
|
||||
this.activateAnnouncement(announcements.Announcement.RE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Now for CONTRA
|
||||
switch(announcement) {
|
||||
case announcements.Announcement.CONTRA_NO_THIRTY:
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA);
|
||||
break;
|
||||
case announcements.Announcement.CONTRA_NO_SIXTY:
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA);
|
||||
break;
|
||||
case announcements.Announcement.CONTRA_NO_NINETY:
|
||||
this.activateAnnouncement(announcements.Announcement.CONTRA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the given announcement if it is inactive
|
||||
* @param announcement The announcement to activate
|
||||
*/
|
||||
activateAnnouncement(announcement: announcements.Announcement) {
|
||||
let index = this.selectedAnnouncements.indexOf(announcement);
|
||||
if (index === -1) {
|
||||
this.selectedAnnouncements.push(announcement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,26 +244,26 @@ export class AddGameComponent implements OnInit {
|
|||
* Checks if the given announcement is already marked as selected
|
||||
* @param announcement The announcement to check the status for
|
||||
*/
|
||||
isAnnouncementActive(announcement: Announcement.Announcement): boolean {
|
||||
isAnnouncementActive(announcement: announcements.Announcement): boolean {
|
||||
return this.selectedAnnouncements.indexOf(announcement) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all possible announcements
|
||||
*/
|
||||
getAllPossibleAnnouncements(): Announcement.Announcement[] {
|
||||
return Announcement.getAllAnnouncementValues();
|
||||
getAllPossibleAnnouncements(): announcements.Announcement[] {
|
||||
return announcements.getAllAnnouncementValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the currently selected announcements are a valid set of announcements
|
||||
*/
|
||||
checkAnnouncementsValid(): boolean {
|
||||
return Announcement.checkValidity(this.selectedAnnouncements);
|
||||
return announcements.checkValidity(this.selectedAnnouncements);
|
||||
}
|
||||
|
||||
getHighestAnnouncements(): string {
|
||||
return Announcement.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
||||
return announcements.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,13 +319,27 @@ export class AddGameComponent implements OnInit {
|
|||
/**
|
||||
* Checks if the sum of all points is exactly 240
|
||||
*/
|
||||
totalScoreValid(): boolean {
|
||||
calculatePointSum(): number {
|
||||
let totalScore: number = 0;
|
||||
for (let player of this.actualPlayers) {
|
||||
totalScore += player.finalCardScore ?? 0;
|
||||
}
|
||||
|
||||
return totalScore === 240;
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string that explains if the total point sum is too low / too high
|
||||
*/
|
||||
getScoreDifferenceText(): string {
|
||||
let difference = this.calculatePointSum() - 240;
|
||||
|
||||
if(difference > 0) {
|
||||
return difference + ' more than expected';
|
||||
} else {
|
||||
difference *= -1;
|
||||
return difference + ' less than expected';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user