@@ -192,6 +192,7 @@ class Tetris {
192
192
this . score = 0 ;
193
193
this . isGameOver = false ;
194
194
this . level = 0 ;
195
+ this . lines = 0 ;
195
196
fps = PAL_FPS [ this . level ] ;
196
197
this . spawn ( ) ;
197
198
}
@@ -274,10 +275,7 @@ class Tetris {
274
275
275
276
if ( dir == DOWN ) {
276
277
this . score ++ ;
277
- if ( this . score > this . highScore ) {
278
- this . highScore = this . score ;
279
- localStorage . setItem ( "highscore" , this . score ) ;
280
- }
278
+ this . updateHighScore ( ) ;
281
279
}
282
280
283
281
if ( wall == WALL ) return ;
@@ -373,10 +371,7 @@ class Tetris {
373
371
fps = PAL_FPS [ this . level ] ;
374
372
frameRate ( fps ) ;
375
373
}
376
- if ( this . score > this . highScore ) {
377
- this . highScore = this . score ;
378
- localStorage . setItem ( "highscore" , this . score ) ;
379
- }
374
+ this . updateHighScore ( ) ;
380
375
}
381
376
382
377
checkWallOnMove ( dir , coords ) {
@@ -483,13 +478,21 @@ class Tetris {
483
478
}
484
479
485
480
this . score += 2 * minDistance ;
481
+ this . updateHighScore ( ) ;
486
482
487
483
for ( let i = 0 ; i < coords . length ; i ++ ) {
488
484
coords [ i ] . y += minDistance ;
489
485
}
490
486
return coords ;
491
487
}
492
488
489
+ updateHighScore ( ) {
490
+ if ( this . score > this . highScore ) {
491
+ this . highScore = this . score ;
492
+ localStorage . setItem ( "highscore" , this . score ) ;
493
+ }
494
+ }
495
+
493
496
hardDrop ( ) {
494
497
let coords = this . hardDropCoords ( ) ;
495
498
this . applyBoxes ( coords ) ;
0 commit comments