Android Open Source - Marble-Run Format






From Project

Back to project page Marble-Run.

License

The source code is released under:

Apache License

If you think the Android project Marble-Run 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 nttu.edu.score;
//from  ww w.  j av a2 s. c  om
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OptionalDataException;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.Log;

public class Format implements Serializable {
  
  private static final long serialVersionUID = 1L;
  public List<Format> sessions = new ArrayList<Format>();
  
  public Map<Integer, Long> highScores;
  public Map<String, Integer> profiles;
  public Map<AbstractMap.SimpleEntry<String, Integer>, Long> entries;
  
  public Format() {
    try {
      Log.d("Format()", "Creating new file, 'format.dat'. ");
      File directory = new File("/data/data/nttu.edu/files");
      if (directory.exists()) {
        FileOutputStream out = new FileOutputStream(new File(directory, "format.dat"));
        out.close();
      }
    }
    catch (FileNotFoundException e1) {
      e1.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
  
  public void addEntry(String player, long points) {
    Format format = new Format();
    sessions.add(format);
    format = null;
  }
  
  public void addBestEntry(int stageNumber, long score) {
    // If true, the values has been changed. If false, we do nothing.
    if (highScores == null)
      highScores = new LinkedHashMap<Integer, Long>();
    Integer compare = Integer.valueOf(stageNumber);
    Long t = Long.valueOf(score);
    if (highScores.containsKey(compare)) {
      Long s = Long.valueOf(highScores.get(compare));
      if (s < t) {
        highScores.put(compare, t);
      }
    }
    else
      highScores.put(compare, t);
  }
  
  public void addBestEntryAndName(int stageNumber, long score, String name) {
    if (entries == null)
      entries = new LinkedHashMap<AbstractMap.SimpleEntry<String, Integer>, Long>();
    Integer stage = Integer.valueOf(stageNumber);
    Long points = Long.valueOf(score);
    AbstractMap.SimpleEntry<String, Integer> entryKey = new AbstractMap.SimpleEntry<String, Integer>(name, stage);
    if (entries.containsKey(entryKey)) {
      Long oldPoints = Long.valueOf(entries.get(entryKey));
      if (points > oldPoints) {
        entries.put(entryKey, points);
      }
    }
    else {
      entries.put(entryKey, points);
    }
  }
  
  public Long getScore(int key) {
    if (highScores != null) {
      Integer k = Integer.valueOf(key);
      Long temp = highScores.get(k);
      if (temp == null)
        return 0L;
      return temp;
    }
    return 0L;
  }
  
  public static Format loadFormat(Context context) {
    FileInputStream in = null;
    ObjectInputStream inn = null;
    Format format = null;
    try {
      in = context.openFileInput("format.dat");
      inn = new ObjectInputStream(new BufferedInputStream(in));
      if (inn != null){
        format = (Format) inn.readObject();
      }
    }
    catch (FileNotFoundException e) {
      Log.e("PlayActivity", "FileNotFoundException", e);
      format = new Format();
    }
    catch (OptionalDataException e) {
      Log.e("PlayActivity", "OptionalDataException", e);
      format = new Format();
    }
    catch (ClassNotFoundException e) {
      Log.e("PlayActivity", "ClassNotFoundException", e);
      format = new Format();
    }
    catch (IOException e) {
      Log.e("PlayActivity", "IOException", e);
      format = new Format();
    }
    finally {
      if (in != null) {
        try {
          in.close();
        }
        catch (IOException e) {
          Log.e("PlayActivity", "IOException", e);
        }
      }
      if (inn != null) {
        try {
          inn.close();
        }
        catch (IOException e) {
          Log.e("PlayActivity", "IOException", e);
        }
      }
      if (format ==  null){
        format = new Format();
      }
    }
    return format;
  }
}




Java Source Code List

nttu.edu.activities.LevelSelectionActivity.java
nttu.edu.activities.MenuActivity.java
nttu.edu.activities.NewLoadingActivity.java
nttu.edu.activities.PlayActivity.java
nttu.edu.activities.ScoreActivity.java
nttu.edu.activities.SettingsActivity.java
nttu.edu.alt.NewBall.java
nttu.edu.alt.NewCue.java
nttu.edu.alt.NewHole.java
nttu.edu.alt.Obstacle.java
nttu.edu.ball.Ball.java
nttu.edu.ball.Cue.java
nttu.edu.ball.Marble.java
nttu.edu.entity.Border.java
nttu.edu.entity.Bumper.java
nttu.edu.entity.Coin.java
nttu.edu.entity.Connector.java
nttu.edu.entity.CurvePipe.java
nttu.edu.entity.Entity.java
nttu.edu.entity.Funnel.java
nttu.edu.entity.Hole.java
nttu.edu.entity.Path.java
nttu.edu.entity.Pipe.java
nttu.edu.entity.Ramp.java
nttu.edu.entity.ShortFunnel.java
nttu.edu.entity.Tee.java
nttu.edu.entity.Terrain.java
nttu.edu.entity.Void.java
nttu.edu.graphics.Art.java
nttu.edu.graphics.RenderView.java
nttu.edu.handler.Accelero.java
nttu.edu.handler.ImageInfo.java
nttu.edu.handler.Info.java
nttu.edu.handler.Loading.java
nttu.edu.handler.ModPlayer.java
nttu.edu.handler.MusicHandler.java
nttu.edu.hud.BestScore.java
nttu.edu.hud.Compass.java
nttu.edu.hud.GoalCompass.java
nttu.edu.hud.HUDMenu.java
nttu.edu.hud.HUDScore.java
nttu.edu.hud.MarbleCompass.java
nttu.edu.hud.TimeBasedScore.java
nttu.edu.level.HUD.java
nttu.edu.level.Stage.java
nttu.edu.score.Format.java
nttu.edu.score.Score.java
nttu.edu.sound.Sound.java