Compare commits
No commits in common. "e41a07411ecce6e48901c61edb1562f6e2feeb4c" and "ae45cc78a1a334b076989f84bce6579945401ce2" have entirely different histories.
e41a07411e
...
ae45cc78a1
|
@ -43,8 +43,8 @@
|
|||
<td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p id="score-warn" *ngIf="calculatePointSum() !== 240">Total score doesn't add up ({{getScoreDifferenceText()}})</p>
|
||||
<button (click)="switchToNextPage()" [disabled]="!calculatePointSum()">Next</button>
|
||||
<p id="score-warn" *ngIf="!totalScoreValid()">Total score doesn't add up!</p>
|
||||
<button (click)="switchToNextPage()" [disabled]="!totalScoreValid()">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 announcements from '../../models/doppelkopf/enums/announcement';
|
||||
import * as Announcement 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: announcements.Announcement[] = [];
|
||||
selectedAnnouncements: Announcement.Announcement[] = [];
|
||||
|
||||
currentPage: number = 0;
|
||||
|
||||
|
@ -127,116 +127,15 @@ export class AddGameComponent implements OnInit {
|
|||
*/
|
||||
|
||||
/**
|
||||
* Toggles the activity status for the given announcement and also activates / deactivates other announcements
|
||||
* to conform to the rules.
|
||||
* Toggles the activity status for the given announcement
|
||||
* @param announcement The announcement to toggle activity for
|
||||
*/
|
||||
toggleAnnouncement(announcement: announcements.Announcement): void {
|
||||
toggleAnnouncement(announcement: Announcement.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,26 +143,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: announcements.Announcement): boolean {
|
||||
isAnnouncementActive(announcement: Announcement.Announcement): boolean {
|
||||
return this.selectedAnnouncements.indexOf(announcement) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all possible announcements
|
||||
*/
|
||||
getAllPossibleAnnouncements(): announcements.Announcement[] {
|
||||
return announcements.getAllAnnouncementValues();
|
||||
getAllPossibleAnnouncements(): Announcement.Announcement[] {
|
||||
return Announcement.getAllAnnouncementValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the currently selected announcements are a valid set of announcements
|
||||
*/
|
||||
checkAnnouncementsValid(): boolean {
|
||||
return announcements.checkValidity(this.selectedAnnouncements);
|
||||
return Announcement.checkValidity(this.selectedAnnouncements);
|
||||
}
|
||||
|
||||
getHighestAnnouncements(): string {
|
||||
return announcements.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
||||
return Announcement.returnTwoHighestAnnouncements(this.selectedAnnouncements);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -319,27 +218,13 @@ export class AddGameComponent implements OnInit {
|
|||
/**
|
||||
* Checks if the sum of all points is exactly 240
|
||||
*/
|
||||
calculatePointSum(): number {
|
||||
totalScoreValid(): boolean {
|
||||
let totalScore: number = 0;
|
||||
for (let player of this.actualPlayers) {
|
||||
totalScore += player.finalCardScore ?? 0;
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
return totalScore === 240;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user