Android Open Source - Freebloks-Android Highscore D B






From Project

Back to project page Freebloks-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Freebloks-Android 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 de.saschahlusiak.freebloks.database;
/*from ww  w . j a v  a2  s.  c o m*/
import de.saschahlusiak.freebloks.controller.GameMode;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class HighscoreDB extends FreebloksDB {
  public static final String TABLE = "highscores";

  public static final String HIGHSCORE_ID = "_id";        /* 0 */
  public static final String GAME_MODE_ID = "gamemode";      /* 1 */
  public static final String POINTS_ID = "points";        /* 2 */
  public static final String STONES_LEFT_ID = "stonesleft";    /* 3 */
  public static final String PLAYER_COLOR_ID = "playercolor";  /* 4 */
  public static final String PLACE_ID = "place";          /* 5 */
  public static final String FLAGS_ID = "flags";          /* 6 */

  /* NEVER CHANGE THE INDEX OF COLUMNS FOR BACKWARDS COMPATIBILITY */
  public static final int HIGHSCORE_INDEX = 0;
  public static final int GAME_MODE_INDEX = 1;
  public static final int POINTS_INDEX = 2;
  public static final int STONES_LEFT_INDEX = 3;
  public static final int PLAYER_COLOR_INDEX = 4;
  public static final int PLACE_INDEX = 5;
  public static final int FLAGS_INDEX = 6;


  public static final int FLAG_IS_PERFECT = 0x01;


  /* WARNING: The IDs are used in Cursors to query the colums, for compatibility they should NEVER be changed.
   * Make sure to ONLY append colums. */
  public static final String CREATE_TABLE = "CREATE TABLE " + TABLE + " (" +
      HIGHSCORE_ID + " INTEGER PRIMARY KEY, " +  /* 0 */
      GAME_MODE_ID + " INTEGER, " +        /* 1 */
      POINTS_ID + " INTEGER, " +          /* 2 */
      STONES_LEFT_ID + " INTEGER, " +        /* 3 */
      PLAYER_COLOR_ID + " INTEGER, " +      /* 4 */
      PLACE_ID + " INTEGER, " +          /* 5 */
      FLAGS_ID + " INTEGER);";          /* 6 */

  public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE + ";";

  public HighscoreDB(Context context) {
    super(context);
  }

  public long addHighscore(GameMode game_mode,
      int points,
      int stones_left,
      int player_color,
      int place,
      int flags) {
    ContentValues values = new ContentValues();

    values.put(GAME_MODE_ID, game_mode.ordinal());
    values.put(POINTS_ID, points);
    values.put(STONES_LEFT_ID, stones_left);
    values.put(PLAYER_COLOR_ID, player_color);
    values.put(PLACE_ID, place);
    values.put(FLAGS_ID, flags);

    return db.insert(TABLE, null, values);
  }

  public boolean clearHighscores() {
    return db.delete(TABLE, null, null) > 0;
  }

  public int getTotalNumberOfGames(GameMode game_mode) {
    int count;
    String sql = "SELECT COUNT(*) FROM " + TABLE;
    if (game_mode != null)
      sql += " WHERE " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getTotalNumberOfPoints(GameMode game_mode) {
    int count;
    String sql = "SELECT SUM(" + POINTS_ID + ") FROM " + TABLE;
    if (game_mode != null)
      sql += " WHERE " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getTotalNumberOfStonesLeft(GameMode game_mode) {
    int count;
    String sql = "SELECT SUM(" + STONES_LEFT_ID + ") FROM " + TABLE;
    if (game_mode != null)
      sql += " WHERE " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getNumberOfPlace(GameMode game_mode, int place) {
    int count;
    String sql = "SELECT COUNT(*) FROM " + TABLE + " WHERE " + PLACE_ID + " = " + place;
    if (game_mode != null)
      sql += " AND " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getNumberOfPlace(GameMode game_mode, int place, int color) {
    int count;
    String sql = "SELECT COUNT(*) FROM " + TABLE + " WHERE " + PLACE_ID + " = " + place + " AND " + PLAYER_COLOR_ID + " = " + color;
    if (game_mode != null)
      sql += " AND " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getNumberOfGoodGames(GameMode game_mode) {
    int count;
    String sql = "SELECT COUNT(*) FROM " + TABLE + " WHERE " + STONES_LEFT_ID + " = 0";
    if (game_mode != null)
      sql += " AND " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }

  public int getNumberOfPerfectGames(GameMode game_mode) {
    int count;
    String sql = "SELECT COUNT(*) FROM " + TABLE + " WHERE " + STONES_LEFT_ID + " = 0";
    sql += " AND (" + FLAGS_ID + "&" + FLAG_IS_PERFECT + ")=" + FLAG_IS_PERFECT;
    if (game_mode != null)
      sql += " AND " + GAME_MODE_ID + " = " + game_mode.ordinal();
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    count = c.getInt(0);
    c.close();
    return count;
  }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
de.saschahlusiak.freebloks.AboutActivity.java
de.saschahlusiak.freebloks.Global.java
de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java
de.saschahlusiak.freebloks.controller.GameMode.java
de.saschahlusiak.freebloks.controller.JNIServer.java
de.saschahlusiak.freebloks.controller.PlayerData.java
de.saschahlusiak.freebloks.controller.SpielClientInterface.java
de.saschahlusiak.freebloks.controller.SpielClient.java
de.saschahlusiak.freebloks.controller.Spielleiter.java
de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java
de.saschahlusiak.freebloks.database.FreebloksDB.java
de.saschahlusiak.freebloks.database.HighscoreDB.java
de.saschahlusiak.freebloks.donate.DonateActivity.java
de.saschahlusiak.freebloks.game.ActivityInterface.java
de.saschahlusiak.freebloks.game.AddScoreTask.java
de.saschahlusiak.freebloks.game.CustomGameDialog.java
de.saschahlusiak.freebloks.game.FreebloksActivity.java
de.saschahlusiak.freebloks.game.GameFinishActivity.java
de.saschahlusiak.freebloks.game.GameMenu.java
de.saschahlusiak.freebloks.game.RateAppDialog.java
de.saschahlusiak.freebloks.game.RetainedConfig.java
de.saschahlusiak.freebloks.game.SpielClientThread.java
de.saschahlusiak.freebloks.lobby.ChatEntry.java
de.saschahlusiak.freebloks.lobby.ChatListAdapter.java
de.saschahlusiak.freebloks.lobby.ColorAdapter.java
de.saschahlusiak.freebloks.lobby.LobbyDialog.java
de.saschahlusiak.freebloks.model.Player.java
de.saschahlusiak.freebloks.model.Spiel.java
de.saschahlusiak.freebloks.model.Stone.java
de.saschahlusiak.freebloks.model.Turn.java
de.saschahlusiak.freebloks.model.Turnpool.java
de.saschahlusiak.freebloks.network.NET_CHAT.java
de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java
de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_HEADER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java
de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java
de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java
de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java
de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java
de.saschahlusiak.freebloks.network.NET_SET_STONE.java
de.saschahlusiak.freebloks.network.NET_START_GAME.java
de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java
de.saschahlusiak.freebloks.network.Network.java
de.saschahlusiak.freebloks.preferences.AboutFragment.java
de.saschahlusiak.freebloks.preferences.DisplayFragment.java
de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java
de.saschahlusiak.freebloks.preferences.InterfaceFragment.java
de.saschahlusiak.freebloks.preferences.MiscFragment.java
de.saschahlusiak.freebloks.preferences.StatisticsFragment.java
de.saschahlusiak.freebloks.preferences.ThemePreference.java
de.saschahlusiak.freebloks.stats.StatisticsActivity.java
de.saschahlusiak.freebloks.stats.StatisticsAdapter.java
de.saschahlusiak.freebloks.view.BackgroundRenderer.java
de.saschahlusiak.freebloks.view.BoardRenderer.java
de.saschahlusiak.freebloks.view.Freebloks3DView.java
de.saschahlusiak.freebloks.view.FreebloksRenderer.java
de.saschahlusiak.freebloks.view.SimpleModel.java
de.saschahlusiak.freebloks.view.effects.AbsEffect.java
de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java
de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java
de.saschahlusiak.freebloks.view.effects.EffectSet.java
de.saschahlusiak.freebloks.view.effects.Effect.java
de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java
de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java
de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java
de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java
de.saschahlusiak.freebloks.view.model.Board.java
de.saschahlusiak.freebloks.view.model.CurrentStone.java
de.saschahlusiak.freebloks.view.model.Intro.java
de.saschahlusiak.freebloks.view.model.Sounds.java
de.saschahlusiak.freebloks.view.model.Theme.java
de.saschahlusiak.freebloks.view.model.ViewElement.java
de.saschahlusiak.freebloks.view.model.ViewModel.java
de.saschahlusiak.freebloks.view.model.Wheel.java