Android Open Source - Hungry-Mouse Settings






From Project

Back to project page Hungry-Mouse.

License

The source code is released under:

MIT License

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

//Name:   Settings.java
//Purpose:  save and load settings like sounds on/off gyroscope on/off and save high scores
package com.hungry.mouse.main;
/*  w  w w  .  j  ava 2  s  .c  om*/
import com.hungry.mouse.framework.FileIO;

//java libraries
import java.io.BufferedReader;//wraps and existing reader and buffers the input
import java.io.BufferedWriter;//wraps an existing Writer and buffers the output
import java.io.IOException;//signal that i/o exception has occurred
import java.io.InputStreamReader;//turn a byte stream to character stream
import java.io.OutputStreamWriter;



public class Settings {
   
    // Create variables that will hold the values you want to save in your game.
    // Default values:
   
    public static boolean soundEnabled = true;
    public static boolean gyroscopeEnabled = false;
    public static int currentLevel = 0;
    public static int theLevelPassed = 0;
    public static int level1CollectedCheeses, level2CollectedCheeses, level3CollectedCheeses;
    public static int level1KilledKamikazis, level2KilledKamikazis, level3KilledKamikazis;
   
    public static void save(FileIO files) {
        BufferedWriter out = null;
        try {
           
            // Writes a file called .savedata to the SD Card
            out = new BufferedWriter(new OutputStreamWriter(
                    files.writeFile(".savethedataHungryMouse")));
           
            // Line by line ("\n" creates a new line), write the value of each variable to the file.
            out.write(Boolean.toString(soundEnabled));
            out.write("\n");
            out.write(Boolean.toString(gyroscopeEnabled));
            out.write("\n");            
            out.write(Integer.toString(currentLevel));
            out.write("\n");
            out.write(Integer.toString(theLevelPassed));
            out.write("\n");
            
            //cheeses
            out.write(Integer.toString(level1CollectedCheeses));
            out.write("\n");
            out.write(Integer.toString(level2CollectedCheeses));
            out.write("\n");
            out.write(Integer.toString(level3CollectedCheeses));
            out.write("\n");
            
            //kamikazis
            out.write(Integer.toString(level1KilledKamikazis));
            out.write("\n");
            out.write(Integer.toString(level2KilledKamikazis));
            out.write("\n");
            out.write(Integer.toString(level3KilledKamikazis));
            out.write("\n");
       
           
           // This section handles errors in file management!
           
        } catch (IOException e) {
        } finally {
            try {
                if (out != null)
                    out.close();
            } catch (IOException e) {
            }
        }
    }
   
    public static void load(FileIO files) {
        BufferedReader in = null;
        try {
            // Reads file called Save Data
            in = new BufferedReader(new InputStreamReader(
                    files.readFile(".savethedataHungryMouse")));

            // Loads values from the file and replaces default values.
            soundEnabled = Boolean.parseBoolean(in.readLine());
            gyroscopeEnabled = Boolean.parseBoolean(in.readLine());
            currentLevel = Integer.parseInt(in.readLine());
            theLevelPassed = Integer.parseInt(in.readLine());
            
            level1CollectedCheeses = Integer.parseInt(in.readLine());
            level2CollectedCheeses = Integer.parseInt(in.readLine());
            level3CollectedCheeses = Integer.parseInt(in.readLine());            
            
            level1KilledKamikazis = Integer.parseInt(in.readLine());
            level2KilledKamikazis = Integer.parseInt(in.readLine());
            level3KilledKamikazis = Integer.parseInt(in.readLine());
           
        } catch (IOException e) {
            // Catches errors. Default values are used.
        } catch (NumberFormatException e) {
            // Catches errors. Default values are used.
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
            }
        }
    }
}




Java Source Code List

com.hungry.mouse.framework.Audio.java
com.hungry.mouse.framework.FileIO.java
com.hungry.mouse.framework.Game.java
com.hungry.mouse.framework.Graphics.java
com.hungry.mouse.framework.Image.java
com.hungry.mouse.framework.Input.java
com.hungry.mouse.framework.Music.java
com.hungry.mouse.framework.Pool.java
com.hungry.mouse.framework.Screen.java
com.hungry.mouse.framework.Sound.java
com.hungry.mouse.framework.implementation.AccelerometerHandler.java
com.hungry.mouse.framework.implementation.AndroidAudio.java
com.hungry.mouse.framework.implementation.AndroidFastRenderView.java
com.hungry.mouse.framework.implementation.AndroidFileIO.java
com.hungry.mouse.framework.implementation.AndroidGame.java
com.hungry.mouse.framework.implementation.AndroidGraphics.java
com.hungry.mouse.framework.implementation.AndroidImage.java
com.hungry.mouse.framework.implementation.AndroidInput.java
com.hungry.mouse.framework.implementation.AndroidMusic.java
com.hungry.mouse.framework.implementation.AndroidSound.java
com.hungry.mouse.framework.implementation.MultiTouchHandler.java
com.hungry.mouse.framework.implementation.SingleTouchHandler.java
com.hungry.mouse.framework.implementation.TouchHandler.java
com.hungry.mouse.main.AboutScreen.java
com.hungry.mouse.main.Animation.java
com.hungry.mouse.main.Assets.java
com.hungry.mouse.main.Background.java
com.hungry.mouse.main.Bomb.java
com.hungry.mouse.main.Cheese.java
com.hungry.mouse.main.Enemy.java
com.hungry.mouse.main.GameScreen.java
com.hungry.mouse.main.HelpScreen1.java
com.hungry.mouse.main.HelpScreen2.java
com.hungry.mouse.main.HelpScreen3.java
com.hungry.mouse.main.HelpScreen4.java
com.hungry.mouse.main.Kamikazi.java
com.hungry.mouse.main.LevelSelectorScreen.java
com.hungry.mouse.main.LoadingScreen.java
com.hungry.mouse.main.MainMenuScreen.java
com.hungry.mouse.main.Mouse.java
com.hungry.mouse.main.Projectile.java
com.hungry.mouse.main.Rewards.java
com.hungry.mouse.main.SampleGame.java
com.hungry.mouse.main.Settings.java
com.hungry.mouse.main.Sign.java
com.hungry.mouse.main.SplashLoadingScreen.java
com.hungry.mouse.main.Tile.java