Skip to content

Instantly share code, notes, and snippets.

@EliteIntegrity
Created March 5, 2019 12:04
Show Gist options
  • Save EliteIntegrity/15c0b6aa5e5bb498cc868cfa7e117e1a to your computer and use it in GitHub Desktop.
Save EliteIntegrity/15c0b6aa5e5bb498cc868cfa7e117e1a to your computer and use it in GitHub Desktop.
Add this code to the end of the pause function to save the players new high score if one was achieved in the current play session
val prefs = context.getSharedPreferences(
"Kotlin Invaders",
Context.MODE_PRIVATE)
val oldHighScore = prefs.getInt("highScore", 0)
if(highScore > oldHighScore) {
val editor = prefs.edit()
editor.putInt(
"highScore", highScore)
editor.apply()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment