Android Open Source - Marble-Run Score






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;
//  w ww.j a va  2  s  .c o m
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

// Scoreboard: This class lists all 10 players' high scores.
// Activity: ScoreActivity uses this class Score.

//TODO: Continue working on the scoreboard, and figure a way to:
// #1: Calculate the points the player earned while playing a level (demo level, play against time).
// #2: Obtain the player's name after the player completes a level (demo level, when goal is reached).
// #3: Display 10 players (place, name, and score) when player presses "High Score" menu button.
// #4: Only insert entries after player finishes a level. Only display entries, otherwise.

public class Score {
  private static final String DB_NAME = "Scoreboard";
  private static final String DB_TABLE = "Leaderboard";
  private static final int DB_VERSION = 1;
  private static final String KEY_ID = "_id";
  private static final String KEY_NAME = "_name";
  private static final String KEY_SCORE = "_score";
  
  private class DBHelper extends SQLiteOpenHelper {
    public DBHelper(Context c) {
      super(c, DB_NAME, null, DB_VERSION);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE IF NOT EXISTS " + DB_TABLE + " (" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_SCORE + " INTEGER NOT NULL);");
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE + ";");
      this.onCreate(db);
    }
  }
  
  private final Context context;
  private DBHelper helper;
  private SQLiteDatabase database;
  
  public Score(Context c) {
    this.context = c;
  }
  
  public Score open() throws SQLiteException{
    this.helper = new DBHelper(this.context);
    this.database = helper.getWritableDatabase();
    return this;
  }
  
  public void close(){
    this.helper.close();
  }
  
  public void createEntry(String name, long score){
    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME, name);
    cv.put(KEY_SCORE, score);
    this.database.insert(DB_TABLE, null, cv);
  }
}




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