Add text that tells the players exactly why the total points are wrong

This commit is contained in:
Patrick Müller 2022-09-10 22:36:21 +02:00
parent ae45cc78a1
commit cd5154a07a
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
2 changed files with 18 additions and 4 deletions

View File

@ -43,8 +43,8 @@
<td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore"/></td> <td><input type="number" [(ngModel)]="this.actualPlayers[3].finalCardScore"/></td>
</tr> </tr>
</table> </table>
<p id="score-warn" *ngIf="!totalScoreValid()">Total score doesn't add up!</p> <p id="score-warn" *ngIf="calculatePointSum() !== 240">Total score doesn't add up ({{getScoreDifferenceText()}})</p>
<button (click)="switchToNextPage()" [disabled]="!totalScoreValid()">Next</button> <button (click)="switchToNextPage()" [disabled]="!calculatePointSum()">Next</button>
</div> </div>
<div id="which-solo" class="visible-{{this.currentPage === 4}}"> <div id="which-solo" class="visible-{{this.currentPage === 4}}">

View File

@ -218,13 +218,27 @@ export class AddGameComponent implements OnInit {
/** /**
* Checks if the sum of all points is exactly 240 * Checks if the sum of all points is exactly 240
*/ */
totalScoreValid(): boolean { calculatePointSum(): number {
let totalScore: number = 0; let totalScore: number = 0;
for (let player of this.actualPlayers) { for (let player of this.actualPlayers) {
totalScore += player.finalCardScore ?? 0; 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';
}
} }
/** /**