File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ class Page extends React.Component {
187187 }
188188 l . forEach ( ( d , i ) => {
189189 keep [ d . x ] [ d . y ] = false
190- this . state . score += ( ( newColoredDot . type + 1 ) * 5 )
190+ this . updateScore ( this . state . score + ( ( newColoredDot . type + 1 ) * 5 ) )
191191 } )
192192 this . state . blocksKilled ++
193193 }
@@ -222,17 +222,18 @@ class Page extends React.Component {
222222 dots : [ ] ,
223223 floatingDots : [ ]
224224 } )
225+ this . updateScore ( this . state . score )
225226 }
226227
227- setHighScore ( ) {
228+ updateScore ( score ) {
228229 if ( typeof window === 'undefined' ) return
229- const localStorage = window . localStorage
230- if ( ! localStorage ) return
231- localStorage [ 'score' ] = Math . max ( this . state . score , this . state . highScore )
230+ const highScore = Math . max ( score , this . state . highScore )
231+ window . localStorage [ 'score' ] = highScore
232+ this . setState ( { highScore , score } )
232233 }
233234
234235 getHighScore ( ) {
235- if ( typeof window === 'undefined' ) return
236+ if ( typeof window === 'undefined' ) return 0
236237 const localStorage = window . localStorage
237238 if ( ! localStorage ) return
238239 return localStorage [ 'score' ] || 0
You can’t perform that action at this time.
0 commit comments