Android Open Source - BlastWords Settings






From Project

Back to project page BlastWords.

License

The source code is released under:

Apache License

If you think the Android project BlastWords 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

/**
 * BlastWords/*from ww  w. ja v  a2  s.c  om*/
 * Settings.java
 * 
 * Created by Lou Foster
 * Copyright Studio332 2013. All rights reserved.
 */
package com.studio332.blastwords.model;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.studio332.blastwords.model.BlastWordsGame.Mode;

/**
 * Persisted blastwords game settings
 * 
 * @author lfoster
 *
 */
public final class Settings {
   private static final Settings instance = new Settings();
   private boolean soundOn = true;
   private boolean musicOn = true;
   private Map<Mode, Integer> highScores;
   private boolean rulesEverSeen = false;
   
   private static final String PREFS_NAME = "blastwords";
   
   public static Settings instance() {
      return Settings.instance;
   }
   
   private Settings() {
      this.highScores = new HashMap<BlastWordsGame.Mode, Integer>();
      this.highScores.put(Mode.TIMED ,0);
      this.highScores.put(Mode.CLEAR ,0);
      this.highScores.put(Mode.ENDLESS ,0);
      
      Preferences p =  Gdx.app.getPreferences( PREFS_NAME );
      if ( p.contains("soundOn")) {
         this.soundOn = p.getBoolean("soundOn");
      }
      if ( p.contains("musicOn")) {
         this.musicOn = p.getBoolean("musicOn");
      }
      if ( p.contains("rulesEverSeen")) { 
         this.rulesEverSeen = p.getBoolean("rulesEverSeen");
      }
      if ( p.contains(Mode.TIMED.toString())) { 
         this.highScores.put(Mode.TIMED, p.getInteger(Mode.TIMED.toString()));
      }
      if ( p.contains(Mode.CLEAR.toString())) { 
         this.highScores.put(Mode.CLEAR, p.getInteger(Mode.CLEAR.toString()));
      }
      if ( p.contains(Mode.ENDLESS.toString())) { 
         this.highScores.put(Mode.ENDLESS, p.getInteger(Mode.ENDLESS.toString()));
      }
   }
   
   public boolean rulesEverSeen() {
      return this.rulesEverSeen;
   }
   
   public void rulesViewed() {
      this.rulesEverSeen = true;
      Preferences p =  Gdx.app.getPreferences( PREFS_NAME );
      p.putBoolean("rulesEverSeen", this.rulesEverSeen);
      p.flush();
   }
   
   public void toggleSound() {
      this.soundOn = !this.soundOn;
      Preferences p =  Gdx.app.getPreferences( PREFS_NAME );
      p.putBoolean("soundOn", this.soundOn);
      p.flush();
   }
   
   public boolean isSoundOn() {
      return this.soundOn;
   }
   
   public void toggleMusic() {
      this.musicOn = !this.musicOn;
      Preferences p =  Gdx.app.getPreferences( PREFS_NAME );
      p.putBoolean("musicOn", this.musicOn);
      p.flush();
   }
   
   public boolean isMusicOn() {
      return this.musicOn;
   }
   
   public Integer getHighScoreForMode( Mode m ) {
      return this.highScores.get(m);
   }
   
   public void setHighScoreForMode( Mode m, int score ) {
      this.highScores.put(m, score);
      Preferences p =  Gdx.app.getPreferences( PREFS_NAME );
      p.putInteger(m.toString(), score);
      p.flush();
   }
}




Java Source Code List

com.studio332.blastwords.BlastWords.java
com.studio332.blastwords.MainActivity.java
com.studio332.blastwords.Main.java
com.studio332.blastwords.model.BlastWordsGame.java
com.studio332.blastwords.model.LetterInfo.java
com.studio332.blastwords.model.Settings.java
com.studio332.blastwords.objects.Blaster.java
com.studio332.blastwords.objects.Bomb.java
com.studio332.blastwords.objects.Digit.java
com.studio332.blastwords.objects.GameTimer.java
com.studio332.blastwords.objects.ScoreBoard.java
com.studio332.blastwords.objects.Tile.java
com.studio332.blastwords.screens.AbstractScreen.java
com.studio332.blastwords.screens.GameOver.java
com.studio332.blastwords.screens.GameScreen.java
com.studio332.blastwords.screens.GameStateListener.java
com.studio332.blastwords.screens.MainMenuScreen.java
com.studio332.blastwords.screens.Popup.java
com.studio332.blastwords.screens.SplashScreen.java
com.studio332.blastwords.util.Assets.java
com.studio332.blastwords.util.BlastWordsActions.java
com.studio332.blastwords.util.Overlay.java
com.studio332.blastwords.util.ParticleEffectActor.java
com.studio332.blastwords.util.SoundManager.java