add updateScore method

This commit is contained in:
Florian Schmid 2023-04-28 21:10:07 +02:00
parent 8e5143fba8
commit 1445942d04
2 changed files with 15 additions and 5 deletions

View File

@ -108,7 +108,7 @@ class ViewModel {
}
reduceScore() {
this.stats.incrementScore(-1);
this.stats.updateScore(-1);
}
resetScore() {

View File

@ -14,16 +14,26 @@ export class Stats {
incrementScore(value = 1) {
this.#score += value;
if (this.#highScore < this.#score) {
this.#highScore = this.#score;
localStorage.setItem(this.#highScoreStorageKey, this.#highScore.toString());
}
this.checkHighScore;
}
resetScore(): void {
this.#score = 0;
}
updateScore(value) {
this.#score += value;
this.checkHighScore;
}
private checkHighScore() {
if (this.#highScore < this.#score) {
this.#highScore = this.#score;
localStorage.setItem(this.#highScoreStorageKey, this.#highScore.toString());
}
}
get highScore(): number {
return this.#highScore;
}