add statistic class
This commit is contained in:
parent
69a4772b76
commit
1fb4e3f8e3
23
js/statistics.js
Normal file
23
js/statistics.js
Normal file
@ -0,0 +1,23 @@
|
||||
class Stats {
|
||||
#score;
|
||||
#highScore;
|
||||
#highScoreStorageKey;
|
||||
|
||||
constructor(highScoreStorageKey) {
|
||||
// used as key for localStorage
|
||||
|
||||
this.#highScoreStorageKey = highScoreStorageKey;
|
||||
|
||||
this.#score = 0;
|
||||
this.#highScore = localStorage.getItem(this.#highScoreStorageKey) ?? 0;
|
||||
}
|
||||
|
||||
incrementScore(value = 1) {
|
||||
this.#score += value;
|
||||
|
||||
if (this.#highScore < this.#score) {
|
||||
this.#highScore = this.#score;
|
||||
localStorage.setItem(this.#highScoreStorageKey, this.#highScore);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user