From 1445942d04b32e6be61cad9cc2f35da1f891857e Mon Sep 17 00:00:00 2001 From: Florian Schmid Date: Fri, 28 Apr 2023 21:10:07 +0200 Subject: [PATCH] add updateScore method --- src/newMode.ts | 2 +- src/statistics.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/newMode.ts b/src/newMode.ts index 54b508a..33ecc30 100644 --- a/src/newMode.ts +++ b/src/newMode.ts @@ -108,7 +108,7 @@ class ViewModel { } reduceScore() { - this.stats.incrementScore(-1); + this.stats.updateScore(-1); } resetScore() { diff --git a/src/statistics.ts b/src/statistics.ts index f320c64..54a7545 100644 --- a/src/statistics.ts +++ b/src/statistics.ts @@ -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; }