Android Open Source - shapemergency Game Preferences






From Project

Back to project page shapemergency.

License

The source code is released under:

GNU General Public License

If you think the Android project shapemergency 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.adsg0186.shapemergency.testgame1.config;
/*from  www. ja v a 2s.c  o  m*/
import com.adsg0186.shapemergency.testgame1.GameSound;
import com.adsg0186.shapemergency.testgame1.Vibrate;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class GamePreferences {

    protected int sound;
    protected int vibrate;
    protected int difficulty;
    protected Context context;
    protected SharedPreferences store;
    
    public GamePreferences(Context context) { 
        this.context = context;
        store = PreferenceManager.getDefaultSharedPreferences(context);
    }
    
    public int setSound(int sound) { this.sound = sound; return sound; }
    public int setVibrate(int vib) { this.vibrate = vib; return vib; }
    public int setDifficulty(int dif) { this.difficulty = dif; return dif; }
    
    private static String createKey(String pref) {
        return String.format("pref_%s", pref);
    }

    // call before getting
    public void load() {
        sound = store.getInt(createKey("sound"), 1);
        vibrate = store.getInt(createKey("vibrate"), 1);
        difficulty = store.getInt(createKey("difficulty"), 1); // default to Normal
    }
    
    public int getSound() { return sound; }
    public int getVibrate() { return vibrate; }
    public int getDifficulty() { return difficulty; }
    
    // call after setting
    public void save() {
        SharedPreferences.Editor editor = store.edit();
        editor.putInt(createKey("sound"), sound);
        editor.putInt(createKey("vibrate"), vibrate);
        editor.putInt(createKey("difficulty"), difficulty);
        editor.commit();
    }
   
    // set up singletons based on preferences
    public void doInitFromPreferences() {
        switch(sound) {
            case 0:
                GameSound.setFakeInstance();
                break;
            case 1:
                GameSound.setRealInstance(context);
                break;
        }

        switch(vibrate) {
            case 0:
                Vibrate.setFakeInstance();
                break;
            case 1:
                Vibrate.setRealInstance(context);
                break;
        }
    }
         
    protected static GamePreferences instance;
    public static GamePreferences createInstance(Context context) {
        instance = new GamePreferences(context);
        return instance;
    }
    public static GamePreferences get() { return instance; }
}




Java Source Code List

com.adsg0186.shapemergency.GameActivity.java
com.adsg0186.shapemergency.GameScreen.java
com.adsg0186.shapemergency.HelpView.java
com.adsg0186.shapemergency.HighScoreView.java
com.adsg0186.shapemergency.MainActivity.java
com.adsg0186.shapemergency.SettingsView.java
com.adsg0186.shapemergency.testgame1.AngryTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.BonusFactory.java
com.adsg0186.shapemergency.testgame1.BossTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.CreateEnemyTrigger.java
com.adsg0186.shapemergency.testgame1.DefenderCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.FiringGameTest.java
com.adsg0186.shapemergency.testgame1.GameSound.java
com.adsg0186.shapemergency.testgame1.MissileBlobSource.java
com.adsg0186.shapemergency.testgame1.MissileCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.ShieldCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.TargetMissileSource.java
com.adsg0186.shapemergency.testgame1.TargetUtils.java
com.adsg0186.shapemergency.testgame1.Vibrate.java
com.adsg0186.shapemergency.testgame1.blobs.BonusDropper.java
com.adsg0186.shapemergency.testgame1.blobs.BonusIF.java
com.adsg0186.shapemergency.testgame1.blobs.BossEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.DamagableIF.java
com.adsg0186.shapemergency.testgame1.blobs.DamagerIF.java
com.adsg0186.shapemergency.testgame1.blobs.DefaultEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyBomb.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyFactory.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyIF.java
com.adsg0186.shapemergency.testgame1.blobs.FiringBlobDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.FlashMessage.java
com.adsg0186.shapemergency.testgame1.blobs.HitpointBonusDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.ScoreTextDisplay.java
com.adsg0186.shapemergency.testgame1.blobs.ShieldRing.java
com.adsg0186.shapemergency.testgame1.config.BaseGameConfig.java
com.adsg0186.shapemergency.testgame1.config.EasyGameConfig.java
com.adsg0186.shapemergency.testgame1.config.GameConfigIF.java
com.adsg0186.shapemergency.testgame1.config.GameConfig.java
com.adsg0186.shapemergency.testgame1.config.GamePreferences.java
com.adsg0186.shapemergency.testgame1.config.InsaneGameConfig.java
com.adsg0186.shapemergency.testgame1.config.SavedGame.java