8000 add high score to local storage · sjefvanleeuwen/shooter@773382a · GitHub
[go: up one dir, main page]

Skip to content

Commit 773382a

Browse files
add high score to local storage
1 parent 869d07b commit 773382a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

js/game.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class Game {
7171
this.invulnerabilityTime = 2.0;
7272
this.invulnerabilityTimer = 0;
7373
this.score = 0;
74-
this.highScore = parseInt(localStorage.getItem('highScore')) || 0;
74+
this.highScore = localStorage.getItem('highScore')
75+
? parseInt(localStorage.getItem('highScore'), 10)
76+
: 0;
7577
this.lives = 3;
7678

7779
// Initialize music player without starting it
@@ -407,7 +409,7 @@ class Game {
407409
this.score += points;
408410
if (this.score > this.highScore) {
409411
this.highScore = this.score;
410-
localStorage.setItem('highScore', this.highScore.toString());
412+
localStorage.setItem('highScore', this.highScore.toString()); // Store high score to local storage
411413
}
412414
}
413415

0 commit comments

Comments
 (0)
0