Android Open Source - Tilt-snake Saving






From Project

Back to project page Tilt-snake.

License

The source code is released under:

Apache License

If you think the Android project Tilt-snake listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.awhittle.tiltsnake;
/*www . j a  v  a 2 s  .  c  om*/
import android.content.SharedPreferences;

public class Saving {

  //Save high score for active flag if counter is higher than old high score
  public static void saveScore(SharedPreferences settings, int score){
    
    saveThis(settings, score);
    
    if(MainActivity.insanityFlag){
      if (GameActivity.counter > MainActivity.insaneHS){
        saveInsaneHS(settings, score);
      }
    } else if(MainActivity.hardFlag){
      if (GameActivity.counter > MainActivity.hardHS){
        saveHardHS(settings, score);
      }
    } else {
      if (GameActivity.counter > MainActivity.normalHS){
        saveNormalHS(settings, score);
      }
    }
  }
  
  private static void saveNormalHS(SharedPreferences settings, int score){
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("NormalHS", score);
    editor.commit();
  }
  
  private static void saveHardHS(SharedPreferences settings, int score){
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("HardHS", score);
    editor.commit();
  }
  
  private static void saveInsaneHS(SharedPreferences settings, int score){
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("InsaneHS", score);
    editor.commit();
  }
  private static void saveThis(SharedPreferences settings, int score){
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("ThisScore", score);
    editor.commit();
  }
}




Java Source Code List

com.awhittle.tiltsnake.Direction.java
com.awhittle.tiltsnake.Egg.java
com.awhittle.tiltsnake.GameActivity.java
com.awhittle.tiltsnake.Head.java
com.awhittle.tiltsnake.MainActivity.java
com.awhittle.tiltsnake.Movement.java
com.awhittle.tiltsnake.MyGLRenderer.java
com.awhittle.tiltsnake.MyGLSurfaceView.java
com.awhittle.tiltsnake.Saving.java
com.awhittle.tiltsnake.ShapeTools.java
com.awhittle.tiltsnake.Square.java
com.awhittle.tiltsnake.Tail.java