This commit is contained in:
Florian Schmid 2023-04-28 22:55:00 +02:00
parent cb403d1e51
commit 4e006e64e8
2 changed files with 6 additions and 4 deletions

View File

@ -23,16 +23,17 @@ export class Stats {
}
incrementScore(value = 1) {
__classPrivateFieldSet(this, _Stats_score, __classPrivateFieldGet(this, _Stats_score, "f") + value, "f");
this.checkHighScore;
this.checkHighScore();
}
resetScore() {
__classPrivateFieldSet(this, _Stats_score, 0, "f");
}
updateScore(value) {
__classPrivateFieldSet(this, _Stats_score, __classPrivateFieldGet(this, _Stats_score, "f") + value, "f");
this.checkHighScore;
this.checkHighScore();
}
checkHighScore() {
console.log("Highscore: " + __classPrivateFieldGet(this, _Stats_highScore, "f") + " | Score: " + __classPrivateFieldGet(this, _Stats_score, "f"));
if (__classPrivateFieldGet(this, _Stats_highScore, "f") < __classPrivateFieldGet(this, _Stats_score, "f")) {
__classPrivateFieldSet(this, _Stats_highScore, __classPrivateFieldGet(this, _Stats_score, "f"), "f");
localStorage.setItem(__classPrivateFieldGet(this, _Stats_highScoreStorageKey, "f"), __classPrivateFieldGet(this, _Stats_highScore, "f").toString());

View File

@ -14,7 +14,7 @@ export class Stats {
incrementScore(value = 1) {
this.#score += value;
this.checkHighScore;
this.checkHighScore();
}
resetScore(): void {
@ -24,10 +24,11 @@ export class Stats {
updateScore(value) {
this.#score += value;
this.checkHighScore;
this.checkHighScore();
}
private checkHighScore() {
console.log("Highscore: " + this.#highScore + " | Score: " + this.#score)
if (this.#highScore < this.#score) {
this.#highScore = this.#score;
localStorage.setItem(this.#highScoreStorageKey, this.#highScore.toString());