Android Open Source - Airplanes Game Configuration






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes 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.axnsan.airplanes;
//from  w ww.j av  a2s . com
import com.axnsan.airplanes.util.StringManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

public class GameConfiguration {
  public enum KillMode { Headshot, Full };
  public KillMode killMode = KillMode.Headshot;
  public boolean revealDeadPlanes = true;
  public int numPlanes = 3;
  public int gridSize = 10;
  public int numPlayers = 1;
  
  public static final int maxPlayers = 8;
  public static final int maxNameLength = 15;
  public String[] playerNames = new String[maxPlayers];
  
  private void initDefaultNames()
  {
    playerNames = new String[maxPlayers];
    for (int i = 1;i <= maxPlayers;++i)
      playerNames[i-1] = StringManager.getString("player_%d").replace("%d", Integer.toString(i));
    
  }
  public static void ResetConfig(String identifier) {
    Preferences pref = Gdx.app.getPreferences(identifier + "_CONFIG");
    pref.putBoolean("valid", false);
    pref.flush();
  }
  
  public GameConfiguration() { }
  private String ID;
  public GameConfiguration(String identifier)
  {
    this.ID = identifier + "_CONFIG";
    Preferences pref = Gdx.app.getPreferences(ID);
    initDefaultNames();
    
    
    if (pref.getBoolean("valid", false))
    {
      numPlanes = pref.getInteger("numPlanes", numPlanes);
      revealDeadPlanes = pref.getBoolean("revealDeadPlanes", revealDeadPlanes);
      gridSize = pref.getInteger("gridSize", gridSize);
      numPlayers = pref.getInteger("numPlayers", numPlayers);

      String nameString = pref.getString("playerNames", null);
      if (nameString != null)
      {
        String[] names = nameString.split("([\\[\\]])|(\\,[ ])");
        for (int i = 0, j = 0;i < maxPlayers && j < names.length;++j)
        {
          if (names[j].length() > 0)
          {
            if (names[j].length() <= maxNameLength)
              playerNames[i++] = names[j];
            else playerNames[i++] = names[j].substring(0, maxNameLength);
          }
        }
      }
      killMode = KillMode.valueOf(pref.getString("killMode", killMode.toString()));
    }
    else
    {
      dumpConfig();
    }
  }
  public void dumpConfig()
  {
    if (ID == null)
      throw new UnsupportedOperationException();
    
    Preferences pref = Gdx.app.getPreferences(ID);
    pref.putString("killMode", killMode.toString());
    pref.putBoolean("revealDeadPlanes", revealDeadPlanes);
    pref.putInteger("numPlanes", numPlanes);
    pref.putInteger("gridSize", gridSize);
    pref.putInteger("numPlayers", numPlayers);
    pref.putString("playerNames", java.util.Arrays.toString(playerNames));
    pref.putBoolean("valid", true);
    pref.flush();
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java