Android Open Source - Android-Tile-Based-Game Game Level Tile Data






From Project

Back to project page Android-Tile-Based-Game.

License

The source code is released under:

MIT License

If you think the Android project Android-Tile-Based-Game 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 org.ruscoe.example.tilegame.data;
//from w  w  w.  j a v  a 2  s. c o m
import static android.provider.BaseColumns._ID;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * The GameTileData class represents a definition of a game
 * level stored in the database.
 * 
 * @author Dan Ruscoe (ruscoe.org)
 * @version 1.0
 */
public class GameLevelTileData extends GameDAO
{
  public static final String TABLE_NAME = "gameLevelTileData";

  public static final String STAGE = "stage";
  public static final String LEVEL = "level";
  public static final String PLAYER_START_TILE_X = "playerStartTileX";
  public static final String PLAYER_START_TILE_Y = "playerStartTileY";
  public static final String TILE_DATA = "tileData";

  public static final int FIELD_ID_ID = 0;
  public static final int FIELD_ID_STAGE = 1;
  public static final int FIELD_ID_LEVEL = 2;
  public static final int FIELD_ID_PLAYER_START_TILE_X = 3;
  public static final int FIELD_ID_PLAYER_START_TILE_Y = 4;
  public static final int FIELD_ID_TILE_DATA = 5;

  public static final String TILE_DATA_LINE_BREAK = "//";

  public GameLevelTileData(Context ctx)
  {
    super(ctx);
  }

  /**
   * Gets an array of game level data for a given stage and level.
   * @param int stage - The game stage.
   * @param level - The game level, relative to the stage.
   * @return ArrayList
   */
  public ArrayList<String> getGameLevelData(int stage, int level)
  {
      SQLiteDatabase db = this.getReadableDatabase();
      
      String[] from = { _ID, STAGE, LEVEL, PLAYER_START_TILE_X, PLAYER_START_TILE_Y, TILE_DATA };
      String where = STAGE + " = " + stage + " AND " + LEVEL + " = " + level;
      
      Cursor cursor = db.query(TABLE_NAME, from, where, null, null, null, null);
      
      ArrayList<String> levelData = new ArrayList<String>();
      
      if (cursor != null)
      {
        while (cursor.moveToNext())
          {
          levelData.add(cursor.getString(FIELD_ID_ID));
          levelData.add(cursor.getString(FIELD_ID_STAGE));
          levelData.add(cursor.getString(FIELD_ID_LEVEL));
          levelData.add(cursor.getString(FIELD_ID_PLAYER_START_TILE_X));
          levelData.add(cursor.getString(FIELD_ID_PLAYER_START_TILE_Y));
          levelData.add(cursor.getString(FIELD_ID_TILE_DATA));
          }
        cursor.close();
      }
      
      db.close();
      return levelData;
  }
}




Java Source Code List

org.ruscoe.example.tilegame.About.java
org.ruscoe.example.tilegame.GameImage.java
org.ruscoe.example.tilegame.GameTile.java
org.ruscoe.example.tilegame.GameUi.java
org.ruscoe.example.tilegame.GameUnit.java
org.ruscoe.example.tilegame.GameView.java
org.ruscoe.example.tilegame.Play.java
org.ruscoe.example.tilegame.PlayerUnit.java
org.ruscoe.example.tilegame.data.GameDAO.java
org.ruscoe.example.tilegame.data.GameLevelTileData.java
org.ruscoe.example.tilegame.data.GameTileData.java